BrightSide Workbench Full Report + Source Code
ContactsPU.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.contacts.db;
19 
20 import javax.persistence.EntityManager;
21 import javax.persistence.EntityManagerFactory;
22 import org.turro.annotation.ElephantDao;
23 import org.turro.contacts.Address;
24 import org.turro.contacts.BusinessRelation;
25 import org.turro.contacts.Comment;
26 import org.turro.contacts.CommentIt;
27 import org.turro.contacts.Connector;
28 import org.turro.contacts.Contact;
29 import org.turro.contacts.ContactService;
30 import org.turro.contacts.Convocation;
31 import org.turro.contacts.GroupIt;
32 import org.turro.contacts.StarIt;
33 import org.turro.contacts.VoteIt;
34 import org.turro.jpa.Dao;
35 import org.turro.jpa.DaoFactory;
36 import org.turro.version.Module;
37 import org.turro.version.Version;
38 
43 @ElephantDao(pu = "contactsPU")
44 public class ContactsPU extends Dao {
45 
46  private static final DaoFactory factory = new DaoFactory();
47 
48  @Override
49  protected EntityManagerFactory getFactory() {
50  return factory.getEmf();
51  }
52 
53  @Override
54  protected EntityManager createEntityManager() {
55  return factory.createEntityManager("contactsPU", "Contacts");
56  }
57 
58  @Override
59  protected EntityManager createCachedEntityManager() {
60  return factory.createCachedEntityManager("contactsPU", "Contacts");
61  }
62 
63  @Override
64  public String getPath(Object object) {
65  return getObjectPath(object);
66  }
67 
68  public static String getObjectPath(Object object) {
69  if(object instanceof Contact) {
70  return "/contact/" + ((Contact) object).getId();
71  } else if(object instanceof Address) {
72  return getObjectPath(((Address) object).getContact()) + "/address/" + ((Address) object).getId();
73  } else if(object instanceof Connector) {
74  return getObjectPath(((Connector) object).getContact()) + "/connector/" + ((Connector) object).getId();
75  } else if(object instanceof Comment) {
76  return getObjectPath(((Comment) object).getContact()) + "/comment/" + ((Comment) object).getId();
77  } else if(object instanceof BusinessRelation) {
78  return getObjectPath(((BusinessRelation) object).getBusiness()) + "/relation/" + ((BusinessRelation) object).getId();
79  } else if(object instanceof ContactService) {
80  return "/service/" + ((ContactService) object).getId();
81  } else if(object instanceof GroupIt) {
82  return "/groupit/" + ((GroupIt) object).getId();
83  } else if(object instanceof Convocation) {
84  return "/convocation/" + ((Convocation) object).getId();
85  } else if(object instanceof CommentIt) {
86  return "/comment-it/" + ((CommentIt) object).getId();
87  } else if(object instanceof StarIt) {
88  return "/star-it/" + ((StarIt) object).getId();
89  } else if(object instanceof VoteIt) {
90  return "/vote-it/" + ((VoteIt) object).getId();
91  }
92  return null;
93  }
94 
95  public static Module getModule() {
96  return new Module(new Version("2.1"), "BrightSide Contacts");
97  }
98 
99 }
100 
static String getObjectPath(Object object)
Definition: ContactsPU.java:68
EntityManagerFactory getFactory()
Definition: ContactsPU.java:49
String getPath(Object object)
Definition: ContactsPU.java:64
EntityManager createCachedEntityManager()
Definition: ContactsPU.java:59
EntityManager createEntityManager()
Definition: ContactsPU.java:54
EntityManagerFactory getEmf()
Definition: DaoFactory.java:89
EntityManager createEntityManager(String pu, String conf)
Definition: DaoFactory.java:54
synchronized EntityManager createCachedEntityManager(String pu, String conf)
Definition: DaoFactory.java:64