BrightSide Workbench Full Report + Source Code
StudentsPU.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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 package org.turro.students.db;
20 
21 import javax.persistence.EntityManager;
22 import javax.persistence.EntityManagerFactory;
23 import org.turro.jpa.Dao;
24 import org.turro.jpa.DaoFactory;
25 import org.turro.students.entities.Challenge;
26 import org.turro.students.entities.PracticalWork;
27 import org.turro.students.entities.Response;
28 import org.turro.students.entities.TalentCategory;
29 import org.turro.version.Version;
30 
35 public class StudentsPU extends Dao {
36 
37  private static final DaoFactory factory = new DaoFactory();
38 
39  @Override
40  protected EntityManagerFactory getFactory() {
41  return factory.getEmf();
42  }
43 
44  @Override
45  protected EntityManager createEntityManager() {
46  return factory.createEntityManager("studentsPU", "Students");
47  }
48 
49  @Override
50  protected EntityManager createCachedEntityManager() {
51  return factory.createCachedEntityManager("studentsPU", "Students");
52  }
53 
54  @Override
55  public String getPath(Object object) {
56  return getObjectPath(object);
57  }
58 
59  public static String getObjectPath(Object object) {
60  if(object instanceof Challenge) {
61  return "/challenge/" + ((Challenge) object).getId();
62  } else if(object instanceof Response) {
63  return "/response/" + ((Response) object).getId();
64  } else if(object instanceof PracticalWork) {
65  return "/practicalwork/" + ((PracticalWork) object).getId();
66  } else if(object instanceof TalentCategory) {
67  return "/talent-category/" + ((TalentCategory) object).getId();
68  }
69  return null;
70  }
71 
72  public static String getObjectExtendedPath(Object object) {
73  return "";
74  }
75 
76  public static org.turro.version.Module getModule() {
77  return new org.turro.version.Module(new Version("1.0.0"), "Elephant Students");
78  }
79 
80 }
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
String getPath(Object object)
Definition: StudentsPU.java:55
static org.turro.version.Module getModule()
Definition: StudentsPU.java:76
EntityManager createCachedEntityManager()
Definition: StudentsPU.java:50
EntityManagerFactory getFactory()
Definition: StudentsPU.java:40
static String getObjectPath(Object object)
Definition: StudentsPU.java:59
static String getObjectExtendedPath(Object object)
Definition: StudentsPU.java:72
EntityManager createEntityManager()
Definition: StudentsPU.java:45