KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > config > DatasourceInfo


1 /*
2  * $Id: DatasourceInfo.java 5759 2005-09-17 04:45:42Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.entity.config;
26
27 import java.util.LinkedList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.ofbiz.base.util.Debug;
31 import org.ofbiz.base.util.UtilXml;
32 import org.w3c.dom.Element JavaDoc;
33
34 /**
35  * Misc. utility method for dealing with the entityengine.xml file
36  *
37  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
38  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
39  * @version $Rev: 5759 $
40  * @since 2.0
41  */

42 public class DatasourceInfo {
43     public static final String JavaDoc module = DatasourceInfo.class.getName();
44
45     public String JavaDoc name;
46     public String JavaDoc helperClass;
47     public String JavaDoc fieldTypeName;
48     public List JavaDoc sqlLoadPaths = new LinkedList JavaDoc();
49     public List JavaDoc readDatas = new LinkedList JavaDoc();
50     public Element JavaDoc datasourceElement;
51     
52     public static final int TYPE_JNDI_JDBC = 1;
53     public static final int TYPE_INLINE_JDBC = 2;
54     public static final int TYPE_TYREX_DATA_SOURCE = 3;
55     public static final int TYPE_OTHER = 4;
56             
57     public Element JavaDoc jndiJdbcElement;
58     public Element JavaDoc tyrexDataSourceElement;
59     public Element JavaDoc inlineJdbcElement;
60
61     public String JavaDoc schemaName = null;
62     public boolean useSchemas = true;
63     public boolean checkOnStart = true;
64     public boolean addMissingOnStart = false;
65     public boolean useFks = true;
66     public boolean useFkIndices = true;
67     public boolean checkPrimaryKeysOnStart = false;
68     public boolean checkForeignKeysOnStart = false;
69     public boolean checkFkIndicesOnStart = false;
70     public boolean usePkConstraintNames = true;
71     public int constraintNameClipLength = 30;
72     public boolean useProxyCursor = false;
73     public String JavaDoc cursorName = "p_cursor";
74     public int resultFetchSize = -1;
75     public String JavaDoc fkStyle = null;
76     public boolean useFkInitiallyDeferred = true;
77     public boolean useIndices = true;
78     public boolean checkIndicesOnStart = false;
79     public String JavaDoc joinStyle = null;
80     public boolean aliasViews = true;
81     public boolean alwaysUseConstraintKeyword = false;
82     public boolean dropFkUseForeignKeyKeyword = false;
83     public String JavaDoc tableType = null;
84     public String JavaDoc characterSet = null;
85     public String JavaDoc collate = null;
86
87     public DatasourceInfo(Element JavaDoc element) {
88         this.name = element.getAttribute("name");
89         this.helperClass = element.getAttribute("helper-class");
90         this.fieldTypeName = element.getAttribute("field-type-name");
91
92         sqlLoadPaths = UtilXml.childElementList(element, "sql-load-path");
93         readDatas = UtilXml.childElementList(element, "read-data");
94         datasourceElement = element;
95
96         if (datasourceElement == null) {
97             Debug.logWarning("datasource def not found with name " + this.name + ", using default for schema-name (none)", module);
98             Debug.logWarning("datasource def not found with name " + this.name + ", using default for use-schemas (true)", module);
99             Debug.logWarning("datasource def not found with name " + this.name + ", using default for check-on-start (true)", module);
100             Debug.logWarning("datasource def not found with name " + this.name + ", using default for add-missing-on-start (false)", module);
101             Debug.logWarning("datasource def not found with name " + this.name + ", using default for check-pks-on-start (true)", module);
102             Debug.logWarning("datasource def not found with name " + this.name + ", using default for use-foreign-keys (true)", module);
103             Debug.logWarning("datasource def not found with name " + this.name + ", using default use-foreign-key-indices (true)", module);
104             Debug.logWarning("datasource def not found with name " + this.name + ", using default for check-fks-on-start (false)", module);
105             Debug.logWarning("datasource def not found with name " + this.name + ", using default for check-fk-indices-on-start (false)", module);
106             Debug.logWarning("datasource def not found with name " + this.name + ", using default for use-pk-constraint-names (true)", module);
107             Debug.logWarning("datasource def not found with name " + this.name + ", using default for constraint-name-clip-length (30)", module);
108             Debug.logWarning("datasource def not found with name " + this.name + ", using default for fk-style (name_constraint)", module);
109             Debug.logWarning("datasource def not found with name " + this.name + ", using default for use-fk-initially-deferred (true)", module);
110             Debug.logWarning("datasource def not found with name " + this.name + ", using default for use-indices (true)", module);
111             Debug.logWarning("datasource def not found with name " + this.name + ", using default for check-indices-on-start (false)", module);
112             Debug.logWarning("datasource def not found with name " + this.name + ", using default for join-style (ansi)", module);
113             Debug.logWarning("datasource def not found with name " + this.name + ", using default for always-use-constraint-keyword (false)", module);
114             Debug.logWarning("datasource def not found with name " + this.name + ", using default for drop-fk-use-foreign-key-keyword (false)", module);
115             Debug.logWarning("datasource def not found with name " + this.name + ", using default for table-type (none)", module);
116             Debug.logWarning("datasource def not found with name " + this.name + ", using default for character-set (none)", module);
117             Debug.logWarning("datasource def not found with name " + this.name + ", using default for collate (none)", module);
118         } else {
119             this.schemaName = datasourceElement.getAttribute("schema-name");
120             // anything but false is true
121
this.useSchemas = !"false".equals(datasourceElement.getAttribute("use-schemas"));
122             // anything but false is true
123
this.checkOnStart = !"false".equals(datasourceElement.getAttribute("check-on-start"));
124             // anything but false is true
125
this.checkPrimaryKeysOnStart = !"false".equals(datasourceElement.getAttribute("check-pks-on-start"));
126             // anything but true is false
127
this.addMissingOnStart = "true".equals(datasourceElement.getAttribute("add-missing-on-start"));
128             // anything but false is true
129
this.useFks = !"false".equals(datasourceElement.getAttribute("use-foreign-keys"));
130             // anything but false is true
131
this.useFkIndices = !"false".equals(datasourceElement.getAttribute("use-foreign-key-indices"));
132             // anything but true is false
133
this.checkForeignKeysOnStart = "true".equals(datasourceElement.getAttribute("check-fks-on-start"));
134             // anything but true is false
135
this.checkFkIndicesOnStart = "true".equals(datasourceElement.getAttribute("check-fk-indices-on-start"));
136             // anything but false is true
137
this.usePkConstraintNames = !"false".equals(datasourceElement.getAttribute("use-pk-constraint-names"));
138             try {
139                 this.constraintNameClipLength = Integer.parseInt(datasourceElement.getAttribute("constraint-name-clip-length"));
140             } catch (Exception JavaDoc e) {
141                 Debug.logError("Could not parse constraint-name-clip-length value for datasource with name " + this.name + ", using default value of 30", module);
142             }
143             this.useProxyCursor = "true".equalsIgnoreCase(datasourceElement.getAttribute("use-proxy-cursor"));
144             this.cursorName = datasourceElement.getAttribute("proxy-cursor-name");
145             try {
146                 this.resultFetchSize = Integer.parseInt(datasourceElement.getAttribute("result-fetch-size"));
147             } catch (Exception JavaDoc e) {
148                 Debug.logWarning("Could not parse result-fetch-size value for datasource with name " + this.name + ", using JDBC driver default value", module);
149             }
150             this.fkStyle = datasourceElement.getAttribute("fk-style");
151             // anything but true is false
152
this.useFkInitiallyDeferred = "true".equals(datasourceElement.getAttribute("use-fk-initially-deferred"));
153             // anything but false is true
154
this.useIndices = !"false".equals(datasourceElement.getAttribute("use-indices"));
155             // anything but true is false
156
this.checkIndicesOnStart = "true".equals(datasourceElement.getAttribute("check-indices-on-start"));
157             this.joinStyle = datasourceElement.getAttribute("join-style");
158             this.aliasViews = !"false".equals(datasourceElement.getAttribute("alias-view-columns"));
159             // anything but true is false
160
this.alwaysUseConstraintKeyword = "true".equals(datasourceElement.getAttribute("always-use-constraint-keyword"));
161             this.dropFkUseForeignKeyKeyword = "true".equals(datasourceElement.getAttribute("drop-fk-use-foreign-key-keyword"));
162             
163             this.tableType = datasourceElement.getAttribute("table-type");
164             this.characterSet = datasourceElement.getAttribute("character-set");
165             this.collate = datasourceElement.getAttribute("collate");
166         }
167         if (this.fkStyle == null || this.fkStyle.length() == 0) this.fkStyle = "name_constraint";
168         if (this.joinStyle == null || this.joinStyle.length() == 0) this.joinStyle = "ansi";
169
170         this.jndiJdbcElement = UtilXml.firstChildElement(datasourceElement, "jndi-jdbc");
171         this.tyrexDataSourceElement = UtilXml.firstChildElement(datasourceElement, "tyrex-dataSource");
172         this.inlineJdbcElement = UtilXml.firstChildElement(datasourceElement, "inline-jdbc");
173     }
174 }
175
Popular Tags