BrightSide Workbench Full Report + Source Code
RelatedPathsUtil.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 package org.turro.relpaths;
21 
22 import java.util.Date;
23 import java.util.List;
24 import org.turro.contacts.RelatedPaths;
25 import org.turro.contacts.db.ContactsPU;
26 import org.turro.jpa.Dao;
27 
32 @Deprecated
33 public class RelatedPathsUtil {
34 
35  public static void addRelation(String origin, String destination, String description) {
36  if(!existsRelation(origin, destination)) {
37  RelatedPaths rp = new RelatedPaths();
38  rp.setOrigin(origin);
39  rp.setDestination(destination);
40  rp.setDescription(description);
41  if(!rp.isEmpty()) {
42  rp.setCreation(new Date());
43  Dao dao = new ContactsPU();
44  dao.saveObject(rp);
45  }
46  }
47  }
48 
49  public static void removeRelation(String origin, String destination) {
50  Dao dao = new ContactsPU();
51  dao.executeUpdate(
52  " delete from RelatedPaths " +
53  " where origin = ? " +
54  " and destination = ?",
55  new Object[] { origin, destination }
56  );
57  }
58 
59  public static void removePath(String path) {
60  Dao dao = new ContactsPU();
61  dao.executeUpdate(
62  " delete from RelatedPaths " +
63  " where origin = ? or destination = ?",
64  new Object[] { path, path }
65  );
66  }
67 
68  public static boolean existsRelation(String origin, String destination) {
69  Dao dao = new ContactsPU();
70  return ((Long) dao.getSingleResult(
71  " select count(*) from RelatedPaths " +
72  " where origin = ? and destination = ?",
73  new Object[] { origin, destination }
74  )) > 0;
75  }
76 
77  public static boolean existsPath(String path) {
78  Dao dao = new ContactsPU();
79  return ((Long) dao.getSingleResult(
80  " select count(*) from RelatedPaths " +
81  " where origin = ? or destination = ?",
82  new Object[] { path, path }
83  )) > 0;
84  }
85 
86  public static List<RelatedPaths> destinations(String path) {
87  Dao dao = new ContactsPU();
88  return (List<RelatedPaths>)dao.getResultList(
89  " select rp from RelatedPaths as rp" +
90  " where origin = ?",
91  new Object[] { path }
92  );
93  }
94 
95  public static List<RelatedPaths> origins(String path) {
96  Dao dao = new ContactsPU();
97  return (List<RelatedPaths>)dao.getResultList(
98  " select rp from RelatedPaths as rp" +
99  " where destination = ?",
100  new Object[] { path }
101  );
102  }
103 
104  private RelatedPathsUtil() {
105  }
106 
107 }
void setDescription(String description)
void setCreation(Date creation)
void setDestination(String destination)
void setOrigin(String origin)
int executeUpdate(String query)
Definition: Dao.java:463
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380
static boolean existsRelation(String origin, String destination)
static void addRelation(String origin, String destination, String description)
static void removeRelation(String origin, String destination)
static void removePath(String path)
static List< RelatedPaths > origins(String path)
static boolean existsPath(String path)
static List< RelatedPaths > destinations(String path)