001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/db/DBStringFactory.java,v 1.14 2002/02/16 15:28:34 alex Exp $
003: *
004: */
005: package com.teamkonzept.db;
006:
007: import org.apache.log4j.Category;
008:
009: /**
010: * provides databasespecific strings
011: *
012: * @author
013: * @version
014: */
015: public class DBStringFactory {
016:
017: /** no default */
018: private static final String NO_DEFAULT = " NO_DEFAULT ";
019: private static final String DEFAULT_IS_NULL = " IS NULL ";
020: private static final String DEFAULT_IS_NOT_NULL = " IS NOT NULL ";
021: private static final String DEFAULT_NULL_VALUE = " NULL ";
022: private static final String DEFAULT_TEMP = " ";
023: private static final String DEFAULT_TRANS = " ";
024: private static final String DEFAULT_JOIN = " ";
025: private static final String DEFAULT_FROM = " ";
026: private static final String DEFAULT_ESCAPE = " ESCAPE '\\' ";
027: /** wird nur für postgres gebraucht, da postgres casesensitive sortiert */
028: private static final String DEFAULT_UPPER_ORDER = "";
029:
030: public static String equalsNull() {
031: return getDBStringFactory().specEqualsNull();
032: }
033:
034: public static String declareAsTemp() {
035: return getDBStringFactory().specDeclareAsTemp();
036: }
037:
038: public static String declareForTransaction() {
039: return getDBStringFactory().specDeclareForTransaction();
040: }
041:
042: public static String notEqualsNull() {
043: return getDBStringFactory().specNotEqualsNull();
044: }
045:
046: public static String nullValue() {
047: return getDBStringFactory().specNullValue();
048: }
049:
050: public static String nvl() {
051: return getDBStringFactory().specNvl();
052: }
053:
054: public static String checkExistence() {
055: return getDBStringFactory().specCheckExistence();
056: }
057:
058: public static String getFromSystem() {
059: return getDBStringFactory().specGetFromSystem();
060: }
061:
062: public static String leftOuterJoin(String leftColumn,
063: String rightColumn) {
064: return getDBStringFactory().specLeftOuterJoin(leftColumn,
065: rightColumn);
066: }
067:
068: public static String rightOuterJoin(String leftColumn,
069: String rightColumn) {
070: return getDBStringFactory().specRightOuterJoin(leftColumn,
071: rightColumn);
072: }
073:
074: public static String leftOuterJoinFrom(String[] columns,
075: String leftTable, String rightTable) {
076: return getDBStringFactory().specLeftOuterJoinFrom(columns,
077: leftTable, rightTable);
078: }
079:
080: public static String rightOuterJoinFrom(String[] columns,
081: String leftTable, String rightTable) {
082: return getDBStringFactory().specRightOuterJoinFrom(columns,
083: leftTable, rightTable);
084: }
085:
086: /** Escape befehl für like stm. */
087: public static String escape() {
088: return getDBStringFactory().specEscape();
089: }
090:
091: /** wird nur für postgres gebraucht, da postgres casesensitive sortiert
092: @return upperbefehl */
093: public static String upper_order() {
094: return getDBStringFactory().specupperorder();
095: }
096:
097: public static DBStringFactory getDBStringFactory() {
098: return getDBStringFactory(TKDBManager.getManager()
099: .getConnectionData());
100: }
101:
102: public static DBStringFactory getDBStringFactory(
103: TKConnectData connectData) {
104:
105: if (connectData instanceof TKOracleConnectData) {
106: return new OracleStringFactory();
107: }
108: if (connectData instanceof TKSybaseConnectData) {
109: return new SybaseStringFactory();
110: }
111: if (connectData instanceof TKPostgreSQLConnectData) {
112: return new PostgreSQLStringFactory();
113: } else {
114: return new DBStringFactory();
115: }
116: }
117:
118: public static DBStringFactory getDBStringFactory(
119: TKOracleConnectData connectData) {
120: return new OracleStringFactory();
121: }
122:
123: public static DBStringFactory getDBStringFactory(
124: TKSybaseConnectData connectData) {
125: return new SybaseStringFactory();
126: }
127:
128: public static DBStringFactory getDBStringFactory(
129: TKPostgreSQLConnectData connectData) {
130: return new PostgreSQLStringFactory();
131: }
132:
133: /* defaultimplementations, can be overridden by subclasses */
134:
135: protected String specNullValue() {
136: return DEFAULT_NULL_VALUE;
137: };
138:
139: /** create a temporary table */
140: protected String specDeclareAsTemp() {
141: return DEFAULT_TEMP;
142: }
143:
144: /** data in temporary table is persistent for one transaction */
145: protected String specDeclareForTransaction() {
146: return DEFAULT_TRANS;
147: }
148:
149: /** compare a value to null */
150: protected String specEqualsNull() {
151: return DEFAULT_IS_NULL;
152: }
153:
154: /** escape */
155: protected String specEscape() {
156: return DEFAULT_ESCAPE;
157: }
158:
159: /** wird nur für postgres gebraucht, da postgres casesensitive sortiert */
160: protected String specupperorder() {
161: return DEFAULT_UPPER_ORDER;
162: }
163:
164: protected String specNotEqualsNull() {
165: return DEFAULT_IS_NOT_NULL;
166: }
167:
168: /** if null then...*/
169: protected String specNvl() {
170: return NO_DEFAULT;
171: }
172:
173: protected String specCheckExistence() {
174: return NO_DEFAULT;
175: }
176:
177: protected String specGetFromSystem() {
178: return DEFAULT_FROM;
179: }
180:
181: /** left outer loin on the given columns */
182: protected String specLeftOuterJoin(String leftColumn,
183: String rightColumn) {
184: return DEFAULT_JOIN;
185: }
186:
187: /** right outer loin on the given columns */
188: protected String specRightOuterJoin(String leftColumn,
189: String rightColumn) {
190: return DEFAULT_JOIN;
191: }
192:
193: /** left outer loin on the given columns */
194: protected String specLeftOuterJoinFrom(String[] columns,
195: String leftTable, String rightTable) {
196: return DEFAULT_JOIN;
197: }
198:
199: /** right outer loin on the given columns */
200: protected String specRightOuterJoinFrom(String[] columns,
201: String leftTable, String rightTable) {
202: return DEFAULT_JOIN;
203: }
204: }
|