1 package net.sourceforge.jgeocoder.tiger;
2
3 import java.io.Serializable;
4
5 import javax.sql.DataSource;
6
7 import net.sourceforge.jgeocoder.CommonUtils;
8
9 import org.apache.commons.lang.builder.EqualsBuilder;
10 import org.apache.commons.lang.builder.HashCodeBuilder;
11 import org.apache.commons.lang.builder.ToStringBuilder;
12 /***
13 * TODO javadocs me
14 * @author jliang
15 *
16 */
17 public class JGeocoderConfig implements Serializable{
18 private static final long serialVersionUID = 20080604L;
19 public static final JGeocoderConfig DEFAULT = new JGeocoderConfig();
20 private String _jgeocoderDataHome =
21 CommonUtils.nvl(System.getProperty("jgeocoder.data.home"), "/usr/local/jgeocoder/data");
22
23 private DataSource _tigerDataSource = null;
24
25 private long _berkeleyDbCacheSize = -1;
26 private int _berkeleyDbCachePercent = -1;
27
28 /***
29 * get the {@link DataSource} to the tiger/line address database
30 * @return
31 */
32 public synchronized DataSource getTigerDataSource() {
33 if(_tigerDataSource == null){
34 _tigerDataSource = H2DbDataSourceFactory.getH2DbDataSource();
35 }
36 return _tigerDataSource;
37 }
38
39 public synchronized void setTigerDataSource(DataSource tigerDataSource) {
40 _tigerDataSource = tigerDataSource;
41 }
42
43 /***
44 * <p>By default, JE sets its cache size proportionally to the JVM
45 memory. This formula is used:</p>
46
47 <blockquote><pre>je.maxMemoryPercent * JVM maximum memory
48 </pre></blockquote>
49
50 <p>where JVM maximum memory is specified by the JVM -Xmx flag.
51 setCachePercent() specifies the percentage used and is equivalent to
52 setting the je.maxMemoryPercent property in the je.properties file.</p>
53
54 <p>Calling setCacheSize() with a non-zero value overrides the percentage
55 based calculation and sets the cache size explicitly.</p>
56
57 <p>Note that the log buffer cache may be cleared if the cache size is
58 changed after the environment has been opened.</p>
59
60 <p>If setSharedCache(true) is called, setCacheSize and setCachePercent
61 specify the total size of the shared cache, and changing these
62 parameters will change the size of the shared cache.</p>
63 * @param berkeleyDbCachePercent berkeleyDb default will be used if set to negative
64 */
65 public int getBerkeleyDbCachePercent() {
66 return _berkeleyDbCachePercent;
67 }
68
69 public void setBerkeleyDbCachePercent(int berkeleyDbCachePercent) {
70 _berkeleyDbCachePercent = berkeleyDbCachePercent;
71 }
72 /***
73 * see http://www.oracle.com/technology/documentation/berkeley-db/je/java/com/sleepycat/je/EnvironmentMutableConfig.html#setCachePercent(int)
74 * @return
75 */
76 public long getBerkeleyDbCacheSize() {
77 return _berkeleyDbCacheSize;
78 }
79 /***
80 * Configures the memory available to the database system, in bytes.
81 <p>Equivalent to setting the je.maxMemory property in the je.properties
82 file. The system will evict database objects when it comes within a
83 prescribed margin of the limit.</p>
84
85 <p>By default, JE sets the cache size to:</p>
86
87 <pre><blockquote>je.maxMemoryPercent * JVM maximum memory
88 </blockquote></pre>
89
90 <p>where JVM maximum memory is specified by the JVM -Xmx flag. However,
91 calling setCacheSize() with a non-zero value overrides the percentage
92 based calculation and sets the cache size explicitly.</p>
93
94 <p>Note that the cache does not include transient objects created by the
95 JE library, such as cursors, locks and transactions.</p>
96
97 <p>Note that the log buffer cache may be cleared if the cache size is
98 changed after the environment has been opened.</p>
99
100 <p>If setSharedCache(true) is called, setCacheSize and setCachePercent
101 specify the total size of the shared cache, and changing these
102 parameters will change the size of the shared cache.</p>
103 @param berkeleyDbCacheSize berkeleyDb default will be used if set to negative
104 */
105 public void setBerkeleyDbCacheSize(long berkeleyDbCacheSize) {
106 _berkeleyDbCacheSize = berkeleyDbCacheSize;
107 }
108
109 public String getJgeocoderDataHome() {
110 return _jgeocoderDataHome;
111 }
112 public void setJgeocoderDataHome(String jgeocoderDataHome) {
113 _jgeocoderDataHome = jgeocoderDataHome;
114 }
115
116 @Override
117 public String toString() {
118 return ToStringBuilder.reflectionToString(this);
119 }
120 @Override
121 public int hashCode() {
122 return HashCodeBuilder.reflectionHashCode(this);
123 }
124 @Override
125 public boolean equals(Object obj) {
126 return EqualsBuilder.reflectionEquals(this, obj);
127 }
128
129
130
131 }