Skip to content

Commit

Permalink
Merge branch '2_0_x' of github.com:liquibase/liquibase into 2_0_x
Browse files Browse the repository at this point in the history
  • Loading branch information
nvoxland committed Apr 12, 2012
2 parents afc4d78 + 330f80b commit 28883bc
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 11 deletions.
14 changes: 14 additions & 0 deletions liquibase-core/pom.xml
Expand Up @@ -174,6 +174,20 @@
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
4 changes: 2 additions & 2 deletions liquibase-core/src/main/java/liquibase/diff/DiffResult.java
Expand Up @@ -1006,7 +1006,7 @@ private void addInsertDataChanges(List<ChangeSet> changeSets, String dataDir)
columnNames.add(column.getName());
}

// if dataDir is not null, print out a csv file and use loadData
// if dataOutputDirectory is not null, print out a csv file and use loadData
// tag
if (dataDir != null) {
String fileName = table.getName().toLowerCase() + ".csv";
Expand Down Expand Up @@ -1079,7 +1079,7 @@ private void addInsertDataChanges(List<ChangeSet> changeSets, String dataDir)
}

changes.add(change);
} else { // if dataDir is null, build and use insert tags
} else { // if dataOutputDirectory is null, build and use insert tags
for (Map row : rs) {
InsertDataChange change = new InsertDataChange();
change.setSchemaName(schema);
Expand Down
Expand Up @@ -70,7 +70,7 @@ public class Main {
protected String diffTypes;
protected String changeSetAuthor;
protected String changeSetContext;
protected String dataDir;
protected String dataOutputDirectory;

protected String referenceDriver;
protected String referenceUrl;
Expand Down Expand Up @@ -716,7 +716,7 @@ protected void doMigration() throws Exception {
CommandLineUtils.doDiffToChangeLog(changeLogFile, createReferenceDatabaseFromCommandParams(commandParams), database);
return;
} else if ("generateChangeLog".equalsIgnoreCase(command)) {
CommandLineUtils.doGenerateChangeLog(changeLogFile, database, defaultSchemaName, StringUtils.trimToNull(diffTypes), StringUtils.trimToNull(changeSetAuthor), StringUtils.trimToNull(changeSetContext), StringUtils.trimToNull(dataDir));
CommandLineUtils.doGenerateChangeLog(changeLogFile, database, defaultSchemaName, StringUtils.trimToNull(diffTypes), StringUtils.trimToNull(changeSetAuthor), StringUtils.trimToNull(changeSetContext), StringUtils.trimToNull(dataOutputDirectory));
return;
}

Expand Down Expand Up @@ -877,7 +877,7 @@ private Database createReferenceDatabaseFromCommandParams(Set<String> commandPar
} else if ("referenceDefaultSchemaName".equalsIgnoreCase(attributeName)) {
defaultSchemaName = value;
} else if ("dataOutputDirectory".equalsIgnoreCase(attributeName)) {
dataDir = value;
dataOutputDirectory = value;
}
}

Expand Down
Expand Up @@ -3,12 +3,16 @@
import liquibase.logging.LogLevel;
import liquibase.util.StringUtils;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.text.DateFormat;
import java.util.Date;

public class DefaultLogger extends AbstractLogger {

private String name = "liquibase";
private PrintStream err = System.err;

public DefaultLogger() {
String passedLevel = System.getProperty("liquibase.defaultlogger.level");
Expand All @@ -29,6 +33,19 @@ public void setName(String name) {

public void setLogLevel(String logLevel, String logFile) {
setLogLevel(logLevel);
if (logFile != null) {
File log = new File(logFile);
try {
if (!log.exists()) {
if (!log.createNewFile()) {
throw new RuntimeException("Could not create logFile "+log.getAbsolutePath());
}
}
err = new PrintStream(log);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

public void severe(String message) {
Expand All @@ -42,13 +59,13 @@ protected void print(LogLevel logLevel, String message) {
return;
}

System.err.println(logLevel+" "+DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date())+ ":"+name + ": " + message);
err.println(logLevel+" "+DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date())+ ":"+name + ": " + message);
}

public void severe(String message, Throwable e) {
if (getLogLevel().compareTo(LogLevel.SEVERE) <=0) {
print(LogLevel.SEVERE, message);
e.printStackTrace();
e.printStackTrace(err);
}
}

Expand All @@ -61,7 +78,7 @@ public void warning(String message) {
public void warning(String message, Throwable e) {
if (getLogLevel().compareTo(LogLevel.WARNING) <=0) {
print(LogLevel.WARNING, message);
e.printStackTrace();
e.printStackTrace(err);
}
}

Expand All @@ -74,7 +91,7 @@ public void info(String message) {
public void info(String message, Throwable e) {
if (getLogLevel().compareTo(LogLevel.INFO) <=0) {
print(LogLevel.INFO, message);
e.printStackTrace();
e.printStackTrace(err);
}
}

Expand All @@ -87,7 +104,7 @@ public void debug(String message) {
public void debug(String message, Throwable e) {
if (getLogLevel().compareTo(LogLevel.DEBUG) <=0) {
print(LogLevel.DEBUG, message);
e.printStackTrace();
e.printStackTrace(err);
}

}
Expand Down
@@ -0,0 +1,79 @@
package liquibase.sqlgenerator.core;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import liquibase.database.Database;
import liquibase.database.core.DB2Database;
import liquibase.database.core.InformixDatabase;
import liquibase.database.core.MSSQLDatabase;
import liquibase.database.core.PostgresDatabase;
import liquibase.database.core.SybaseASADatabase;
import liquibase.database.structure.Index;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.statement.core.CreateIndexStatement;
import liquibase.util.StringUtils;

public class CreateIndexGeneratorPostgres extends CreateIndexGenerator {

@Override
public int getPriority() {
return PRIORITY_DATABASE;
}

@Override
public boolean supports(CreateIndexStatement statement, Database database) {
return database instanceof PostgresDatabase;
}

public Sql[] generateSql(CreateIndexStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {

// Default filter of index creation:
// creation of all indexes with associations are switched off.
List<String> associatedWith = StringUtils.splitAndTrim(statement.getAssociatedWith(), ",");
if (associatedWith != null && (associatedWith.contains(Index.MARK_PRIMARY_KEY) ||
associatedWith.contains(Index.MARK_UNIQUE_CONSTRAINT) ||
associatedWith.contains(Index.MARK_FOREIGN_KEY))) {
return new Sql[0];
}

StringBuilder buffer = new StringBuilder();

buffer.append("CREATE ");
if (statement.isUnique() != null && statement.isUnique()) {
buffer.append("UNIQUE ");
}
buffer.append("INDEX ");

if (statement.getIndexName() != null) {
String indexSchema = statement.getTableSchemaName();
buffer.append(database.escapeIndexName(null, statement.getIndexName())).append(" ");
}
buffer.append("ON ");
buffer.append(database.escapeTableName(statement.getTableSchemaName(), statement.getTableName())).append("(");
Iterator<String> iterator = Arrays.asList(statement.getColumns()).iterator();
while (iterator.hasNext()) {
String column = iterator.next();
buffer.append(database.escapeColumnName(statement.getTableSchemaName(), statement.getTableName(), column));
if (iterator.hasNext()) {
buffer.append(", ");
}
}
buffer.append(")");

if (StringUtils.trimToNull(statement.getTablespace()) != null && database.supportsTablespaces()) {
if (database instanceof MSSQLDatabase || database instanceof SybaseASADatabase) {
buffer.append(" ON ").append(statement.getTablespace());
} else if (database instanceof DB2Database || database instanceof InformixDatabase) {
buffer.append(" IN ").append(statement.getTablespace());
} else {
buffer.append(" TABLESPACE ").append(statement.getTablespace());
}
}

return new Sql[]{new UnparsedSql(buffer.toString())};
}
}
Expand Up @@ -45,7 +45,7 @@ public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database
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 FK.TABLE_NAME='").append(statement.getBaseTableName()).append("'");
sb.append("WHERE lower(FK.TABLE_NAME)='").append(statement.getBaseTableName().toLowerCase()).append("'");

return new Sql[] {
new UnparsedSql(sb.toString())
Expand Down

0 comments on commit 28883bc

Please sign in to comment.