001: package liquibase.database;
002:
003: import liquibase.database.sql.RawSqlStatement;
004: import liquibase.database.sql.SqlStatement;
005: import liquibase.exception.JDBCException;
006:
007: import java.sql.Connection;
008:
009: /**
010: * Firebird database implementation.
011: * SQL Syntax ref: http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_60_sqlref
012: */
013: public class FirebirdDatabase extends AbstractDatabase {
014:
015: public boolean isCorrectDatabaseImplementation(Connection conn)
016: throws JDBCException {
017: return getDatabaseProductName(conn).startsWith("Firebird");
018: }
019:
020: public String getDefaultDriver(String url) {
021: if (url.startsWith("jdbc:firebirdsql")) {
022: return "org.firebirdsql.jdbc.FBDriver";
023: }
024: return null;
025: }
026:
027: public String getProductName() {
028: return "Firebird";
029: }
030:
031: public String getTypeName() {
032: return "firebird";
033: }
034:
035: public boolean supportsSequences() {
036: return true;
037: }
038:
039: public String getBooleanType() {
040: return "SMALLINT";
041: }
042:
043: public String getCurrencyType() {
044: return "DECIMAL(18, 4)";
045: }
046:
047: public String getUUIDType() {
048: return "CHAR(36)";
049: }
050:
051: public String getClobType() {
052: return "BLOB SUB_TYPE TEXT";
053: }
054:
055: public String getBlobType() {
056: return "BLOB";
057: }
058:
059: public String getDateTimeType() {
060: return "TIMESTAMP";
061: }
062:
063: public boolean supportsInitiallyDeferrableColumns() {
064: return false;
065: }
066:
067: public String getCurrentDateTimeFunction() {
068: return "CURRENT_TIMESTAMP";
069: }
070:
071: public boolean supportsTablespaces() {
072: return false;
073: }
074:
075: public SqlStatement createFindSequencesSQL(String schema)
076: throws JDBCException {
077: return new RawSqlStatement(
078: "SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS WHERE RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0");
079: }
080:
081: public SqlStatement getViewDefinitionSql(String schemaName,
082: String viewName) throws JDBCException {
083: String sql = "select rdb$view_source from rdb$relations where upper(rdb$relation_name)='"
084: + viewName + "'";
085: // if (schemaName != null) {
086: // sql += " and rdb$owner_name='" + schemaName.toUpperCase() + "'";
087: // }
088: // if (getDefaultCatalogName() != null) {
089: // sql += " and table_catalog='" + getDefaultCatalogName() + "'";
090: //
091: // }
092: return new RawSqlStatement(sql);
093: }
094:
095: public boolean supportsDDLInTransaction() {
096: return false;
097: }
098:
099: public String getTrueBooleanValue() {
100: return "1";
101: }
102:
103: public String getFalseBooleanValue() {
104: return "0";
105: }
106:
107: public boolean isSystemTable(String catalogName, String schemaName,
108: String tableName) {
109: return tableName.startsWith("RDB$")
110: || super .isSystemTable(catalogName, schemaName,
111: tableName);
112: }
113:
114: public boolean supportsAutoIncrement() {
115: return false;
116: }
117:
118: public boolean supportsSchemas() {
119: return false;
120: }
121:
122: public String convertRequestedSchemaToSchema(String requestedSchema)
123: throws JDBCException {
124: if (requestedSchema == null) {
125: return getDefaultDatabaseSchemaName();
126: } else {
127: return requestedSchema.toUpperCase();
128: }
129: }
130:
131: public String getColumnType(String columnType, Boolean autoIncrement) {
132: String type = super .getColumnType(columnType, autoIncrement);
133: if (type.startsWith("BLOB SUB_TYPE <0")) {
134: return getBlobType();
135: } else {
136: return type;
137: }
138: }
139: }
|