BrightSide Workbench Full Report + Source Code
AttachPU.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.attach.db;
19 
20 import java.io.File;
21 import javax.persistence.EntityManager;
22 import javax.persistence.EntityManagerFactory;
23 import org.turro.attach.entity.Attachment;
24 import org.turro.jpa.Dao;
25 import org.turro.jpa.DaoFactory;
26 import org.turro.version.Module;
27 import org.turro.version.Version;
28 
33 public class AttachPU extends Dao {
34 
35  private static final DaoFactory factory = new DaoFactory();
36 
37  @Override
38  protected EntityManagerFactory getFactory() {
39  return factory.getEmf();
40  }
41 
42  @Override
43  protected EntityManager createEntityManager() {
44  return factory.createEntityManager("attachPU", "Attach");
45  }
46 
47  @Override
48  protected EntityManager createCachedEntityManager() {
49  return factory.createCachedEntityManager("attachPU", "Attach");
50  }
51 
52  @Override
53  public String getPath(Object object) {
54  return getObjectPath(object);
55  }
56 
57  public static String getObjectPath(Object object) {
58  if(object instanceof Attachment) {
59  return "/attachment/" + ((Attachment) object).getId();
60  } else if(object instanceof File) {
61  return "/file/" + ((File) object).getAbsolutePath();
62  }
63  return null;
64  }
65 
66  public static String getObjectExtendedPath(Object object) {
67  return "";
68  }
69 
70  public static Module getModule() {
71  return new Module(new Version("1.5.0"), "BrightSide Attachment");
72  }
73 
74 }
EntityManager createEntityManager()
Definition: AttachPU.java:43
EntityManager createCachedEntityManager()
Definition: AttachPU.java:48
static String getObjectExtendedPath(Object object)
Definition: AttachPU.java:66
String getPath(Object object)
Definition: AttachPU.java:53
static Module getModule()
Definition: AttachPU.java:70
EntityManagerFactory getFactory()
Definition: AttachPU.java:38
static String getObjectPath(Object object)
Definition: AttachPU.java:57
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