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: public class SybaseDatabase extends MSSQLDatabase {
010:
011: public SybaseDatabase() {
012: systemTablesAndViews.add("sysquerymetrics");
013: }
014:
015: public String getProductName() {
016: return "Sybase SQL Server";
017: }
018:
019: public String getTypeName() {
020: return "sybase";
021: }
022:
023: public void setConnection(Connection connection) {
024: super .setConnection(new SybaseConnectionDelegate(connection));
025: }
026:
027: public String getDefaultDriver(String url) {
028: if (url.startsWith("jdbc:sybase")) {
029: return "com.sybase.jdbc3.jdbc.SybDriver";
030: } else if (url.startsWith("jdbc:jtds:sybase")) {
031: return "net.sourceforge.jtds.jdbc.Driver";
032: }
033: return null;
034: }
035:
036: /**
037: * Sybase does not support DDL and meta data in transactions properly,
038: * as such we turn off the commit and turn on auto commit.
039: */
040: public boolean supportsDDLInTransaction() {
041: return false;
042: }
043:
044: protected SqlStatement getCreateChangeLogSQL() {
045: return new RawSqlStatement(
046: ("CREATE TABLE "
047: + escapeTableName(getDefaultSchemaName(),
048: getDatabaseChangeLogTableName())
049: + " (ID VARCHAR(150) NOT NULL, "
050: + "AUTHOR VARCHAR(150) NOT NULL, "
051: + "FILENAME VARCHAR(255) NOT NULL, "
052: + "DATEEXECUTED " + getDateTimeType()
053: + " NOT NULL, " + "MD5SUM VARCHAR(32) NULL, "
054: + "DESCRIPTION VARCHAR(255) NULL, "
055: + "COMMENTS VARCHAR(255) NULL, "
056: + "TAG VARCHAR(255) NULL, "
057: + "LIQUIBASE VARCHAR(10) NULL, " + "PRIMARY KEY(ID, AUTHOR, FILENAME))"));
058: }
059:
060: protected SqlStatement getCreateChangeLogLockSQL() {
061: return new RawSqlStatement(
062: ("CREATE TABLE "
063: + escapeTableName(getDefaultSchemaName(),
064: getDatabaseChangeLogLockTableName())
065: + " (ID INT NOT NULL PRIMARY KEY, LOCKED "
066: + getBooleanType() + " NOT NULL, LOCKGRANTED "
067: + getDateTimeType() + " NULL, LOCKEDBY VARCHAR(255) NULL)"));
068: }
069:
070: /**
071: * Drops all objects owned by the connected user.
072: *
073: * The Sybase functionality overrides this and does not remove the Foreign Keys.
074: *
075: * Unfortunately it appears to be a problem with the Drivers, see the JTDS driver page.
076: * http://sourceforge.net/tracker/index.php?func=detail&aid=1471425&group_id=33291&atid=407762
077: *
078: */
079: // public void dropDatabaseObjects(String schema) throws JDBCException {
080: // DatabaseConnection conn = getConnection();
081: // try {
082: // //dropForeignKeys(conn);
083: // dropViews(schema, conn);
084: // dropTables(schema, conn);
085: //
086: // if (this.supportsSequences()) {
087: // dropSequences(schema, conn);
088: // }
089: //
090: // changeLogTableExists = false;
091: // } finally {
092: // try {
093: // conn.commit();
094: // } catch (SQLException e) {
095: // ;
096: // }
097: // }
098: // }
099:
100: public boolean isCorrectDatabaseImplementation(Connection conn)
101: throws JDBCException {
102: String dbProductName = getDatabaseProductName(conn);
103: return "Adaptive Server Enterprise".equals(dbProductName)
104: || "sql server".equals(dbProductName);
105: }
106:
107: public boolean supportsTablespaces() {
108: return true;
109: }
110:
111: }
|