001: /*
002: * Copyright (C) 2005 Whitestein Technologies AG, Poststrasse 22, CH-6300 Zug, Switzerland.
003: * All rights reserved. The use of this file in source or binary form requires a written license from Whitestein Technologies AG.
004: *
005: */
006: package liquibase.database;
007:
008: import liquibase.database.sql.RawSqlStatement;
009: import liquibase.database.sql.SqlStatement;
010: import liquibase.exception.JDBCException;
011:
012: import java.sql.Connection;
013: import java.util.HashSet;
014: import java.util.Set;
015:
016: public class MaxDBDatabase extends AbstractDatabase {
017:
018: public static final String PRODUCT_NAME = "SAP DB";
019: protected Set<String> systemTablesAndViews = new HashSet<String>();
020:
021: public MaxDBDatabase() {
022: super ();
023: systemTablesAndViews.add("---");
024:
025: systemTablesAndViews.add("ACTIVECONFIGURATION");
026: systemTablesAndViews.add("BACKUPTHREADS");
027: systemTablesAndViews.add("CACHESTATISTICS");
028: systemTablesAndViews.add("CATALOGCACHESTATISTICS");
029: systemTablesAndViews.add("COMMANDCACHESTATISTICS");
030: systemTablesAndViews.add("COMMANDCACHESTATISTICSRESET");
031: systemTablesAndViews.add("COMMANDSTATISTICS");
032: systemTablesAndViews.add("COMMANDSTATISTICSRESET");
033: systemTablesAndViews.add("CONSISTENTVIEWS");
034: systemTablesAndViews.add("DATACACHE");
035: systemTablesAndViews.add("DATASTATISTICS");
036: systemTablesAndViews.add("DATASTATISTICSRESET");
037: systemTablesAndViews.add("DATAVOLUMES");
038: systemTablesAndViews.add("DATASTATISTICSRESET");
039: systemTablesAndViews.add("FILEDIRECTORIES");
040: systemTablesAndViews.add("FILES");
041: systemTablesAndViews.add("HOTSTANDBYCOMPONENT");
042: systemTablesAndViews.add("HOTSTANDBYGROUP");
043: systemTablesAndViews.add("INSTANCE");
044: systemTablesAndViews.add("IOBUFFERCACHES");
045: systemTablesAndViews.add("IOTHREADSTATISTICS");
046: systemTablesAndViews.add("IOTHREADSTATISTICSRESET");
047: systemTablesAndViews.add("INDEXSIZE");
048: systemTablesAndViews.add("INDEXSTORAGEDETAILS");
049: systemTablesAndViews.add("LOGINFORMATION");
050: systemTablesAndViews.add("LOGQUEUESTATISTICS");
051: systemTablesAndViews.add("LOGQUEUESTATISTICSRESET");
052: systemTablesAndViews.add("LOGSTATISTICS");
053: systemTablesAndViews.add("LOGSTATISTICSRESET");
054: systemTablesAndViews.add("LOGVOLUMES");
055: systemTablesAndViews.add("MACHINECONFIGURATION");
056: systemTablesAndViews.add("MACHINEUTILIZATION");
057: systemTablesAndViews.add("MEMORYALLOCATORSTATISTICS");
058: systemTablesAndViews.add("OPTIMIZERINFORMATION");
059: systemTablesAndViews.add("READERWRITERLOCKINFORMATION");
060: systemTablesAndViews.add("READERWRITERLOCKSTATISTICS");
061: systemTablesAndViews.add("READERWRITERLOCKSTATISTICSRESET");
062: systemTablesAndViews.add("READERWRITERLOCKWAITINGTASKS");
063: systemTablesAndViews.add("REGIONINFORMATION");
064: systemTablesAndViews.add("REGIONSTATISTICS");
065: systemTablesAndViews.add("REGIONSTATISTICSRESET");
066: systemTablesAndViews.add("RESTARTINFORMATION");
067: systemTablesAndViews.add("SCHEMASIZE");
068: systemTablesAndViews.add("SERVERTASKS");
069: systemTablesAndViews.add("SESSIONS");
070: systemTablesAndViews.add("SNAPSHOTS");
071: systemTablesAndViews.add("SPINLOCKPOOLSTATISTICS");
072: systemTablesAndViews.add("SPINLOCKPOOLSTATISTICSRESET");
073: systemTablesAndViews.add("SPINLOCKSTATISTICS");
074: systemTablesAndViews.add("SPINLOCKSTATISTICSRESET");
075: systemTablesAndViews.add("TABLESIZE");
076: systemTablesAndViews.add("TABLESTORAGEDETAILS");
077: systemTablesAndViews.add("TASKGROUPSTATISTICS");
078: systemTablesAndViews.add("TASKGROUPSTATISTICSRESET");
079: systemTablesAndViews.add("TASKLOADBALANCINGINFORMATION");
080: systemTablesAndViews.add("TASKLOADBALANCINGTASKGROUPSTATES");
081: systemTablesAndViews.add("TASKLOADBALANCINGTASKMOVES");
082: systemTablesAndViews.add("TRANSACTIONHISTORY");
083: systemTablesAndViews.add("TRANSACTIONS");
084: systemTablesAndViews.add("UNLOADEDSTATEMENTS");
085: systemTablesAndViews.add("VERSION");
086: }
087:
088: public Set<String> getSystemTablesAndViews() {
089: return systemTablesAndViews;
090: }
091:
092: public String getProductName() {
093: return "MaxDB";
094: }
095:
096: public String getTypeName() {
097: return "maxdb";
098: }
099:
100: public boolean supportsInitiallyDeferrableColumns() {
101: return false;
102: }
103:
104: public boolean supportsSequences() {
105: return true;
106: }
107:
108: public String getBooleanType() {
109: return "BOOLEAN";
110: }
111:
112: public String getCurrencyType() {
113: return "NUMERIC(15, 2)";
114: }
115:
116: public String getUUIDType() {
117: return "CHAR(36)";
118: }
119:
120: public String getClobType() {
121: return "LONG VARCHAR";
122: }
123:
124: public String getBlobType() {
125: return "LONG BYTE";
126: }
127:
128: public String getDateTimeType() {
129: return "TIMESTAMP";
130: }
131:
132: public String getDateType() {
133: return "DATE";
134: }
135:
136: public String getTimeType() {
137: return "TIME";
138: }
139:
140: public boolean isCorrectDatabaseImplementation(Connection conn)
141: throws JDBCException {
142: return PRODUCT_NAME
143: .equalsIgnoreCase(getDatabaseProductName(conn));
144: }
145:
146: public String getDefaultDriver(String url) {
147: if (url.startsWith("jdbc:sapdb")) {
148: return "com.sap.dbtech.jdbc.DriverSapDB";
149: }
150: return null;
151: }
152:
153: public String getCurrentDateTimeFunction() {
154: return "TIMESTAMP";
155: }
156:
157: public String getTrueBooleanValue() {
158: return "TRUE";
159: }
160:
161: public String getFalseBooleanValue() {
162: return "FALSE";
163: }
164:
165: protected String getDefaultDatabaseSchemaName()
166: throws JDBCException {//NOPMD
167: return super .getDefaultDatabaseSchemaName().toUpperCase();
168: }
169:
170: public SqlStatement createFindSequencesSQL(String schema)
171: throws JDBCException {
172: return new RawSqlStatement(
173: "SELECT SEQUENCE_NAME FROM DOMAIN.SEQUENCES WHERE OWNER = '"
174: + convertRequestedSchemaToSchema(schema) + "'");
175: }
176:
177: public boolean isSystemTable(String catalogName, String schemaName,
178: String tableName) {
179: if (super .isSystemTable(catalogName, schemaName, tableName)) {
180: return true;
181: } else if ("DOMAIN".equalsIgnoreCase(schemaName)) {
182: return true;
183: } else if ("SYSINFO".equalsIgnoreCase(schemaName)) {
184: return true;
185: } else if ("SYSLOADER".equalsIgnoreCase(schemaName)) {
186: return true;
187: } else if ("SYSDBA".equalsIgnoreCase(schemaName)) {
188: return true;
189: }
190: return false;
191: }
192:
193: public boolean isSystemView(String catalogName, String schemaName,
194: String tableName) {
195: if (super .isSystemView(catalogName, schemaName, tableName)) {
196: return true;
197: } else if ("DOMAIN".equalsIgnoreCase(schemaName)) {
198: return true;
199: } else if ("SYSINFO".equalsIgnoreCase(schemaName)) {
200: return true;
201: } else if ("SYSLOADER".equalsIgnoreCase(schemaName)) {
202: return true;
203: } else if ("SYSDBA".equalsIgnoreCase(schemaName)) {
204: return true;
205: }
206: return false;
207: }
208:
209: public boolean supportsTablespaces() {
210: return false;
211: }
212:
213: public SqlStatement getViewDefinitionSql(String schemaName,
214: String name) throws JDBCException {
215: return new RawSqlStatement(
216: "SELECT DEFINITION FROM DOMAIN.VIEWDEFS WHERE upper(VIEWNAME)='"
217: + name.toUpperCase() + "' AND OWNER='"
218: + convertRequestedSchemaToSchema(schemaName)
219: + "'");
220: }
221:
222: public boolean supportsAutoIncrement() {
223: return false;
224: }
225:
226: public String convertJavaObjectToString(Object value) {
227: if (value instanceof Boolean) {
228: if (((Boolean) value)) {
229: return this.getTrueBooleanValue();
230: } else {
231: return this.getFalseBooleanValue();
232: }
233: } else {
234: return super.convertJavaObjectToString(value);
235: }
236: }
237:
238: }
|