File | Project | Line |
---|
liquibase/snapshot/jvm/SQLiteDatabaseSnapshotGenerator.java | Liquibase Core | 53 |
liquibase/snapshot/jvm/SQLiteDatabaseSnapshotGenerator.java | Liquibase Core | 100 |
protected void readViews(DatabaseSnapshot snapshot, String schema, DatabaseMetaData databaseMetaData)
throws SQLException, DatabaseException {
Database database = snapshot.getDatabase();
updateListeners("Reading tables for " + database.toString() + " ...");
ResultSet rs = databaseMetaData.getTables(database.convertRequestedSchemaToCatalog(schema),
database.convertRequestedSchemaToSchema(schema), null, new String[] { "TABLE", "VIEW" });
try {
while (rs.next()) {
String type = rs.getString("TABLE_TYPE");
String name = rs.getString("TABLE_NAME");
String schemaName = rs.getString("TABLE_SCHEM");
String catalogName = rs.getString("TABLE_CAT");
String remarks = rs.getString("REMARKS");
if (database.isSystemTable(catalogName, schemaName, name) || database.isLiquibaseTable(name)
|| database.isSystemView(catalogName, schemaName, name)) {
continue;
}
if ("TABLE".equals(type)) {
Table table = new Table(name);
table.setRemarks(StringUtils.trimToNull(remarks));
table.setDatabase(database);
table.setSchema(schemaName);
snapshot.getTables().add(table);
} else if ("VIEW".equals(type)) {
View view = new View();
view.setName(name);
view.setSchema(schemaName);
try {
view.setDefinition(database.getViewDefinition(schema, name));
} catch (DatabaseException e) {
System.out.println("Error getting view with " + new GetViewDefinitionStatement(schema, name));
throw e;
}
snapshot.getViews().add(view);
}
}
} finally {
rs.close();
}
}
/**
* SQLite specific implementation
*/
@Override
protected void readForeignKeyInformation(DatabaseSnapshot snapshot, String schema, DatabaseMetaData databaseMetaData) |
File | Project | Line |
---|
org/liquibase/maven/plugins/LiquibaseMigrateSQL.java | Liquibase Maven Plugin | 43 |
org/liquibase/maven/plugins/LiquibaseUpdateSQL.java | Liquibase Maven Plugin | 31 |
@Override
protected boolean isPromptOnNonLocalDatabase() {
// Always run on an non-local database as we are not actually modifying
// the database
// when run on it.
return false;
}
@Override
protected void doUpdate(Liquibase liquibase) throws LiquibaseException {
if (changesToApply > 0) {
liquibase.update(changesToApply, contexts, outputWriter);
} else {
liquibase.update(contexts, outputWriter);
}
}
@Override
protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
Liquibase liquibase = super.createLiquibase(fo, db);
// Setup the output file writer
try {
if (!migrationSqlOutputFile.exists()) {
// Ensure the parent directories exist
migrationSqlOutputFile.getParentFile().mkdirs();
// Create the actual file
if (!migrationSqlOutputFile.createNewFile()) {
throw new MojoExecutionException("Cannot create the migration SQL file; "
+ migrationSqlOutputFile.getAbsolutePath());
}
}
outputWriter = new FileWriter(migrationSqlOutputFile);
} catch (IOException e) {
getLog().error(e);
throw new MojoExecutionException("Failed to create SQL output writer", e);
}
getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
return liquibase;
}
@Override
protected void printSettings(String indent) {
super.printSettings(indent);
getLog().info(indent + "migrationSQLOutputFile: " + migrationSqlOutputFile);
}
@Override
protected void cleanup(Database db) {
super.cleanup(db);
if (outputWriter != null) {
try {
outputWriter.close();
} catch (IOException e) {
getLog().error(e);
}
}
}
} |
File | Project | Line |
---|
liquibase/change/core/LoadUpdateDataChange.java | Liquibase Core | 70 |
liquibase/sqlgenerator/core/InsertOrUpdateGenerator.java | Liquibase Core | 51 |
insertOrUpdateStatement.getTableName(), thisPkColumn)).append(" = ");
Object newValue = insertOrUpdateStatement.getColumnValues().get(thisPkColumn);
if (newValue == null || newValue.toString().equals("NULL")) {
where.append("NULL");
} else if (newValue instanceof String && database.shouldQuoteValue(((String) newValue))) {
where.append("'").append(database.escapeStringForDatabase((String) newValue)).append("'");
} else if (newValue instanceof Date) {
where.append(database.getDateLiteral(((Date) newValue)));
} else if (newValue instanceof Boolean) {
if (((Boolean) newValue)) {
where.append(TypeConverterFactory.getInstance().findTypeConverter(database).getBooleanType()
.getTrueBooleanValue());
} else {
where.append(TypeConverterFactory.getInstance().findTypeConverter(database).getBooleanType()
.getFalseBooleanValue());
}
} else {
where.append(newValue);
}
where.append(" AND ");
}
where.delete(where.lastIndexOf(" AND "), where.lastIndexOf(" AND ") + " AND ".length());
return where.toString();
} |
File | Project | Line |
---|
liquibase/snapshot/jvm/JdbcDatabaseSnapshotGenerator.java | Liquibase Core | 810 |
liquibase/snapshot/jvm/OracleDatabaseSnapshotGenerator.java | Liquibase Core | 405 |
for (Index index : snapshot.getIndexes()) {
for (PrimaryKey pk : snapshot.getPrimaryKeys()) {
if (index.getTable().getName().equalsIgnoreCase(pk.getTable().getName())
&& index.getColumnNames().equals(pk.getColumnNames())) {
index.addAssociatedWith(Index.MARK_PRIMARY_KEY);
}
}
for (ForeignKey fk : snapshot.getForeignKeys()) {
if (index.getTable().getName().equalsIgnoreCase(fk.getForeignKeyTable().getName())
&& index.getColumnNames().equals(fk.getForeignKeyColumns())) {
index.addAssociatedWith(Index.MARK_FOREIGN_KEY);
}
}
for (UniqueConstraint uc : snapshot.getUniqueConstraints()) {
if (index.getTable().getName().equalsIgnoreCase(uc.getTable().getName())
&& index.getColumnNames().equals(uc.getColumnNames())) {
index.addAssociatedWith(Index.MARK_UNIQUE_CONSTRAINT);
}
}
} |
File | Project | Line |
---|
org/liquibase/maven/plugins/LiquibaseMigrateSQL.java | Liquibase Maven Plugin | 57 |
org/liquibase/maven/plugins/LiquibaseRollbackSQL.java | Liquibase Maven Plugin | 44 |
}
@Override
protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
Liquibase liquibase = super.createLiquibase(fo, db);
// Setup the output file writer
try {
if (!migrationSqlOutputFile.exists()) {
// Ensure the parent directories exist
migrationSqlOutputFile.getParentFile().mkdirs();
// Create the actual file
if (!migrationSqlOutputFile.createNewFile()) {
throw new MojoExecutionException("Cannot create the migration SQL file; "
+ migrationSqlOutputFile.getAbsolutePath());
}
}
outputWriter = new FileWriter(migrationSqlOutputFile);
} catch (IOException e) {
getLog().error(e);
throw new MojoExecutionException("Failed to create SQL output writer", e);
}
getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
return liquibase;
}
@Override
protected void printSettings(String indent) {
super.printSettings(indent);
getLog().info(indent + "migrationSQLOutputFile: " + migrationSqlOutputFile);
}
@Override
protected void cleanup(Database db) {
super.cleanup(db);
if (outputWriter != null) {
try {
outputWriter.close();
} catch (IOException e) {
getLog().error(e);
}
}
} |
File | Project | Line |
---|
liquibase/database/core/H2Database.java | Liquibase Core | 129 |
liquibase/database/core/HsqlDatabase.java | Liquibase Core | 66 |
}
@Override
public String getConcatSql(String... values) {
if (values == null) {
return null;
}
return getConcatSql(Arrays.asList(values));
}
/**
* Recursive way of building CONCAT instruction
*
* @param values
* a non null List of String
* @return a String containing the CONCAT instruction with all elements, or only a value if there is only one
* element in the list
*/
private String getConcatSql(List<String> values) {
if (values.size() == 1) {
return values.get(0);
} else {
return START_CONCAT + values.get(0) + SEP_CONCAT + getConcatSql(values.subList(1, values.size()))
+ END_CONCAT;
}
}
@Override
public String getDateLiteral(String isoDate) {
String returnString = isoDate;
try {
if (isDateTime(isoDate)) {
ISODateFormat isoTimestampFormat = new ISODateFormat();
DateFormat dbTimestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
returnString = dbTimestampFormat.format(isoTimestampFormat.parse(isoDate));
}
} catch (ParseException e) {
throw new RuntimeException("Unexpected date format: " + isoDate, e);
}
return "'" + returnString + "'";
}
@Override
public Date parseDate(String dateAsString) throws DateParseException { |
File | Project | Line |
---|
liquibase/database/typeconversion/core/MSSQLTypeConverter.java | Liquibase Core | 31 |
liquibase/database/typeconversion/core/SybaseTypeConverter.java | Liquibase Core | 25 |
}
@Override
public Object convertDatabaseValueToObject(Object defaultValue, int dataType, int columnSize, int decimalDigits,
Database database) throws ParseException {
if (defaultValue == null) {
return null;
}
if (defaultValue instanceof String) {
if (((String) defaultValue).startsWith("('")) {
defaultValue = ((String) defaultValue).replaceFirst("^\\('", "").replaceFirst("'\\)$", "");
} else if (((String) defaultValue).startsWith("((")) {
defaultValue = ((String) defaultValue).replaceFirst("^\\(\\(", "").replaceFirst("\\)\\)$", "");
}
}
defaultValue = super.convertDatabaseValueToObject(defaultValue, dataType, columnSize, decimalDigits, database);
return defaultValue;
}
@Override
public DataType getDataType(String columnTypeString, Boolean autoIncrement) { |
File | Project | Line |
---|
liquibase/sqlgenerator/core/AddDefaultValueGeneratorOracle.java | Liquibase Core | 22 |
liquibase/sqlgenerator/core/AddDefaultValueGeneratorSybaseASA.java | Liquibase Core | 22 |
}
@Override
public Sql[] generateSql(AddDefaultValueStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
Object defaultValue = statement.getDefaultValue();
return new Sql[] { new UnparsedSql("ALTER TABLE "
+ database.escapeTableName(statement.getSchemaName(), statement.getTableName())
+ " MODIFY "
+ database.escapeColumnName(statement.getSchemaName(), statement.getTableName(),
statement.getColumnName())
+ " DEFAULT "
+ TypeConverterFactory.getInstance().findTypeConverter(database).getDataType(defaultValue)
.convertObjectToString(defaultValue, database), new Column().setTable(
new Table(statement.getTableName()).setSchema(statement.getSchemaName())).setName(
statement.getColumnName())) };
}
} |
File | Project | Line |
---|
org/liquibase/maven/plugins/LiquibaseChangeLogSyncSQLMojo.java | Liquibase Maven Plugin | 46 |
org/liquibase/maven/plugins/LiquibaseRollbackSQL.java | Liquibase Maven Plugin | 39 |
@Override
protected boolean isPromptOnNonLocalDatabase() {
// Always run on an non-local database as we are not actually modifying
// the database when run on it.
return false;
}
@Override
protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
Liquibase liquibase = super.createLiquibase(fo, db);
// Setup the output file writer
try {
if (!migrationSqlOutputFile.exists()) {
// Ensure the parent directories exist
migrationSqlOutputFile.getParentFile().mkdirs();
// Create the actual file
if (!migrationSqlOutputFile.createNewFile()) {
throw new MojoExecutionException("Cannot create the migration SQL file; "
+ migrationSqlOutputFile.getAbsolutePath());
}
}
outputWriter = new FileWriter(migrationSqlOutputFile);
} catch (IOException e) {
getLog().error(e);
throw new MojoExecutionException("Failed to create SQL output writer", e);
}
getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
return liquibase;
}
@Override
protected void printSettings(String indent) { |
File | Project | Line |
---|
liquibase/change/core/InsertDataChange.java | Liquibase Core | 25 |
liquibase/change/core/UpdateDataChange.java | Liquibase Core | 26 |
super("update", "Update Data", ChangeMetaData.PRIORITY_DEFAULT);
columns = new ArrayList<ColumnConfig>();
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = StringUtils.trimToNull(schemaName);
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public List<ColumnConfig> getColumns() {
return columns;
}
public void setColumns(List<ColumnConfig> columns) {
this.columns = columns;
}
public void addColumn(ColumnConfig column) {
columns.add(column);
}
public void removeColumn(ColumnConfig column) {
columns.remove(column);
}
public String getWhereClause() { |
File | Project | Line |
---|
org/liquibase/maven/plugins/LiquibaseChangeLogSyncSQLMojo.java | Liquibase Maven Plugin | 52 |
org/liquibase/maven/plugins/LiquibaseUpdateSQL.java | Liquibase Maven Plugin | 46 |
}
@Override
protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
Liquibase liquibase = super.createLiquibase(fo, db);
// Setup the output file writer
try {
if (!migrationSqlOutputFile.exists()) {
// Ensure the parent directories exist
migrationSqlOutputFile.getParentFile().mkdirs();
// Create the actual file
if (!migrationSqlOutputFile.createNewFile()) {
throw new MojoExecutionException("Cannot create the migration SQL file; "
+ migrationSqlOutputFile.getAbsolutePath());
}
}
outputWriter = new FileWriter(migrationSqlOutputFile);
} catch (IOException e) {
getLog().error(e);
throw new MojoExecutionException("Failed to create SQL output writer", e);
}
getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
return liquibase;
}
@Override
protected void printSettings(String indent) { |
File | Project | Line |
---|
liquibase/database/core/MSSQLDatabase.java | Liquibase Core | 72 |
liquibase/database/core/SybaseDatabase.java | Liquibase Core | 101 |
} else if (url.startsWith("jdbc:jtds:sybase")) {
return "net.sourceforge.jtds.jdbc.Driver";
}
return null;
}
public String getCurrentDateTimeFunction() {
if (currentDateTimeFunction != null) {
return currentDateTimeFunction;
}
return "GETDATE()";
}
@Override
public String getAutoIncrementClause() {
return "IDENTITY";
}
@Override
protected String getDefaultDatabaseSchemaName() throws DatabaseException {
return null;
}
@Override
public String getDefaultCatalogName() throws DatabaseException {
return getConnection().getCatalog();
}
@Override
public String getConcatSql(String... values) {
StringBuffer returnString = new StringBuffer();
for (String value : values) {
returnString.append(value).append(" + ");
}
return returnString.toString().replaceFirst(" \\+ $", "");
} |
File | Project | Line |
---|
liquibase/database/core/MSSQLDatabase.java | Liquibase Core | 21 |
liquibase/database/core/SybaseDatabase.java | Liquibase Core | 30 |
public SybaseDatabase() {
systemTablesAndViews.add("syscolumns");
systemTablesAndViews.add("syscomments");
systemTablesAndViews.add("sysdepends");
systemTablesAndViews.add("sysfilegroups");
systemTablesAndViews.add("sysfiles");
systemTablesAndViews.add("sysfiles1");
systemTablesAndViews.add("sysforeignkeys");
systemTablesAndViews.add("sysfulltextcatalogs");
systemTablesAndViews.add("sysfulltextnotify");
systemTablesAndViews.add("sysindexes");
systemTablesAndViews.add("sysindexkeys");
systemTablesAndViews.add("sysmembers");
systemTablesAndViews.add("sysobjects");
systemTablesAndViews.add("syspermissions");
systemTablesAndViews.add("sysproperties");
systemTablesAndViews.add("sysprotects");
systemTablesAndViews.add("sysreferences");
systemTablesAndViews.add("systypes");
systemTablesAndViews.add("sysusers");
systemTablesAndViews.add("sysquerymetrics"); |
File | Project | Line |
---|
liquibase/change/core/DropDefaultValueChange.java | Liquibase Core | 29 |
liquibase/change/core/DropNotNullConstraintChange.java | Liquibase Core | 29 |
super("dropNotNullConstraint", "Drop Not-Null Constraint", ChangeMetaData.PRIORITY_DEFAULT);
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = StringUtils.trimToNull(schemaName);
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public String getColumnDataType() {
return columnDataType;
}
public void setColumnDataType(String columnDataType) {
this.columnDataType = columnDataType;
}
public SqlStatement[] generateStatements(Database database) {
// todo if (database instanceof SQLiteDatabase) {
// // return special statements for SQLite databases
// return generateStatementsForSQLiteDatabase(database);
// }
return new SqlStatement[] { new SetNullableStatement(getSchemaName() == null ? database.getDefaultSchemaName() |
File | Project | Line |
---|
liquibase/serializer/core/xml/XMLChangeLogSerializer.java | Liquibase Core | 133 |
liquibase/serializer/core/xml/XMLChangeLogSerializer.java | Liquibase Core | 170 |
Class classToExtractFieldsFrom = change.getClass();
while (!classToExtractFieldsFrom.equals(Object.class)) {
allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields()));
classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass();
}
for (Field field : allFields) {
field.setAccessible(true);
ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class);
if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) {
continue;
}
if (field.getName().equals("serialVersionUID")) {
continue;
}
if (field.getName().equals("$VRc")) { // from emma
continue;
} |
File | Project | Line |
---|
liquibase/change/core/AddAutoIncrementChange.java | Liquibase Core | 27 |
liquibase/change/core/DropNotNullConstraintChange.java | Liquibase Core | 29 |
super("dropDefaultValue", "Drop Default Value", ChangeMetaData.PRIORITY_DEFAULT);
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = StringUtils.trimToNull(schemaName);
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public String getColumnDataType() {
return columnDataType;
}
public void setColumnDataType(String columnDataType) {
this.columnDataType = columnDataType;
}
public SqlStatement[] generateStatements(Database database) { |
File | Project | Line |
---|
liquibase/integration/ant/DatabaseUpdateTask.java | Liquibase Core | 12 |
liquibase/integration/ant/DatabaseUpdateTestingRollbackTask.java | Liquibase Core | 10 |
public class DatabaseUpdateTestingRollbackTask extends BaseLiquibaseTask {
private boolean dropFirst = false;
public boolean isDropFirst() {
return dropFirst;
}
public void setDropFirst(boolean dropFirst) {
this.dropFirst = dropFirst;
}
@Override
public void execute() throws BuildException {
if (!shouldRun()) {
return;
}
super.execute();
Liquibase liquibase = null;
try {
liquibase = createLiquibase();
if (isPromptOnNonLocalDatabase() && !liquibase.isSafeToRunMigration()
&& UIFactory.getInstance().getFacade().promptForNonLocalDatabase(liquibase.getDatabase())) {
throw new BuildException("Chose not to run against non-production database");
} |
File | Project | Line |
---|
liquibase/database/structure/type/DateType.java | Liquibase Core | 12 |
liquibase/database/structure/type/TimeType.java | Liquibase Core | 12 |
public TimeType(String dataTypeName) {
super(dataTypeName, 0, 0);
}
@Override
public String convertObjectToString(Object value, Database database) {
if (value == null) {
return null;
} else if (value.toString().equalsIgnoreCase("null")) {
return "null";
} else if (value instanceof DatabaseFunction) {
return ((DatabaseFunction) value).getValue();
} else if (value.toString().equals("CURRENT_TIMESTAMP()")) {
return database.getCurrentDateTimeFunction();
} else if (value instanceof java.sql.Time) { |
File | Project | Line |
---|
liquibase/snapshot/jvm/JdbcDatabaseSnapshotGenerator.java | Liquibase Core | 834 |
liquibase/snapshot/jvm/SQLiteDatabaseSnapshotGenerator.java | Liquibase Core | 161 |
protected void readPrimaryKeys(DatabaseSnapshot snapshot, String schema, DatabaseMetaData databaseMetaData)
throws DatabaseException, SQLException {
Database database = snapshot.getDatabase();
updateListeners("Reading primary keys for " + database.toString() + " ...");
// we can't add directly to the this.primaryKeys hashSet because adding columns to an exising PK changes the
// hashCode and .contains() fails
List<PrimaryKey> foundPKs = new ArrayList<PrimaryKey>();
for (Table table : snapshot.getTables()) {
ResultSet rs = databaseMetaData.getPrimaryKeys(database.convertRequestedSchemaToCatalog(schema),
database.convertRequestedSchemaToSchema(schema), table.getName());
try {
while (rs.next()) {
String tableName = rs.getString("TABLE_NAME"); |
File | Project | Line |
---|
liquibase/change/core/AddAutoIncrementChange.java | Liquibase Core | 27 |
liquibase/change/core/AddDefaultValueChange.java | Liquibase Core | 33 |
super("addDefaultValue", "Add Default Value", ChangeMetaData.PRIORITY_DEFAULT);
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = StringUtils.trimToNull(schemaName);
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public String getColumnDataType() {
return columnDataType;
}
public void setColumnDataType(String columnDataType) {
this.columnDataType = columnDataType;
}
public String getDefaultValue() { |
File | Project | Line |
---|
liquibase/sqlgenerator/core/DeleteGenerator.java | Liquibase Core | 49 |
liquibase/sqlgenerator/core/InsertOrUpdateGeneratorMySQL.java | Liquibase Core | 77 |
sqlString = "'" + database.escapeStringForDatabase(newValue.toString()) + "'";
} else if (newValue instanceof Date) {
sqlString = database.getDateLiteral(((Date) newValue));
} else if (newValue instanceof Boolean) {
if (((Boolean) newValue)) {
sqlString = TypeConverterFactory.getInstance().findTypeConverter(database).getBooleanType()
.getTrueBooleanValue();
} else {
sqlString = TypeConverterFactory.getInstance().findTypeConverter(database).getBooleanType()
.getFalseBooleanValue();
}
} else {
sqlString = newValue.toString();
}
return sqlString;
}
} |