Skip to content

Commit

Permalink
support for additional projects that need to depend on local reposito…
Browse files Browse the repository at this point in the history
…ries and the test packages of symmetric-io
  • Loading branch information
chenson42 committed Feb 16, 2012
1 parent 4b7dbac commit fbf0ece
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 33 deletions.
2 changes: 1 addition & 1 deletion symmetric/symmetric-assemble/pom.xml
Expand Up @@ -31,7 +31,7 @@
<module>../symmetric-util</module>
<module>../symmetric-csv</module>
<module>../symmetric-db</module>
<module>../symmetric-jdbc</module>
<module>../symmetric-jdbc</module>
<module>../symmetric-io</module>
<module>../symmetric-core</module>
<module>../symmetric-client</module>
Expand Down
Expand Up @@ -115,7 +115,7 @@ public TriggerHistory(Table table, Trigger trigger, TriggerReBuildReason reason)
this.triggerId = trigger.getTriggerId();
this.pkColumnNames = getCommaDeliminatedColumns(table.getPrimaryKeyColumns());
this.triggerRowHash = trigger.toHashedValue();
tableHash = calculateTableHashFor(table);
tableHash = table.calculateTableHashcode();
}

public TriggerHistory(Trigger trigger) {
Expand All @@ -125,27 +125,6 @@ public TriggerHistory(Trigger trigger) {
this.triggerId = trigger.getTriggerId();
}

public static int calculateTableHashFor(Table table) {
final int PRIME = 31;
int result = 1;
result = PRIME * result + table.getName().hashCode();
result = PRIME * result + calculateHashForColumns(PRIME, table.getColumns());
result = PRIME * result + calculateHashForColumns(PRIME, table.getPrimaryKeyColumns());
return result;
}

private static int calculateHashForColumns(final int PRIME, Column[] cols) {
int result = 1;
if (cols != null && cols.length > 0) {
for (Column column : cols) {
result = PRIME * result + column.getName().hashCode();
result = PRIME * result + column.getType().hashCode();
result = PRIME * result + column.getSizeAsInt();
}
}
return result;
}

private String getCommaDeliminatedColumns(Column[] cols) {
StringBuilder columns = new StringBuilder();
if (cols != null && cols.length > 0) {
Expand Down
Expand Up @@ -888,7 +888,7 @@ protected void updateOrCreateDatabaseTriggers(List<Trigger> triggers, StringBuil
reason = TriggerReBuildReason.NEW_TRIGGERS;
forceRebuildOfTriggers = true;

} else if (TriggerHistory.calculateTableHashFor(table) != latestHistoryBeforeRebuild
} else if (table.calculateTableHashcode() != latestHistoryBeforeRebuild
.getTableHash()) {
reason = TriggerReBuildReason.TABLE_SCHEMA_CHANGED;
forceRebuildOfTriggers = true;
Expand Down
Expand Up @@ -246,10 +246,6 @@ public void initialize() throws ModelException {
HashSet<String> namesOfProcessedIndices = new HashSet<String>();
int tableIdx = 0;

if ((getName() == null) || (getName().length() == 0)) {
throw new ModelException("The database model has no name");
}

for (Iterator<Table> tableIt = tables.iterator(); tableIt.hasNext(); tableIdx++) {
Table curTable = tableIt.next();

Expand Down
Expand Up @@ -1029,6 +1029,29 @@ public String[] getPrimaryKeyColumnNames() {
}
return columnNames;
}

public int calculateTableHashcode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + name.hashCode();
result = PRIME * result + calculateHashcodeForColumns(PRIME, getColumns());
result = PRIME * result + calculateHashcodeForColumns(PRIME, getPrimaryKeyColumns());
return result;
}

private static int calculateHashcodeForColumns(final int PRIME, Column[] cols) {
int result = 1;
if (cols != null && cols.length > 0) {
for (Column column : cols) {
result = PRIME * result + column.getName().hashCode();
result = PRIME * result + column.getType().hashCode();
result = PRIME * result + column.getSizeAsInt();
}
}
return result;
}



public static Table buildTable(String tableName, String[] keyNames, String[] columnNames) {
Table table = new Table();
Expand Down
20 changes: 20 additions & 0 deletions symmetric/symmetric-io/pom.xml
Expand Up @@ -17,6 +17,26 @@
<version>3.0.0-SNAPSHOT</version>
<relativePath>../symmetric-parent/pom.xml</relativePath>
</parent>

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<phase>test-compile</phase>
</execution>
</executions>
<configuration>
<outputDirectory>${basedir}\target</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.jumpmind.db.AbstractDbTest;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.AbstractDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.symmetric.io.data.Batch;
Expand All @@ -25,6 +26,8 @@
abstract public class AbstractWriterTest extends AbstractDbTest {

protected static IDatabasePlatform platform;

protected boolean errorExpected = true;

protected final static String TEST_TABLE = "test_dataloader_table";

Expand Down Expand Up @@ -58,17 +61,17 @@ protected Table buildSourceTable(String tableName, String[] keyNames, String[] c
return Table.buildTable(tableName, keyNames, columnNames);
}

protected void writeData(CsvData data, String[] expectedValues) throws Exception {
protected void writeData(CsvData data, String[] expectedValues) {
writeData(data, expectedValues, TEST_COLUMNS);
}

protected void writeData(CsvData data, String[] expectedValues, String[] columnNames)
throws Exception {
{
writeData(data, expectedValues, TEST_TABLE, TEST_KEYS, columnNames);
}

protected void writeData(CsvData data, String[] expectedValues, String tableName,
String[] keyNames, String[] columnNames) throws Exception {
String[] keyNames, String[] columnNames) {
Table table = buildSourceTable(tableName, keyNames, columnNames);
writeData(new TableCsvData(table, data));
String[] pkData = data.getParsedData(CsvData.ROW_DATA);
Expand Down Expand Up @@ -100,6 +103,14 @@ protected long writeData(IDataWriter writer, TableCsvData... datas) {
writer.end(batch, false);
} catch (Exception ex) {
writer.end(batch, true);
if (!isErrorExpected()) {
if (ex instanceof RuntimeException) {
throw (RuntimeException)ex;
} else {
throw new RuntimeException(ex);
}
}

}

}
Expand Down Expand Up @@ -205,6 +216,18 @@ protected void assertEquals(String[] name, String[] expected, Map<String, Object
protected String printDatabase() {
return " The database we are testing against is " + platform.getName() + ".";
}

protected boolean isOracle() {
return DatabaseNamesConstants.ORACLE.equals(platform.getName());
}

public void setErrorExpected(boolean errorExpected) {
this.errorExpected = errorExpected;
}

public boolean isErrorExpected() {
return errorExpected;
}

class TableCsvData {
Table table;
Expand Down
Expand Up @@ -142,6 +142,8 @@ protected Integer overrideJdbcTypeForColumn(Map<String, Object> values) {
return Types.LONGVARCHAR;
} else if (typeName != null && typeName.startsWith("NCHAR")) {
return Types.CHAR;
} else if (typeName != null && typeName.startsWith("XML")) {
return Types.CLOB;
} else if (typeName != null && typeName.startsWith("NCLOB")) {
return Types.CLOB;
} else if (typeName != null && typeName.startsWith("BINARY_FLOAT")) {
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.AbstractJdbcDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.platform.DatabasePlatformSettings;
import org.jumpmind.db.sql.DmlStatement;
import org.jumpmind.db.sql.DmlStatement.DmlType;
Expand All @@ -38,7 +39,7 @@
public class OraclePlatform extends AbstractJdbcDatabasePlatform {

/* Database name of this platform. */
public static final String DATABASENAME = "Oracle";
public static final String DATABASENAME = DatabaseNamesConstants.ORACLE;

/* The standard Oracle jdbc driver. */
public static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
Expand Down
@@ -1,4 +1,4 @@
test.root=firebird
test.root=oracle
test.client=h2

mysql.db.driver=com.mysql.jdbc.Driver
Expand Down
17 changes: 17 additions & 0 deletions symmetric/symmetric-parent/pom.xml
Expand Up @@ -69,6 +69,11 @@
<id>snapshot</id>
<url>http://snapshots.repository.codehaus.org</url>
</repository>
<repository>
<id>symmetric-local</id>
<name>symmetric-local</name>
<url>file://${project.basedir}/src/repository</url>
</repository>
</repositories>

<issueManagement>
Expand Down Expand Up @@ -373,6 +378,18 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jumpmind.symmetric</groupId>
<artifactId>symmetric-io</artifactId>
<type>test-jar</type>
<version>3.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jumpmind.symmetric</groupId>
<artifactId>symmetric-io</artifactId>
Expand Down

0 comments on commit fbf0ece

Please sign in to comment.