001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.entity.config;
019:
020: import java.util.LinkedList;
021: import java.util.List;
022:
023: import org.ofbiz.base.util.Debug;
024: import org.ofbiz.base.util.UtilXml;
025: import org.w3c.dom.Element;
026:
027: /**
028: * Misc. utility method for dealing with the entityengine.xml file
029: *
030: */
031: public class DatasourceInfo {
032: public static final String module = DatasourceInfo.class.getName();
033:
034: public String name;
035: public String helperClass;
036: public String fieldTypeName;
037: public List sqlLoadPaths = new LinkedList();
038: public List readDatas = new LinkedList();
039: public Element datasourceElement;
040:
041: public static final int TYPE_JNDI_JDBC = 1;
042: public static final int TYPE_INLINE_JDBC = 2;
043: public static final int TYPE_TYREX_DATA_SOURCE = 3;
044: public static final int TYPE_OTHER = 4;
045:
046: public Element jndiJdbcElement;
047: public Element tyrexDataSourceElement;
048: public Element inlineJdbcElement;
049:
050: public String schemaName = null;
051: public boolean useSchemas = true;
052: public boolean checkOnStart = true;
053: public boolean addMissingOnStart = false;
054: public boolean useFks = true;
055: public boolean useFkIndices = true;
056: public boolean checkPrimaryKeysOnStart = false;
057: public boolean checkForeignKeysOnStart = false;
058: public boolean checkFkIndicesOnStart = false;
059: public boolean usePkConstraintNames = true;
060: public int constraintNameClipLength = 30;
061: public boolean useProxyCursor = false;
062: public String cursorName = "p_cursor";
063: public int resultFetchSize = -1;
064: public String fkStyle = null;
065: public boolean useFkInitiallyDeferred = true;
066: public boolean useIndices = true;
067: public boolean checkIndicesOnStart = false;
068: public String joinStyle = null;
069: public boolean aliasViews = true;
070: public boolean alwaysUseConstraintKeyword = false;
071: public boolean dropFkUseForeignKeyKeyword = false;
072: public boolean useBinaryTypeForBlob = false;
073: public String tableType = null;
074: public String characterSet = null;
075: public String collate = null;
076:
077: public DatasourceInfo(Element element) {
078: this .name = element.getAttribute("name");
079: this .helperClass = element.getAttribute("helper-class");
080: this .fieldTypeName = element.getAttribute("field-type-name");
081:
082: sqlLoadPaths = UtilXml.childElementList(element,
083: "sql-load-path");
084: readDatas = UtilXml.childElementList(element, "read-data");
085: datasourceElement = element;
086:
087: if (datasourceElement == null) {
088: Debug.logWarning("datasource def not found with name "
089: + this .name
090: + ", using default for schema-name (none)", module);
091: Debug.logWarning("datasource def not found with name "
092: + this .name
093: + ", using default for use-schemas (true)", module);
094: Debug.logWarning("datasource def not found with name "
095: + this .name
096: + ", using default for check-on-start (true)",
097: module);
098: Debug
099: .logWarning(
100: "datasource def not found with name "
101: + this .name
102: + ", using default for add-missing-on-start (false)",
103: module);
104: Debug.logWarning("datasource def not found with name "
105: + this .name
106: + ", using default for check-pks-on-start (true)",
107: module);
108: Debug.logWarning("datasource def not found with name "
109: + this .name
110: + ", using default for use-foreign-keys (true)",
111: module);
112: Debug.logWarning("datasource def not found with name "
113: + this .name
114: + ", using default use-foreign-key-indices (true)",
115: module);
116: Debug.logWarning("datasource def not found with name "
117: + this .name
118: + ", using default for check-fks-on-start (false)",
119: module);
120: Debug
121: .logWarning(
122: "datasource def not found with name "
123: + this .name
124: + ", using default for check-fk-indices-on-start (false)",
125: module);
126: Debug
127: .logWarning(
128: "datasource def not found with name "
129: + this .name
130: + ", using default for use-pk-constraint-names (true)",
131: module);
132: Debug
133: .logWarning(
134: "datasource def not found with name "
135: + this .name
136: + ", using default for constraint-name-clip-length (30)",
137: module);
138: Debug.logWarning("datasource def not found with name "
139: + this .name
140: + ", using default for fk-style (name_constraint)",
141: module);
142: Debug
143: .logWarning(
144: "datasource def not found with name "
145: + this .name
146: + ", using default for use-fk-initially-deferred (true)",
147: module);
148: Debug.logWarning("datasource def not found with name "
149: + this .name
150: + ", using default for use-indices (true)", module);
151: Debug
152: .logWarning(
153: "datasource def not found with name "
154: + this .name
155: + ", using default for check-indices-on-start (false)",
156: module);
157: Debug.logWarning("datasource def not found with name "
158: + this .name
159: + ", using default for join-style (ansi)", module);
160: Debug
161: .logWarning(
162: "datasource def not found with name "
163: + this .name
164: + ", using default for always-use-constraint-keyword (false)",
165: module);
166: Debug
167: .logWarning(
168: "datasource def not found with name "
169: + this .name
170: + ", using default for drop-fk-use-foreign-key-keyword (false)",
171: module);
172: Debug
173: .logWarning(
174: "datasource def not found with name "
175: + this .name
176: + ", using default for use-binary-type-for-blob (false)",
177: module);
178: Debug.logWarning("datasource def not found with name "
179: + this .name
180: + ", using default for table-type (none)", module);
181: Debug.logWarning("datasource def not found with name "
182: + this .name
183: + ", using default for character-set (none)",
184: module);
185: Debug.logWarning("datasource def not found with name "
186: + this .name + ", using default for collate (none)",
187: module);
188: } else {
189: this .schemaName = datasourceElement
190: .getAttribute("schema-name");
191: // anything but false is true
192: this .useSchemas = !"false".equals(datasourceElement
193: .getAttribute("use-schemas"));
194: // anything but false is true
195: this .checkOnStart = !"false".equals(datasourceElement
196: .getAttribute("check-on-start"));
197: // anything but false is true
198: this .checkPrimaryKeysOnStart = !"false"
199: .equals(datasourceElement
200: .getAttribute("check-pks-on-start"));
201: // anything but true is false
202: this .addMissingOnStart = "true".equals(datasourceElement
203: .getAttribute("add-missing-on-start"));
204: // anything but false is true
205: this .useFks = !"false".equals(datasourceElement
206: .getAttribute("use-foreign-keys"));
207: // anything but false is true
208: this .useFkIndices = !"false".equals(datasourceElement
209: .getAttribute("use-foreign-key-indices"));
210: // anything but true is false
211: this .checkForeignKeysOnStart = "true"
212: .equals(datasourceElement
213: .getAttribute("check-fks-on-start"));
214: // anything but true is false
215: this .checkFkIndicesOnStart = "true"
216: .equals(datasourceElement
217: .getAttribute("check-fk-indices-on-start"));
218: // anything but false is true
219: this .usePkConstraintNames = !"false"
220: .equals(datasourceElement
221: .getAttribute("use-pk-constraint-names"));
222: try {
223: this .constraintNameClipLength = Integer
224: .parseInt(datasourceElement
225: .getAttribute("constraint-name-clip-length"));
226: } catch (Exception e) {
227: Debug
228: .logError(
229: "Could not parse constraint-name-clip-length value for datasource with name "
230: + this .name
231: + ", using default value of 30",
232: module);
233: }
234: this .useProxyCursor = "true"
235: .equalsIgnoreCase(datasourceElement
236: .getAttribute("use-proxy-cursor"));
237: this .cursorName = datasourceElement
238: .getAttribute("proxy-cursor-name");
239: try {
240: this .resultFetchSize = Integer
241: .parseInt(datasourceElement
242: .getAttribute("result-fetch-size"));
243: } catch (Exception e) {
244: Debug.logWarning(
245: "Could not parse result-fetch-size value for datasource with name "
246: + this .name
247: + ", using JDBC driver default value",
248: module);
249: }
250: this .fkStyle = datasourceElement.getAttribute("fk-style");
251: // anything but true is false
252: this .useFkInitiallyDeferred = "true"
253: .equals(datasourceElement
254: .getAttribute("use-fk-initially-deferred"));
255: // anything but false is true
256: this .useIndices = !"false".equals(datasourceElement
257: .getAttribute("use-indices"));
258: // anything but true is false
259: this .checkIndicesOnStart = "true".equals(datasourceElement
260: .getAttribute("check-indices-on-start"));
261: this .joinStyle = datasourceElement
262: .getAttribute("join-style");
263: this .aliasViews = !"false".equals(datasourceElement
264: .getAttribute("alias-view-columns"));
265: // anything but true is false
266: this .alwaysUseConstraintKeyword = "true"
267: .equals(datasourceElement
268: .getAttribute("always-use-constraint-keyword"));
269: this .dropFkUseForeignKeyKeyword = "true"
270: .equals(datasourceElement
271: .getAttribute("drop-fk-use-foreign-key-keyword"));
272: this .useBinaryTypeForBlob = "true".equals(datasourceElement
273: .getAttribute("use-binary-type-for-blob"));
274:
275: this .tableType = datasourceElement
276: .getAttribute("table-type");
277: this .characterSet = datasourceElement
278: .getAttribute("character-set");
279: this .collate = datasourceElement.getAttribute("collate");
280: }
281: if (this .fkStyle == null || this .fkStyle.length() == 0)
282: this .fkStyle = "name_constraint";
283: if (this .joinStyle == null || this .joinStyle.length() == 0)
284: this .joinStyle = "ansi";
285:
286: this .jndiJdbcElement = UtilXml.firstChildElement(
287: datasourceElement, "jndi-jdbc");
288: this .tyrexDataSourceElement = UtilXml.firstChildElement(
289: datasourceElement, "tyrex-dataSource");
290: this .inlineJdbcElement = UtilXml.firstChildElement(
291: datasourceElement, "inline-jdbc");
292: }
293: }
|