View Javadoc
1   /*******************************************************************************
2    * Copyright 2012 pw999
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   ******************************************************************************/
16  package net.sf.oqt.core;
17  
18  import java.text.MessageFormat;
19  import java.util.Collection;
20  import java.util.TreeSet;
21  
22  import net.sf.oqt.model.EntityVO;
23  import net.sf.oqt.model.PackageVO;
24  import net.sf.oqt.model.ResultVO;
25  
26  
27  /**
28   * Contains all the configuration settings.
29   * 
30   * @author phillip
31   * 
32   */
33  public class CoreProperties {
34  
35      CoreProperties() {
36  
37      }
38  
39      /**
40       * Database connection url.
41       */
42      private String url = "";
43      /**
44       * Database username. Leave empty if not required.
45       */
46      private String username = "";
47      /**
48       * Database password. Leave empty if not required.
49       */
50      private String password = "";
51      /**
52       * Database driver name. Must be on the classPath.
53       */
54      private String driverName = "";
55      /**
56       * Database dictionary. Must be known to the OpenJPA version on the
57       * classpath.
58       */
59      private String dictionary = "";
60      /**
61       * The list of package names where the application can find the JPA
62       * entities.
63       */
64      private final Collection<String> packageNames = new TreeSet<String>();
65      /**
66       * List of fully qualified names of the JPA entities.
67       */
68      private final Collection<String> fqns = new TreeSet<String>();
69      /**
70       * The version of openJPA. This is automatically initialized when the {@link CoreFactory#getEntityManager()} method
71       * is called.
72       */
73      private String jpaVersion = "";
74  
75      public final String getUrl() {
76          return url;
77      }
78  
79      public final void setUrl(final String url) {
80          this.url = url;
81      }
82  
83      public final String getUsername() {
84          return username;
85      }
86  
87      public final void setUsername(final String username) {
88          this.username = username;
89      }
90  
91      public final String getPassword() {
92          return password;
93      }
94  
95      public final void setPassword(final String password) {
96          this.password = password;
97      }
98  
99      public final String getDriverName() {
100         return driverName;
101     }
102 
103     public final void setDriverName(final String driverName) {
104         this.driverName = driverName;
105     }
106 
107     public final String getDictionary() {
108         return dictionary;
109     }
110 
111     public final void setDictionary(final String dictionary) {
112         this.dictionary = dictionary;
113     }
114 
115     public final Collection<String> getFqns() {
116         return fqns;
117     }
118 
119     public final Collection<String> getPackageNames() {
120         return packageNames;
121     }
122 
123     public final String getJpaVersion() {
124         return jpaVersion;
125     }
126 
127     final void setJpaVersion(final String jpaVersion) {
128         this.jpaVersion = jpaVersion;
129     }
130 
131     /**
132      * Initializes the list of fully qualified names based on the info in the
133      * ResultVO object.
134      * 
135      * @param result the initialized ResultVO
136      */
137     public final void setFqnsFromResult(final ResultVO result) {
138         String pattern = "{0}.{1}";
139         fqns.clear();
140         Collection<PackageVO> packages = result.getPackages();
141         for (final PackageVO packageVO : packages) {
142             Collection<EntityVO> entities = packageVO.getEntities();
143             for (final EntityVO entityVO : entities) {
144                 fqns.add(MessageFormat.format(pattern, packageVO.getName(), entityVO.getName()));
145             }
146         }
147     }
148 
149 }