001: package liquibase.database;
002:
003: import liquibase.ChangeSet;
004: import liquibase.RanChangeSet;
005: import liquibase.database.sql.SqlStatement;
006: import liquibase.database.structure.DatabaseObject;
007: import liquibase.database.template.JdbcTemplate;
008: import liquibase.exception.DatabaseHistoryException;
009: import liquibase.exception.JDBCException;
010:
011: import java.sql.Connection;
012: import java.sql.SQLException;
013: import java.text.ParseException;
014: import java.util.Date;
015: import java.util.List;
016:
017: public interface Database extends DatabaseObject {
018: /**
019: * Is this AbstractDatabase subclass the correct one to use for the given connection.
020: */
021: boolean isCorrectDatabaseImplementation(Connection conn)
022: throws JDBCException;
023:
024: /**
025: * If this database understands the given url, return the default driver class name. Otherwise return null.
026: */
027: String getDefaultDriver(String url);
028:
029: DatabaseConnection getConnection();
030:
031: void setConnection(Connection conn);
032:
033: void setConnection(DatabaseConnection conn);
034:
035: /**
036: * Auto-commit mode to run in
037: */
038: public boolean getAutoCommitMode();
039:
040: /**
041: * Determines if the database supports DDL within a transaction or not.
042: *
043: * @return True if the database supports DDL within a transaction, otherwise false.
044: */
045: boolean supportsDDLInTransaction();
046:
047: String getDatabaseProductName();
048:
049: String getDatabaseProductVersion() throws JDBCException;
050:
051: /**
052: * Returns the full database product name. May be different than what the JDBC connection reports (getDatabaseProductName())
053: */
054: String getProductName();
055:
056: /**
057: * Returns an all-lower-case short name of the product. Used for end-user selecting of database type
058: * such as the DBMS precondition.
059: */
060: String getTypeName();
061:
062: String getDriverName() throws JDBCException;
063:
064: String getConnectionURL() throws JDBCException;
065:
066: String getConnectionUsername() throws JDBCException;
067:
068: String getDefaultCatalogName() throws JDBCException;
069:
070: String getDefaultSchemaName();
071:
072: void setDefaultSchemaName(String schemaName) throws JDBCException;
073:
074: /**
075: * Returns whether this database support initially deferrable columns.
076: */
077: boolean supportsInitiallyDeferrableColumns();
078:
079: public boolean supportsSequences();
080:
081: public boolean supportsAutoIncrement();
082:
083: String getColumnType(String columnType, Boolean autoIncrement);
084:
085: String getFalseBooleanValue();
086:
087: String getTrueBooleanValue();
088:
089: String getDateLiteral(String isoDate);
090:
091: /**
092: * Returns database-specific function for generating the current date/time.
093: */
094: String getCurrentDateTimeFunction();
095:
096: void setCurrentDateTimeFunction(String function);
097:
098: String getLineComment();
099:
100: String getAutoIncrementClause();
101:
102: String getDatabaseChangeLogTableName();
103:
104: String getDatabaseChangeLogLockTableName();
105:
106: /**
107: * Returns SQL to concat the passed values.
108: */
109: String getConcatSql(String... values);
110:
111: boolean doesChangeLogTableExist();
112:
113: boolean doesChangeLogLockTableExist();
114:
115: void checkDatabaseChangeLogTable() throws JDBCException;
116:
117: void checkDatabaseChangeLogLockTable() throws JDBCException;
118:
119: void dropDatabaseObjects(String schema) throws JDBCException;
120:
121: void tag(String tagString) throws JDBCException;
122:
123: boolean doesTagExist(String tag) throws JDBCException;
124:
125: boolean isSystemTable(String catalogName, String schemaName,
126: String tableName);
127:
128: boolean isLiquibaseTable(String tableName);
129:
130: SqlStatement createFindSequencesSQL(String schema)
131: throws JDBCException;
132:
133: boolean shouldQuoteValue(String value);
134:
135: boolean supportsTablespaces();
136:
137: String getViewDefinition(String schemaName, String name)
138: throws JDBCException;
139:
140: int getDatabaseType(int type);
141:
142: String getDatabaseProductName(Connection conn) throws JDBCException;
143:
144: /**
145: * Returns the actual database-specific data type to use a "boolean" column.
146: */
147: String getBooleanType();
148:
149: /**
150: * Returns the actual database-specific data type to use a "currency" column.
151: */
152: String getCurrencyType();
153:
154: /**
155: * Returns the actual database-specific data type to use a "UUID" column.
156: */
157: String getUUIDType();
158:
159: /**
160: * Returns the actual database-specific data type to use a "CLOB" column.
161: */
162: String getClobType();
163:
164: /**
165: * Returns the actual database-specific data type to use a "BLOB" column.
166: */
167: String getBlobType();
168:
169: String getDateType();
170:
171: /**
172: * Returns the actual database-specific data type to use a "datetime" column.
173: */
174: String getDateTimeType();
175:
176: String getTimeType();
177:
178: Object convertDatabaseValueToJavaObject(Object defaultValue,
179: int dataType, int columnSize, int decimalDigits)
180: throws ParseException;
181:
182: String convertJavaObjectToString(Object value);
183:
184: boolean isSystemView(String catalogName, String schemaName,
185: String name);
186:
187: String getDateLiteral(java.sql.Date date);
188:
189: String getDateLiteral(java.sql.Time time);
190:
191: String getDateLiteral(java.sql.Timestamp timeStamp);
192:
193: String getDateLiteral(Date defaultDateValue);
194:
195: /**
196: * Escapes the table name in a database-dependent manner so reserved words can be used as a table name (i.e. "order").
197: * Currently only escapes MS-SQL because other DBMSs store table names case-sensitively when escaping is used which
198: * could confuse end-users. Pass null to schemaName to use the default schema
199: */
200: String escapeTableName(String schemaName, String tableName);
201:
202: /**
203: * Escapes a single column name in a database-dependent manner so reserved words can be used as a column
204: * name (i.e. "return").
205: *
206: * @param columnName column name
207: * @return escaped column name
208: */
209: String escapeColumnName(String columnName);
210:
211: /**
212: * Escapes a list of column names in a database-dependent manner so reserved words can be used as a column
213: * name (i.e. "return").
214: *
215: * @param columnNames list of column names
216: * @return escaped column name list
217: */
218: String escapeColumnNameList(String columnNames);
219:
220: // Set<UniqueConstraint> findUniqueConstraints(String schema) throws JDBCException;
221:
222: String convertRequestedSchemaToSchema(String requestedSchema)
223: throws JDBCException;
224:
225: String convertRequestedSchemaToCatalog(String requestedSchema)
226: throws JDBCException;
227:
228: boolean supportsSchemas();
229:
230: String generatePrimaryKeyName(String tableName);
231:
232: String escapeSequenceName(String schemaName, String sequenceName);
233:
234: String escapeViewName(String schemaName, String viewName);
235:
236: boolean isColumnAutoIncrement(String schemaName, String tableName,
237: String columnName) throws SQLException, JDBCException;
238:
239: ChangeSet.RunStatus getRunStatus(ChangeSet changeSet)
240: throws JDBCException, DatabaseHistoryException;
241:
242: RanChangeSet getRanChangeSet(ChangeSet changeSet)
243: throws JDBCException, DatabaseHistoryException;
244:
245: void markChangeSetAsRan(ChangeSet changeSet) throws JDBCException;
246:
247: void markChangeSetAsReRan(ChangeSet changeSet) throws JDBCException;
248:
249: List<RanChangeSet> getRanChangeSetList() throws JDBCException;
250:
251: Date getRanDate(ChangeSet changeSet) throws JDBCException,
252: DatabaseHistoryException;
253:
254: void removeRanStatus(ChangeSet changeSet) throws JDBCException;
255:
256: void commit() throws JDBCException;
257:
258: void rollback() throws JDBCException;
259:
260: SqlStatement getSelectChangeLogLockSQL() throws JDBCException;
261:
262: JdbcTemplate getJdbcTemplate();
263:
264: void setJdbcTemplate(JdbcTemplate template);
265:
266: String escapeStringForDatabase(String string);
267:
268: void close() throws JDBCException;
269: }
|