use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.
the class DatabasePlatformTest method testExportDefaultValueWithUnderscores.
@Test
public void testExportDefaultValueWithUnderscores() {
Table table = new Table("TEST_DEFAULT_UNDERSCORES");
table.addColumn(new Column("ID", true));
table.getColumnWithName("ID").setTypeCode(Types.INTEGER);
table.getColumnWithName("ID").setRequired(true);
table.addColumn(new Column("NOTES"));
table.getColumnWithName("NOTES").setTypeCode(Types.VARCHAR);
table.getColumnWithName("NOTES").setSize("20");
table.getColumnWithName("NOTES").setDefaultValue("this_has_underscores");
Table tableFromDatabase = dropCreateAndThenReadTable(table);
assertEquals(table.getColumnWithName("NOTES").getDefaultValue(), tableFromDatabase.getColumnWithName("NOTES").getDefaultValue());
}
use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.
the class DatabasePlatformTest method testNvarcharType.
@Test
public void testNvarcharType() {
Table table = new Table("test_nvarchar");
table.addColumn(new Column("id", true, Types.INTEGER, 0, 0));
table.addColumn(new Column("note", false, ColumnTypes.NVARCHAR, 100, 0));
platform.createTables(true, false, table);
}
use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.
the class DatabasePlatformTest method testUpgradePrimaryKeyAutoIncrementFromIntToBigInt.
@Test
public void testUpgradePrimaryKeyAutoIncrementFromIntToBigInt() throws Exception {
boolean upgradeSupported = !platform.getName().equals(DatabaseNamesConstants.DERBY) && !platform.getName().equals(DatabaseNamesConstants.HSQLDB2) && !platform.getName().equals(DatabaseNamesConstants.INFORMIX) && !platform.getName().equals(DatabaseNamesConstants.DB2) && !platform.getName().equals(DatabaseNamesConstants.ASE) && !platform.getName().equals(DatabaseNamesConstants.MSSQL2000) && !platform.getName().equals(DatabaseNamesConstants.MSSQL2005) && !platform.getName().equals(DatabaseNamesConstants.MSSQL2008) && !platform.getName().equals(DatabaseNamesConstants.SQLANYWHERE);
if (upgradeSupported) {
Table table = new Table("TEST_UPGRADE");
table.addColumn(new Column("ID", true));
table.getColumnWithName("ID").setTypeCode(Types.INTEGER);
table.getColumnWithName("ID").setAutoIncrement(true);
table.getColumnWithName("ID").setRequired(true);
table.addColumn(new Column("NOTES"));
table.getColumnWithName("NOTES").setTypeCode(Types.VARCHAR);
table.getColumnWithName("NOTES").setSize("100");
Table tableFromDatabase = dropCreateAndThenReadTable(table);
assertNotNull(tableFromDatabase);
assertTrue(tableFromDatabase.getColumnWithName("ID").isPrimaryKey());
String insertSql = "insert into \"TEST_UPGRADE\" (\"ID\",\"NOTES\") values(null,?)";
insertSql = insertSql.replaceAll("\"", platform.getDatabaseInfo().getDelimiterToken());
long id1 = platform.getSqlTemplate().insertWithGeneratedKey(insertSql, "ID", getSequenceName(platform), new Object[] { "test" }, new int[] { Types.VARCHAR });
table.getColumnWithName("ID").setTypeCode(Types.BIGINT);
IDdlBuilder builder = platform.getDdlBuilder();
String alterSql = builder.alterTable(tableFromDatabase, table);
assertFalse(alterSql, alterSql.toLowerCase().contains("create table"));
new SqlScript(alterSql, platform.getSqlTemplate(), true, platform.getSqlScriptReplacementTokens()).execute(true);
tableFromDatabase = platform.getTableFromCache(table.getName(), true);
assertEquals(Types.BIGINT, table.getColumnWithName("ID").getMappedTypeCode());
assertTrue(tableFromDatabase.getColumnWithName("ID").isPrimaryKey());
long id2 = platform.getSqlTemplate().insertWithGeneratedKey(insertSql, "ID", getSequenceName(platform), new Object[] { "test" }, new int[] { Types.VARCHAR });
assertNotSame(id1, id2);
}
}
use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.
the class JdbcPersistenceManagerTest method setup.
@Before
public void setup() throws Exception {
manager = new JdbcPersistenceManager(createDatabasePlatform());
testTableA = new Table("A");
testTableA.addColumn(new Column("ID", true, Types.INTEGER, -1, -1));
testTableA.addColumn(new Column("LAST_UPDATE_TIME", false, Types.TIMESTAMP, -1, -1));
testTableA.addColumn(new Column("NOTE", false, Types.VARCHAR, 100, -1));
manager.getDatabasePlatform().alterCaseToMatchDatabaseDefaultCase(testTableA);
manager.getDatabasePlatform().createTables(true, true, testTableA);
}
use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.
the class MySqlDdlReader method readColumn.
@Override
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
Column column = super.readColumn(metaData, values);
// is an illegal ISO value, so we replace it with NULL
if ((column.getMappedTypeCode() == Types.TIMESTAMP) && "0000-00-00 00:00:00".equals(column.getDefaultValue())) {
column.setDefaultValue(null);
}
// make sure the defaultvalue is null when an empty is returned.
if ("".equals(column.getDefaultValue())) {
column.setDefaultValue(null);
}
if (column.getJdbcTypeName().equalsIgnoreCase(TypeMap.POINT) || column.getJdbcTypeName().equalsIgnoreCase(TypeMap.LINESTRING) || column.getJdbcTypeName().equalsIgnoreCase(TypeMap.POLYGON)) {
column.setJdbcTypeName(TypeMap.GEOMETRY);
}
if (column.getJdbcTypeName().equalsIgnoreCase("enum")) {
ISqlTemplate template = platform.getSqlTemplate();
String unParsedEnums = template.queryForString("SELECT SUBSTRING(COLUMN_TYPE,5) FROM information_schema.COLUMNS" + " WHERE TABLE_SCHEMA=? AND TABLE_NAME=? AND COLUMN_NAME=?", metaData.getCatalog(), (String) values.get("TABLE_NAME"), column.getName());
if (unParsedEnums != null) {
unParsedEnums = unParsedEnums.trim();
if (unParsedEnums.startsWith("(")) {
unParsedEnums = unParsedEnums.substring(1);
if (unParsedEnums.endsWith(")")) {
unParsedEnums = unParsedEnums.substring(0, unParsedEnums.length() - 1);
}
}
String[] parsedEnums = unParsedEnums.split(",");
for (int i = 0; i < parsedEnums.length; i++) {
String parsedEnum = parsedEnums[i];
if (parsedEnum.startsWith("'")) {
parsedEnum = parsedEnum.substring(1);
if (parsedEnum.endsWith("'")) {
parsedEnum = parsedEnum.substring(0, parsedEnum.length() - 1);
}
}
parsedEnums[i] = parsedEnum;
}
column.setEnumValues(parsedEnums);
}
}
return column;
}
Aggregations