Skip to content

Commit

Permalink
dev checkin. working on postgres tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Feb 11, 2012
1 parent ef6a6e6 commit 98e413f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
Expand Up @@ -25,40 +25,56 @@ public TestTablesService(ISymmetricEngine engine) {

// TODO support insert of blob test for postgres and informix
public boolean insertIntoTestUseStreamLob(int id, String tableName, String lobValue) {
if (!DatabaseNamesConstants.POSTGRESQL.equals(platform.getName())
&& !DatabaseNamesConstants.INFORMIX.equals(platform.getName())) {
sqlTemplate.update(
String.format("insert into %s (test_id, test_blob) values(?, ?)", tableName),
new Object[] { id, lobValue.getBytes() },
new int[] { Types.INTEGER, Types.BLOB });
return true;
if (!DatabaseNamesConstants.INFORMIX.equals(platform.getName())) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
boolean updated = transaction.prepareAndExecute(String.format(
"insert into %s (test_id, test_blob) values(?, ?)", tableName),
new Object[] { id, lobValue.getBytes() }, new int[] { Types.INTEGER,
Types.BLOB }) > 0;
transaction.commit();
return updated;
} finally {
if (transaction != null) {
transaction.close();
}
}
} else {
return false;
}
}

// TODO support insert of blob test for postgres and informix
public boolean updateTestUseStreamLob(int id, String tableName, String lobValue) {
if (!DatabaseNamesConstants.POSTGRESQL.equals(platform.getName())
&& !DatabaseNamesConstants.INFORMIX.equals(platform.getName())) {
sqlTemplate.update(
String.format("update %s set test_blob=? where test_id=?", tableName),
new Object[] { lobValue.getBytes(), id },
new int[] { Types.BLOB, Types.INTEGER });
return true;
if (!DatabaseNamesConstants.INFORMIX.equals(platform.getName())) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
boolean updated = transaction.prepareAndExecute(
String.format("update %s set test_blob=? where test_id=?", tableName),
new Object[] { lobValue.getBytes(), id }, new int[] { Types.BLOB,
Types.INTEGER }) > 0;
transaction.commit();
return updated;
} finally {
if (transaction != null) {
transaction.close();
}
}
} else {
return false;
}
}

public void assertTestUseStreamBlobInDatabase(int id, String tableName, String expected) {
if (!DatabaseNamesConstants.POSTGRESQL.equals(platform.getName())
&& !DatabaseNamesConstants.INFORMIX.equals(platform.getName())) {
public void assertTestUseStreamBlobInDatabase(int id, String tableName, String expected,
String serverDatabaseName) {
if (!DatabaseNamesConstants.INFORMIX.equals(serverDatabaseName)) {
Map<String, Object> values = sqlTemplate.queryForMap("select test_blob from "
+ tableName + " where test_id=?", id);
Assert.assertEquals(
"The blob column for test_use_stream_lob was not loaded into the client database",
expected, new String((byte[]) values.get("TEST_BLOB")));
expected, values != null ? new String((byte[]) values.get("TEST_BLOB")) : null);
}
}

Expand Down
Expand Up @@ -31,17 +31,19 @@
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;
import org.jumpmind.db.util.BinaryEncoding;
import org.springframework.jdbc.support.lob.DefaultLobHandler;

/*
* The platform implementation for PostgresSql.
*/
public class PostgreSqlPlatform extends AbstractJdbcDatabasePlatform {
/* Database name of this platform. */
public static final String DATABASENAME = "PostgreSql";
public static final String DATABASENAME = DatabaseNamesConstants.POSTGRESQL;
/* The standard PostgreSQL jdbc driver. */
public static final String JDBC_DRIVER = "org.postgresql.Driver";
/* The subprotocol used by the standard PostgreSQL driver. */
Expand Down
Expand Up @@ -17,7 +17,7 @@ public static void setValues(PreparedStatement ps, Object[] args, int[] argTypes
LobHandler lobHandler) throws SQLException {
for (int i = 1; i <= args.length; i++) {
Object arg = args[i - 1];
int argType = argTypes != null && argTypes.length > i ? argTypes[i - 1] : SqlTypeValue.TYPE_UNKNOWN;
int argType = argTypes != null && argTypes.length >= i ? argTypes[i - 1] : SqlTypeValue.TYPE_UNKNOWN;
if (argType == Types.BLOB && lobHandler != null && arg instanceof byte[]) {
lobHandler.getLobCreator().setBlobAsBytes(ps, i, (byte[]) arg);
} else if (argType == Types.BLOB && lobHandler != null && arg instanceof String) {
Expand All @@ -30,6 +30,10 @@ public static void setValues(PreparedStatement ps, Object[] args, int[] argTypes
}
}

public static void main(String[] args) {
System.out.println(new byte[] {'0'}.getClass().equals(byte[].class));
}

protected static int verifyArgType(int argType) {
if (argType == -101) {
return SqlTypeValue.TYPE_UNKNOWN;
Expand Down
@@ -1,4 +1,4 @@
test.root=oracle
test.root=postgres
test.client=h2

mysql.db.driver=com.mysql.jdbc.Driver
Expand Down
2 changes: 1 addition & 1 deletion symmetric/symmetric-parent/pom.xml
Expand Up @@ -26,7 +26,7 @@
<version.derby>10.5.3.0_1</version.derby>
<version.hsqldb>2.2.4</version.hsqldb>
<version.h2>1.2.140</version.h2>
<version.postgresql>8.4-701.jdbc4</version.postgresql>
<version.postgresql>9.1-901-1.jdbc4 </version.postgresql>
<version.mysql>5.1.17</version.mysql>
<test.root>h2</test.root>
<test.client>h2</test.client>
Expand Down
Expand Up @@ -149,9 +149,9 @@ public void initialLoad() {
.isInitialLoadEnabled());

clientTestService.assertTestUseStreamBlobInDatabase(100, "test_use_stream_lob",
THIS_IS_A_TEST);
THIS_IS_A_TEST, getServer().getSymmetricDialect().getPlatform().getName());
clientTestService.assertTestUseStreamBlobInDatabase(100, "test_use_capture_lob",
THIS_IS_A_TEST);
THIS_IS_A_TEST, getServer().getSymmetricDialect().getPlatform().getName());
}

@Test(timeout = 120000)
Expand Down

0 comments on commit 98e413f

Please sign in to comment.