001: package liquibase.database;
002:
003: import liquibase.exception.JDBCException;
004:
005: import java.sql.Connection;
006: import java.sql.ResultSet;
007: import java.sql.SQLException;
008: import java.sql.Types;
009:
010: public class UnsupportedDatabase extends AbstractDatabase {
011: private String dateTimeType;
012:
013: public void setConnection(Connection conn) {
014: super .setConnection(conn);
015: dateTimeType = findDateTypeType();
016: if (currentDateTimeFunction == null) {
017: currentDateTimeFunction = findCurrentDateTimeFunction();
018: }
019: }
020:
021: /**
022: * Always returns null or DATABASECHANGELOG table may not be found.
023: */
024: public String getDefaultCatalogName() throws JDBCException {
025: return null;
026: }
027:
028: /**
029: * Always returns null or DATABASECHANGELOG table may not be found.
030: */
031: protected String getDefaultDatabaseSchemaName()
032: throws JDBCException {
033: return null;
034: }
035:
036: public String getBooleanType() {
037: return "INT";
038: }
039:
040: public String getFalseBooleanValue() {
041: return "0";
042: }
043:
044: public String getTrueBooleanValue() {
045: return "1";
046: }
047:
048: public String getCurrencyType() {
049: return "DECIMAL";
050: }
051:
052: public String getUUIDType() {
053: return "CHAR(36)";
054: }
055:
056: public String getClobType() {
057: return "CLOB";
058: }
059:
060: public String getBlobType() {
061: return "BLOB";
062: }
063:
064: public String getDateTimeType() {
065: return dateTimeType;
066: }
067:
068: private String findDateTypeType() {
069: ResultSet typeInfo = null;
070: try {
071: typeInfo = getConnection().getMetaData().getTypeInfo();
072: while (typeInfo.next()) {
073: if (typeInfo.getInt("DATA_TYPE") == Types.TIMESTAMP) {
074: return typeInfo.getString("TYPE_NAME");
075: }
076: }
077: } catch (SQLException e) {
078: throw new RuntimeException(e);
079: } finally {
080: if (typeInfo != null) {
081: try {
082: typeInfo.close();
083: } catch (SQLException e) {
084: ;
085: }
086: }
087: }
088: return "DATETIME";
089: }
090:
091: public boolean isCorrectDatabaseImplementation(Connection conn)
092: throws JDBCException {
093: return false;
094: }
095:
096: public String getDefaultDriver(String url) {
097: return null;
098: }
099:
100: public String getProductName() {
101: return "Unsupported Database (" + getDatabaseProductName()
102: + ")";
103: }
104:
105: public String getTypeName() {
106: return getDatabaseProductName().toLowerCase().replaceAll("\\W",
107: "");
108: }
109:
110: public boolean supportsInitiallyDeferrableColumns() {
111: return false;
112: }
113:
114: public String getCurrentDateTimeFunction() {
115: return currentDateTimeFunction;
116: }
117:
118: private String findCurrentDateTimeFunction() {
119: try {
120: String nowFunction = null;
121: String dateFunction = null;
122: String dateTimeFunction = null;
123: String timeStampFunction = null;
124:
125: String[] timeDateFunctions = getConnection().getMetaData()
126: .getTimeDateFunctions().split(",");
127: for (String functionName : timeDateFunctions) {
128: String function = functionName.trim().toUpperCase();
129: if (function.endsWith("TIMESTAMP")) {
130: timeStampFunction = functionName.trim();
131: }
132: if (function.endsWith("DATETIME")) {
133: dateTimeFunction = functionName.trim();
134: }
135: if (function.endsWith("DATE")) {
136: dateFunction = functionName.trim();
137: }
138: if ("NOW".equals(function)) {
139: nowFunction = functionName.trim();
140: }
141: }
142:
143: if (nowFunction != null) {
144: return "{fn " + nowFunction + "()" + "}";
145: } else if (timeStampFunction != null) {
146: return "{fn " + timeStampFunction + "()" + "}";
147: } else if (dateTimeFunction != null) {
148: return "{fn " + dateTimeFunction + "()" + "}";
149: } else if (dateFunction != null) {
150: return "{fn " + dateFunction + "()" + "}";
151: } else {
152: return "NOW()";
153: }
154:
155: } catch (SQLException e) {
156: throw new RuntimeException(e);
157: }
158: }
159:
160: protected boolean canCreateChangeLogTable() throws JDBCException {
161: //check index size. Many drivers just return 0, so it's not a great test
162: int maxIndexLength;
163: try {
164: maxIndexLength = getConnection().getMetaData()
165: .getMaxIndexLength();
166:
167: return maxIndexLength == 0
168: || maxIndexLength >= 150 + 150 + 255 //id + author + filename length
169: && super .canCreateChangeLogTable();
170: } catch (SQLException e) {
171: throw new JDBCException(e);
172: }
173: }
174:
175: public boolean supportsTablespaces() {
176: return false;
177: }
178: }
|