本文整理汇总了Java中liquibase.sql.UnparsedSql类的典型用法代码示例。如果您正苦于以下问题:Java UnparsedSql类的具体用法?Java UnparsedSql怎么用?Java UnparsedSql使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnparsedSql类属于liquibase.sql包,在下文中一共展示了UnparsedSql类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(GetViewDefinitionStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
try {
String sql = "select view_definition from information_schema.views where upper(table_name)='" + statement.getViewName().toUpperCase() + "'";
if (database.convertRequestedSchemaToCatalog(statement.getSchemaName()) != null) {
sql += " and table_schema='" + database.convertRequestedSchemaToSchema(statement.getSchemaName()) + "'";
} else if (database.convertRequestedSchemaToCatalog(statement.getSchemaName()) != null) {
sql += " and table_catalog='" + database.convertRequestedSchemaToCatalog(statement.getSchemaName()) + "'";
}
return new Sql[] {
new UnparsedSql(sql)
};
} catch (DatabaseException e) {
throw new UnexpectedLiquibaseException(e);
}
}
示例2: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(CreateViewStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String createClause;
if (database instanceof FirebirdDatabase) {
if (statement.isReplaceIfExists()) {
createClause = "RECREATE VIEW";
} else {
createClause = "RECREATE VIEW";
}
} else if (database instanceof SybaseASADatabase && statement.getSelectQuery().toLowerCase().startsWith("create view")) {
// Sybase ASA saves view definitions with header.
return new Sql[]{
new UnparsedSql(statement.getSelectQuery())
};
} else {
createClause = "CREATE " + (statement.isReplaceIfExists() ? "OR REPLACE " : "") + "VIEW";
}
return new Sql[]{
new UnparsedSql(createClause + " " + database.escapeViewName(statement.getSchemaName(), statement.getViewName()) + " AS " + statement.getSelectQuery())
};
}
示例3: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT ");
sb.append("RC.TABLE_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME).append(", ");
sb.append("KCU.COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME).append(", ");
sb.append("RC.REFERENCED_TABLE_NAME ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME).append(", ");
sb.append("KCU.REFERENCED_COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME).append(", ");
sb.append("RC.CONSTRAINT_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME).append(" ");
sb.append("FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC,");
sb.append(" INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU ");
sb.append("WHERE RC.TABLE_NAME = KCU.TABLE_NAME ");
sb.append("AND RC.CONSTRAINT_SCHEMA = KCU.CONSTRAINT_SCHEMA ");
sb.append("AND RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME ");
sb.append("AND RC.TABLE_NAME = '").append(statement.getBaseTableName()).append("' ");
try {
sb.append("AND RC.CONSTRAINT_SCHEMA = '").append(database.convertRequestedSchemaToSchema(null)).append("'");
} catch (DatabaseException e) {
throw new UnexpectedLiquibaseException(e);
}
return new Sql[]{
new UnparsedSql(sb.toString())
};
}
示例4: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT ");
sb.append("TABNAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME).append(", ");
sb.append("PK_COLNAMES as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME).append(", ");
sb.append("REFTABNAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME).append(", ");
sb.append("FK_COLNAMES as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME).append(",");
sb.append("CONSTNAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME).append(" ");
sb.append("FROM SYSCAT.REFERENCES ");
sb.append("WHERE TABNAME='").append(statement.getBaseTableName()).append("'");
return new Sql[]{
new UnparsedSql(sb.toString())
};
}
示例5: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
@Override
public Sql[] generateSql(AddUniqueConstraintStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
final String sqlNoContraintNameTemplate = "ALTER TABLE %s ADD CONSTRAINT UNIQUE (%s)";
final String sqlTemplate = "ALTER TABLE %s ADD CONSTRAINT UNIQUE (%s) CONSTRAint %s";
if (statement.getConstraintName() == null) {
return new Sql[] {
new UnparsedSql(String.format(sqlNoContraintNameTemplate
, database.escapeTableName(statement.getSchemaName(), statement.getTableName())
, database.escapeColumnNameList(statement.getColumnNames())
))
};
} else {
return new Sql[] {
new UnparsedSql(String.format(sqlTemplate
, database.escapeTableName(statement.getSchemaName(), statement.getTableName())
, database.escapeColumnNameList(statement.getColumnNames())
, database.escapeConstraintName(statement.getConstraintName())
))
};
}
}
示例6: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(SelectFromDatabaseChangeLogLockStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String liquibaseSchema;
liquibaseSchema = database.getLiquibaseSchemaName();
String[] columns = statement.getColumnsToSelect();
int numberOfColumns = columns.length;
String[] escapedColumns = new String[numberOfColumns];
for (int i=0; i<numberOfColumns; i++) {
escapedColumns[i] = database.escapeColumnName(liquibaseSchema, database.getDatabaseChangeLogLockTableName(), columns[i]);
}
String sql = "SELECT " + StringUtils.join(escapedColumns, ",") + " FROM " +
database.escapeTableName(liquibaseSchema, database.getDatabaseChangeLogLockTableName()) +
" WHERE " + database.escapeColumnName(liquibaseSchema, database.getDatabaseChangeLogLockTableName(), "ID") + "=1";
if (database instanceof OracleDatabase) {
sql += " FOR UPDATE";
}
return new Sql[] {
new UnparsedSql(sql)
};
}
示例7: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(AddPrimaryKeyStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String sql;
if (statement.getConstraintName() == null || database instanceof MySQLDatabase || database instanceof SybaseASADatabase) {
sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " ADD PRIMARY KEY (" + database.escapeColumnNameList(statement.getColumnNames()) + ")";
} else {
sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " ADD CONSTRAINT " + database.escapeConstraintName(statement.getConstraintName()) + " PRIMARY KEY (" + database.escapeColumnNameList(statement.getColumnNames()) + ")";
}
if (StringUtils.trimToNull(statement.getTablespace()) != null && database.supportsTablespaces()) {
if (database instanceof MSSQLDatabase) {
sql += " ON "+statement.getTablespace();
} else if (database instanceof DB2Database || database instanceof SybaseASADatabase) {
; //not supported
} else {
sql += " USING INDEX TABLESPACE "+statement.getTablespace();
}
}
return new Sql[] {
new UnparsedSql(sql)
};
}
示例8: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
@Override
public Sql[] generateSql(
AddAutoIncrementStatement statement,
Database database,
SqlGeneratorChain sqlGeneratorChain) {
return new Sql[]{
new UnparsedSql(
"ALTER TABLE "
+ database.escapeTableName(statement.getSchemaName(), statement.getTableName())
+ " ALTER COLUMN "
+ database.escapeColumnName(
statement.getSchemaName(),
statement.getTableName(),
statement.getColumnName())
+ " SET "
+ database.getAutoIncrementClause(
statement.getStartWith(), statement.getIncrementBy()),
new Column()
.setTable(
new Table(statement.getTableName()).setSchema(statement.getSchemaName()))
.setName(statement.getColumnName()))
};
}
示例9: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(CopyRowsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
StringBuffer sql = new StringBuffer();
if (database instanceof SQLiteDatabase) {
sql.append("INSERT INTO `").append(statement.getTargetTable()).append("` SELECT ");
for (int i = 0; i < statement.getCopyColumns().size(); i++) {
ColumnConfig column = statement.getCopyColumns().get(i);
if (i > 0) {
sql.append(",");
}
sql.append("`").append(column.getName()).append("`");
}
sql.append(" FROM `").append(statement.getSourceTable()).append("`");
}
return new Sql[]{
new UnparsedSql(sql.toString())
};
}
示例10: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(CreateDatabaseChangeLogTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
return new Sql[] {
new UnparsedSql("CREATE TABLE " + database.escapeTableName(database.getDefaultSchemaName(), database.getDatabaseChangeLogTableName()) + " (ID VARCHAR(150) NOT NULL, " +
"AUTHOR VARCHAR(150) NOT NULL, " +
"FILENAME VARCHAR(255) NOT NULL, " +
"DATEEXECUTED " + TypeConverterFactory.getInstance().findTypeConverter(database).getDateTimeType() + " NOT NULL, " +
"ORDEREXECUTED INT NOT NULL, " +
"EXECTYPE VARCHAR(10) NOT NULL, " +
"MD5SUM VARCHAR(35) NULL, " +
"DESCRIPTION VARCHAR(255) NULL, " +
"COMMENTS VARCHAR(255) NULL, " +
"TAG VARCHAR(255) NULL, " +
"LIQUIBASE VARCHAR(20) NULL, " +
"PRIMARY KEY(ID, AUTHOR, FILENAME))")
}; //To change body of implemented methods use File | Settings | File Templates.
}
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:17,代码来源:CreateDatabaseChangeLogTableGeneratorSybase.java
示例11: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(DropTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
StringBuffer buffer = new StringBuffer();
buffer.append("DROP TABLE ").append(database.escapeTableName(statement.getSchemaName(), statement.getTableName()));
if (statement.isCascadeConstraints()) {
if (!database.supportsDropTableCascadeConstraints()) {
LogFactory.getLogger().warning("Database does not support drop with cascade");
} else if (database instanceof OracleDatabase) {
buffer.append(" CASCADE CONSTRAINTS");
} else {
buffer.append(" CASCADE");
}
}
return new Sql[]{
new UnparsedSql(buffer.toString())
};
}
示例12: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT ");
sb.append("FK.TABLE_NAME as \"").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME).append("\", ");
sb.append("CU.COLUMN_NAME as \"").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME).append("\", ");
sb.append("PK.TABLE_NAME as \"").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME).append("\", ");
sb.append("PT.COLUMN_NAME as \"").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME).append("\", ");
sb.append("C.CONSTRAINT_NAME as \"").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME).append("\" ");
sb.append("FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C ");
sb.append("INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME ");
sb.append("INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME ");
sb.append("INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME ");
sb.append("INNER JOIN ( ");
sb.append(" SELECT i1.TABLE_NAME, i2.COLUMN_NAME ");
sb.append(" FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1 ");
sb.append(" INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME ");
sb.append(" WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY' ");
sb.append(") PT ON PT.TABLE_NAME = PK.TABLE_NAME ");
sb.append("WHERE lower(FK.TABLE_NAME)='").append(statement.getBaseTableName().toLowerCase()).append("'");
return new Sql[] {
new UnparsedSql(sb.toString())
};
}
示例13: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(DropIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
List<String> associatedWith = StringUtils.splitAndTrim(statement.getAssociatedWith(), ",");
if (associatedWith != null) {
if (associatedWith.contains(Index.MARK_PRIMARY_KEY)|| associatedWith.contains(Index.MARK_UNIQUE_CONSTRAINT)) {
return new Sql[0];
} else if (associatedWith.contains(Index.MARK_FOREIGN_KEY) ) {
if (!(database instanceof OracleDatabase || database instanceof MSSQLDatabase)) {
return new Sql[0];
}
}
}
String schemaName = statement.getTableSchemaName();
if (database instanceof MySQLDatabase) {
return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(null, statement.getIndexName()) + " ON " + database.escapeTableName(schemaName, statement.getTableName())) };
} else if (database instanceof MSSQLDatabase) {
return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeTableName(schemaName, statement.getTableName()) + "." + database.escapeIndexName(null, statement.getIndexName())) };
} else if (database instanceof PostgresDatabase) {
return new Sql[]{new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName()))};
}
return new Sql[] {new UnparsedSql("DROP INDEX " + database.escapeIndexName(schemaName, statement.getIndexName())) };
}
示例14: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(UpdateStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
StringBuffer sql = new StringBuffer("UPDATE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " SET");
for (String column : statement.getNewColumnValues().keySet()) {
sql.append(" ").append(database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), column)).append(" = ");
sql.append(convertToString(statement.getNewColumnValues().get(column), database));
sql.append(",");
}
sql.deleteCharAt(sql.lastIndexOf(","));
if (statement.getWhereClause() != null) {
String fixedWhereClause = "WHERE " + statement.getWhereClause().trim();
for (Object param : statement.getWhereParameters()) {
fixedWhereClause = fixedWhereClause.replaceFirst("\\?", convertToString(param, database));
}
sql.append(" ").append(fixedWhereClause);
}
return new Sql[]{
new UnparsedSql(sql.toString())
};
}
示例15: generateSql
import liquibase.sql.UnparsedSql; //导入依赖的package包/类
public Sql[] generateSql(RenameColumnStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String sql;
if (database instanceof MSSQLDatabase) {
// do no escape the new column name. Otherwise it produce "exec sp_rename '[dbo].[person].[usernae]', '[username]'"
sql = "exec sp_rename '" + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + "." + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getOldColumnName()) + "', '" + statement.getNewColumnName() + "'";
} else if (database instanceof MySQLDatabase) {
sql ="ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " CHANGE " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getOldColumnName()) + " " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getNewColumnName()) + " " + statement.getColumnDataType();
} else if (database instanceof HsqlDatabase || database instanceof H2Database) {
sql ="ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " ALTER COLUMN " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getOldColumnName()) + " RENAME TO " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getNewColumnName());
} else if (database instanceof FirebirdDatabase) {
sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " ALTER COLUMN " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getOldColumnName()) + " TO " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getNewColumnName());
} else if ((database instanceof MaxDBDatabase)
// supported in Derby from version 10.3.1.4 (see "http://issues.apache.org/jira/browse/DERBY-1490")
|| (database instanceof DerbyDatabase)
|| (database instanceof InformixDatabase)) {
sql = "RENAME COLUMN " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + "." + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getOldColumnName()) + " TO " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getNewColumnName());
} else if (database instanceof SybaseASADatabase) {
sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " RENAME " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getOldColumnName()) + " TO " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getNewColumnName());
} else {
sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + " RENAME COLUMN " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getOldColumnName()) + " TO " + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), statement.getNewColumnName());
}
return new Sql[] {
new UnparsedSql(sql)
};
}