use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.
the class GetSchemaTaskTest method innerTestGetSchemaTask.
public void innerTestGetSchemaTask() {
try {
if (!createTestTable()) {
dropTestTable();
//test again
if (!createTestTable()) {
fail();
}
}
} catch (Exception e) {
fail();
}
testTableName = testTableName.toLowerCase();
GetSchemaTask task = new GetSchemaTask(databaseInfo, testTableName);
task.execute();
SchemaInfo jSchema = task.getSchema();
DBAttribute attr = null;
SerialInfo auto = null;
//"smallint" smallint AUTO_INCREMENT PRIMARY KEY UNIQUE,
attr = jSchema.getAttributes().get(0);
assertFalse(attr.isClassAttribute());
assertEquals("smallint", attr.getName());
assertEquals("smallint", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNotNull(auto);
assertEquals("1", auto.getMinValue());
assertEquals("1", auto.getIncrementValue());
//"smallint2" smallint,
attr = jSchema.getAttributes().get(1);
assertFalse(attr.isClassAttribute());
assertEquals("smallint2", attr.getName());
assertEquals("smallint", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"integer" integer AUTO_INCREMENT(2,1),
attr = jSchema.getAttributes().get(2);
assertFalse(attr.isClassAttribute());
assertEquals("integer", attr.getName());
assertEquals("integer", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNotNull(auto);
assertEquals("2", auto.getMinValue());
assertEquals("1", auto.getIncrementValue());
//"bigint" bigint,
attr = jSchema.getAttributes().get(3);
assertFalse(attr.isClassAttribute());
assertEquals("bigint", attr.getName());
assertEquals("bigint", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"numeric1" numeric(15,0) AUTO_INCREMENT UNIQUE,
attr = jSchema.getAttributes().get(4);
assertFalse(attr.isClassAttribute());
assertEquals("numeric1", attr.getName());
assertEquals("numeric(15,0)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNotNull(auto);
assertEquals("1", auto.getMinValue());
assertEquals("1", auto.getIncrementValue());
//"numeric2" numeric(17,2) DEFAULT 12.50,
attr = jSchema.getAttributes().get(5);
assertFalse(attr.isClassAttribute());
assertEquals("numeric2", attr.getName());
assertEquals("numeric(17,2)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("12.50", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"float" float DEFAULT 12 NOT NULL,
attr = jSchema.getAttributes().get(6);
assertFalse(attr.isClassAttribute());
assertEquals("float", attr.getName());
assertEquals("float", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("12", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"date" date DEFAULT DATE'12/12/2009',
attr = jSchema.getAttributes().get(7);
assertFalse(attr.isClassAttribute());
assertEquals("date", attr.getName());
assertEquals("date", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("2009/12/12", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"datetime" datetime DEFAULT DATETIME'2009-12-12 12:12:12.333',
attr = jSchema.getAttributes().get(8);
assertFalse(attr.isClassAttribute());
assertEquals("datetime", attr.getName());
assertEquals("datetime", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("2009-12-12 12:12:12.333", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"timestamp" timestamp DEFAULT TIMESTAMP'12/01/2009 03:07:51',
attr = jSchema.getAttributes().get(9);
assertFalse(attr.isClassAttribute());
assertEquals("timestamp", attr.getName());
assertEquals("timestamp", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("2009-12-01 03:07:51", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"time" time DEFAULT TIME'00:00:12',
attr = jSchema.getAttributes().get(10);
assertFalse(attr.isClassAttribute());
assertEquals("time", attr.getName());
assertEquals("time", attr.getType());
assertEquals(testTableName, attr.getInherit());
//assertEquals("AM 12:00:12", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"char" character(10) DEFAULT 'aa ',
attr = jSchema.getAttributes().get(11);
assertFalse(attr.isClassAttribute());
assertEquals("char", attr.getName());
assertEquals("character(10)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("'aa '", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"varchar" character varying(10) DEFAULT '77',
attr = jSchema.getAttributes().get(12);
assertFalse(attr.isClassAttribute());
assertEquals("varchar", attr.getName());
assertEquals("character varying(10)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("'77'", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"setint" set_of(smallint) DEFAULT {1, 2},
attr = jSchema.getAttributes().get(13);
assertFalse(attr.isClassAttribute());
assertEquals("setint", attr.getName());
assertEquals("set_of(smallint)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("{1, 2}", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"multisetchar" multiset_of(character varying(10)) DEFAULT {'12', '13'},
attr = jSchema.getAttributes().get(14);
assertFalse(attr.isClassAttribute());
assertEquals("multisetchar", attr.getName());
assertEquals("multiset_of(character varying(10))", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertEquals("{'12', '13'}", attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"shared" character varying(1073741823) SHARED 'sharedvalue'
attr = jSchema.getAttributes().get(15);
assertFalse(attr.isClassAttribute());
assertEquals("shared", attr.getName());
assertEquals("character varying(1073741823)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertTrue(attr.isShared());
assertEquals("'sharedvalue'", attr.getSharedValue());
auto = attr.getAutoIncrement();
assertNull(auto);
//"bit" bit(1),
attr = jSchema.getAttributes().get(16);
assertFalse(attr.isClassAttribute());
assertEquals("bit", attr.getName());
assertEquals("bit(1)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"bitv" bit varying(100),
attr = jSchema.getAttributes().get(17);
assertFalse(attr.isClassAttribute());
assertEquals("bitv", attr.getName());
assertEquals("bit varying(100)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"nchar" national character(1),
attr = jSchema.getAttributes().get(18);
assertFalse(attr.isClassAttribute());
assertEquals("nchar", attr.getName());
assertEquals("national character(1)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
//"varnchar" national character varying(100)
attr = jSchema.getAttributes().get(19);
assertFalse(attr.isClassAttribute());
assertEquals("varnchar", attr.getName());
assertEquals("national character varying(100)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "sequence_numeric" sequence_of(numeric(15,1)),
attr = jSchema.getAttributes().get(20);
assertFalse(attr.isClassAttribute());
assertEquals("sequence_numeric", attr.getName());
assertEquals("sequence_of(numeric(15,1))", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "set_bigint" set_of(bigint),
attr = jSchema.getAttributes().get(21);
assertFalse(attr.isClassAttribute());
assertEquals("set_bigint", attr.getName());
assertEquals("set_of(bigint)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "multiset_float" multiset_of(float),
attr = jSchema.getAttributes().get(22);
assertFalse(attr.isClassAttribute());
assertEquals("multiset_float", attr.getName());
assertEquals("multiset_of(float)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "sequence_nchar" sequence_of(national character(2)),
attr = jSchema.getAttributes().get(23);
assertFalse(attr.isClassAttribute());
assertEquals("sequence_nchar", attr.getName());
assertEquals("sequence_of(national character(2))", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "set_vnchar" set_of(national character varying(100)),
attr = jSchema.getAttributes().get(24);
assertFalse(attr.isClassAttribute());
assertEquals("set_vnchar", attr.getName());
assertEquals("set_of(national character varying(100))", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "set_time" set_of(time),
attr = jSchema.getAttributes().get(25);
assertFalse(attr.isClassAttribute());
assertEquals("set_time", attr.getName());
assertEquals("set_of(time)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "multiset_date" multiset_of(date),
attr = jSchema.getAttributes().get(26);
assertFalse(attr.isClassAttribute());
assertEquals("multiset_date", attr.getName());
assertEquals("multiset_of(date)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "sequence_datetime" sequence_of(datetime),
attr = jSchema.getAttributes().get(27);
assertFalse(attr.isClassAttribute());
assertEquals("sequence_datetime", attr.getName());
assertEquals("sequence_of(datetime)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "set_timestamp" set_of(timestamp),
attr = jSchema.getAttributes().get(28);
assertFalse(attr.isClassAttribute());
assertEquals("set_timestamp", attr.getName());
assertEquals("set_of(timestamp)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "multiset_monetary" multiset_of(monetary),
attr = jSchema.getAttributes().get(29);
assertFalse(attr.isClassAttribute());
assertEquals("multiset_monetary", attr.getName());
assertEquals("multiset_of(monetary)", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "sequence_bit" sequence_of(bit(2)),
attr = jSchema.getAttributes().get(30);
assertFalse(attr.isClassAttribute());
assertEquals("sequence_bit", attr.getName());
assertEquals("sequence_of(bit(2))", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
// "set_varbit" set_of(bit varying(120))
attr = jSchema.getAttributes().get(31);
assertFalse(attr.isClassAttribute());
assertEquals("set_varbit", attr.getName());
assertEquals("set_of(bit varying(120))", attr.getType());
assertEquals(testTableName, attr.getInherit());
assertNull(attr.getDefault());
auto = attr.getAutoIncrement();
assertNull(auto);
List<String> ruleList = new ArrayList<String>();
List<String> attrList = new ArrayList<String>();
String constraintName = null;
Constraint constraint = null;
//CREATE UNIQUE INDEX ON "testgetrecordcounttask"("numeric2" DESC,"float" ASC,"date" DESC);
attrList.clear();
ruleList.clear();
attrList.add("numeric2");
attrList.add("float");
attrList.add("date");
ruleList.add("numeric2 DESC");
ruleList.add("float ASC");
ruleList.add("date DESC");
constraintName = ConstraintNamingUtil.getUniqueName(testTableName, ruleList);
constraint = jSchema.getConstraintByName(constraintName);
assertNotNull(constraint);
assertEquals(attrList, constraint.getAttributes());
assertEquals(ruleList, constraint.getRules());
//CREATE REVERSE UNIQUE INDEX ON "testgetrecordcounttask"("integer" DESC,"bigint" ASC);
attrList.clear();
ruleList.clear();
attrList.add("integer");
attrList.add("bigint");
ruleList.add("integer DESC");
ruleList.add("bigint ASC");
constraintName = ConstraintNamingUtil.getReverseUniqueName(testTableName, attrList);
constraint = jSchema.getConstraintByName(constraintName);
assertNotNull(constraint);
assertEquals(attrList, constraint.getAttributes());
assertNotSame(ruleList, constraint.getRules());
assertEquals("integer DESC", constraint.getRules().get(0));
assertEquals("bigint DESC", constraint.getRules().get(1));
//CREATE INDEX ON "testgetrecordcounttask"("smallint" DESC,"smallint2" DESC);
attrList.clear();
ruleList.clear();
attrList.add("smallint");
attrList.add("smallint2");
ruleList.add("smallint DESC");
ruleList.add("smallint2 DESC");
constraintName = ConstraintNamingUtil.getIndexName(testTableName, ruleList);
constraint = jSchema.getConstraintByName(constraintName);
assertNotNull(constraint);
assertEquals(attrList, constraint.getAttributes());
assertEquals(ruleList, constraint.getRules());
//CREATE REVERSE INDEX ON "testgetrecordcounttask"("numeric1" ASC,"numeric2" DESC);
attrList.clear();
ruleList.clear();
attrList.add("numeric1");
attrList.add("numeric2");
ruleList.add("numeric1 ASC");
ruleList.add("numeric2 DESC");
constraintName = ConstraintNamingUtil.getReverseIndexName(testTableName, attrList);
constraint = jSchema.getConstraintByName(constraintName);
assertNotNull(constraint);
assertEquals(attrList, constraint.getAttributes());
assertEquals("numeric1 DESC", constraint.getRules().get(0));
assertEquals("numeric2 DESC", constraint.getRules().get(1));
task.setErrorMsg("errorMsg");
task.execute();
task.setErrorMsg(null);
task.execute();
task.cancel();
task.execute();
}
use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.
the class SchemaDDLTest method testGetAlterDDL2.
public void testGetAlterDDL2() throws Exception {
boolean success = createTestTable();
assertTrue(success);
SchemaChangeManager changeLogMgr = new SchemaChangeManager(databaseInfo, false);
SchemaInfo schema = databaseInfo.getSchemaInfo(testTableName);
SchemaInfo alteredschema = schema.clone();
alteredschema.setClassname("alteredName");
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(schema.getClassname(), alteredschema.getClassname(), SchemeInnerType.TYPE_SCHEMA));
/*Change supper*/
schema.setSuperClasses(new ArrayList<String>());
alteredschema.setSuperClasses(new ArrayList<String>());
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(schema.getClassname(), alteredschema.getClassname(), SchemeInnerType.TYPE_SUPER_TABLE));
/*Remove attr*/
alteredschema.removeDBAttributeByName("gender", false);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog("gender", null, SchemeInnerType.TYPE_ATTRIBUTE));
/*Change position*/
DBAttribute charAttr = alteredschema.getDBAttributeByName("char", false);
alteredschema.getAttributes().remove(charAttr);
alteredschema.addAttribute(charAttr);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(charAttr.getName(), charAttr.getName(), SchemeInnerType.TYPE_POSITION));
/*Change attr*/
DBAttribute attr1 = alteredschema.getDBAttributeByName("nation_code", false);
alteredschema.removeDBAttributeByName("nation_code", false);
attr1.setName("nation_code2");
attr1.setDefault("c");
attr1.setNotNull(true);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog("nation_code", "nation_code2", SchemeInnerType.TYPE_ATTRIBUTE));
alteredschema.addAttribute(attr1);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog("nation_code", "nation_code2", SchemeInnerType.TYPE_POSITION));
/*Add attr*/
DBAttribute newAttr = new DBAttribute();
newAttr.setName("newAttr");
newAttr.setDefault("0");
newAttr.setNotNull(false);
newAttr.setType("String");
newAttr.setUnique(false);
newAttr.setInherit(alteredschema.getClassname());
/*Add pk attr*/
DBAttribute pkAttr = new DBAttribute();
pkAttr.setName("pkAttr");
pkAttr.setNotNull(true);
pkAttr.setType("Integer");
pkAttr.setUnique(true);
pkAttr.setInherit(alteredschema.getClassname());
pkAttr.setAutoIncrement(new SerialInfo("pk", "dba", "0", "1", "999999", "0", true, "0", "0", alteredschema.getClassname(), pkAttr.getName()));
alteredschema.addAttribute(newAttr);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(null, newAttr.getName(), SchemeInnerType.TYPE_ATTRIBUTE));
/*Add index*/
Constraint index = new Constraint(false);
index.setType(Constraint.ConstraintType.INDEX.getText());
index.addAttribute("newAttr");
index.addRule("newAttr_index DESC");
index.setName(ConstraintNamingUtil.getIndexName(alteredschema.getClassname(), index.getRules()));
alteredschema.addConstraint(index);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(null, index.getDefaultName(alteredschema.getClassname()) + "$" + index.getName(), SchemeInnerType.TYPE_INDEX));
/*Remove index*/
Constraint removeConstraint = alteredschema.getConstraints().get(0);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(removeConstraint.getDefaultName(alteredschema.getClassname()) + "$" + removeConstraint.getName(), null, SchemeInnerType.TYPE_INDEX));
/*Add pk*/
Constraint pk = new Constraint(false);
pk.addAttribute(pkAttr.getName());
pk.setName(ConstraintNamingUtil.getPKName(alteredschema.getClassname(), pk.getAttributes()));
pk.setType(Constraint.ConstraintType.PRIMARYKEY.getText());
pk.addRule("pkAttr_pk ASC");
alteredschema.addConstraint(pk);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(null, pk.getDefaultName(alteredschema.getClassname()) + "$" + pk.getName(), SchemeInnerType.TYPE_INDEX));
/*Remove fk*/
Constraint fk2 = new Constraint(false);
fk2.setType(Constraint.ConstraintType.FOREIGNKEY.getText());
fk2.addAttribute(pkAttr.getName());
fk2.addRule("REFERENCES " + testTableName);
fk2.addRule("ON DELETE RESTRICT ON UPDATE RESTRICT");
String fkName2 = ConstraintNamingUtil.getFKName(schema.getClassname(), fk2.getAttributes());
fk2.setName(fkName2);
schema.addConstraint(fk2);
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(fk2.getName(), null, SchemeInnerType.TYPE_FK));
/*Alter fk*/
Constraint alterFK = alteredschema.getFKConstraints().get(0);
String oldFKName = alterFK.getName();
alterFK.setName(ConstraintNamingUtil.getFKName(schema.getClassname(), fk2.getAttributes()) + "temp");
changeLogMgr.addSchemeChangeLog(new SchemaChangeLog(oldFKName, alterFK.getName(), SchemeInnerType.TYPE_FK));
SchemaDDL schemaDDL = new SchemaDDL(changeLogMgr, databaseInfo);
assertNotNull(schemaDDL.getAlterDDL(schema, alteredschema));
// schemaDDL = new SchemaDDL(changeLogMgr, databaseInfo831);
// assertNotNull(schemaDDL.getAlterDDL(schema, alteredschema));
}
use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.
the class SerialInfoTest method testSerialInfo.
/**
* test Serial Information
*
*/
public void testSerialInfo() {
String name = "serial1";
String owner = "dba";
String currentValue = "1000";
String incrementValue = "1";
String maxValue = "10000";
String minValue = "1";
boolean isCyclic = true;
String startedValue = "1";
String cacheCount = "cacheCount";
String className = "code";
String attName = "id";
//test constructor
SerialInfo serialInfoNo = new SerialInfo();
assertNotNull(serialInfoNo);
SerialInfo serialInfo = new SerialInfo("serial1", "dba", "1000", "1", "10000", "1", true, "1", cacheCount, "code", "id");
assertNotNull(serialInfo);
//test getters and setters
serialInfo.setAttName(attName);
serialInfo.setClassName(className);
serialInfo.setCurrentValue(currentValue);
serialInfo.setCyclic(isCyclic);
serialInfo.setIncrementValue(incrementValue);
serialInfo.setMaxValue(maxValue);
serialInfo.setMinValue(minValue);
serialInfo.setName(name);
serialInfo.setOwner(owner);
serialInfo.setStartedValue(startedValue);
assertEquals(serialInfo.getAttName(), attName);
assertEquals(serialInfo.getClassName(), className);
assertEquals(serialInfo.getCurrentValue(), currentValue);
assertTrue(serialInfo.isCyclic());
assertEquals(serialInfo.getIncrementValue(), incrementValue);
assertEquals(serialInfo.getMaxValue(), maxValue);
assertEquals(serialInfo.getMinValue(), minValue);
assertEquals(serialInfo.getName(), name);
assertEquals(serialInfo.getOwner(), owner);
assertEquals(serialInfo.getStartedValue(), startedValue);
//test public boolean equals(Object obj)
assertTrue(serialInfo.equals(serialInfo));
assertFalse(serialInfo.equals(null));
assertFalse(serialInfo.equals("other object"));
//test public int hashCode()
serialInfo.hashCode();
//test public SerialInfo clone()
SerialInfo clonedSerialInfo = serialInfo.clone();
assertEquals(serialInfo, clonedSerialInfo);
SerialInfo serialInfoOther = new SerialInfo(null, null, null, null, null, null, false, null, null, null, null);
serialInfo.setAttName(null);
serialInfo.setClassName(null);
serialInfo.setCurrentValue(null);
serialInfo.setIncrementValue(null);
serialInfo.setMaxValue(null);
serialInfo.setMinValue(null);
serialInfo.setName(null);
serialInfo.setOwner(null);
serialInfo.setStartedValue(null);
serialInfo.setCacheCount(null);
serialInfo.equals(serialInfoOther);
SerialInfo serialInfoOther2 = new SerialInfo("serial11", "dba1", "1001", "11", "10001", "11", true, "11", "cacheCount", "code1", "id1");
serialInfo.equals(serialInfoOther2);
serialInfoOther2.equals(serialInfoOther);
}
use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.
the class SubAttribute method getAutoIncrementInfo.
/**
* Get auto increment information
*
* @param schemaInfo the SchemaInfo
* @throws SQLException the exception
*/
private void getAutoIncrementInfo(SchemaInfo schemaInfo) throws SQLException {
if (schemaInfo != null) {
List<SerialInfo> serialInfoList = new ArrayList<SerialInfo>();
//databaseInfo.getServerInfo().compareVersionKey("8.2.2") >= 0;
boolean isSupportCache = CompatibleUtil.isSupportCache(databaseInfo);
String sql = "SELECT owner.name, db_serial.* FROM db_serial WHERE class_name=?";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
try {
stmt = connection.prepareStatement(sql);
((PreparedStatement) stmt).setString(1, tableName);
rs = ((PreparedStatement) stmt).executeQuery();
while (rs.next()) {
String name = rs.getString("name");
String owner = rs.getString("owner.name");
String currentVal = rs.getString("current_val");
String incrementVal = rs.getString("increment_val");
String maxVal = rs.getString("max_val");
String minVal = rs.getString("min_val");
String cyclic = rs.getString("cyclic");
String startVal = rs.getString("started");
String className = rs.getString("class_name");
String attName = rs.getString("att_name");
String cacheCount = null;
if (isSupportCache) {
cacheCount = rs.getString("cached_num");
}
boolean isCycle = false;
if (cyclic != null && cyclic.equals("1")) {
isCycle = true;
}
SerialInfo serialInfo = new SerialInfo(name, owner, currentVal, incrementVal, maxVal, minVal, isCycle, startVal, cacheCount, className, attName);
serialInfoList.add(serialInfo);
}
for (SerialInfo autoIncrement : serialInfoList) {
String attrName = autoIncrement.getAttName();
assert (null != attrName);
DBAttribute a = schemaInfo.getDBAttributeByName(attrName, false);
if (a != null) {
a.setAutoIncrement(autoIncrement);
}
}
} finally {
QueryUtil.freeQuery(stmt, rs);
}
}
}
use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.
the class GetAllSchemaTask method getAutoIncrementInfo.
/**
* Get auto increment information
*
* @param schemaInfo the SchemaInfo
* @throws SQLException the exception
*/
private void getAutoIncrementInfo() throws SQLException {
List<SerialInfo> serialInfoList = new ArrayList<SerialInfo>();
boolean isSupportCache = CompatibleUtil.isSupportCache(databaseInfo);
String sql = "SELECT owner.name, db_serial.*" + " FROM db_serial" + " WHERE class_name IS NOT NULL";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
try {
stmt = connection.prepareStatement(sql);
rs = ((PreparedStatement) stmt).executeQuery();
while (rs.next()) {
String name = rs.getString("name");
String owner = rs.getString("owner.name");
String currentVal = rs.getString("current_val");
String incrementVal = rs.getString("increment_val");
String maxVal = rs.getString("max_val");
String minVal = rs.getString("min_val");
String cyclic = rs.getString("cyclic");
String startVal = rs.getString("started");
String className = rs.getString("class_name");
String attName = rs.getString("att_name");
String cacheCount = null;
if (isSupportCache) {
cacheCount = rs.getString("cached_num");
}
boolean isCycle = false;
if ("1".equals(cyclic)) {
isCycle = true;
}
SerialInfo serialInfo = new SerialInfo(name, owner, currentVal, incrementVal, maxVal, minVal, isCycle, startVal, cacheCount, className, attName);
serialInfoList.add(serialInfo);
}
for (SerialInfo autoIncrement : serialInfoList) {
String className = autoIncrement.getClassName();
String attrName = autoIncrement.getAttName();
assert (null != attrName);
SchemaInfo schemaInfo = schemas.get(className);
if (schemaInfo == null) {
LOGGER.error("Can't find a table with auto increment column : " + attrName);
continue;
}
DBAttribute a = schemaInfo.getDBAttributeByName(attrName, false);
if (a != null) {
a.setAutoIncrement(autoIncrement);
}
}
} finally {
QueryUtil.freeQuery(stmt, rs);
}
}
Aggregations