use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class JavaType method getJavaPOJOString.
/**
* Get the POJO String, The type of schemaNode should be table or class
*
* @param schemaNode
* @return the POJO String
*/
public static String getJavaPOJOString(Connection connection, DefaultSchemaNode schemaNode) {
CubridDatabase database = schemaNode.getDatabase();
String tableName = schemaNode.getName();
SchemaInfo schemaInfo = null;
if (connection == null) {
schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
} else {
schemaInfo = database.getDatabaseInfo().getSchemaInfo(connection, tableName);
}
if (schemaInfo == null) {
com.cubrid.common.ui.spi.util.CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
LOGGER.debug("Can't get the SchemaInfo:" + tableName);
return "";
}
POJOTemplate template = new POJOTemplate();
template.setTableName(tableName);
StringBuffer typeDeclareSB = new StringBuffer();
typeDeclareSB.append("public class ");
typeDeclareSB.append(getUpperName(tableName));
template.setTypeDeclare(typeDeclareSB.toString());
StringBuffer annotationSB = new StringBuffer();
annotationSB.append("/**" + NEW_LINE);
annotationSB.append(" * Table name : " + tableName + NEW_LINE);
annotationSB.append(" * Generated by CUBRID Tools." + NEW_LINE);
annotationSB.append(" */");
template.setAnnotation(annotationSB.toString());
/* Attributes */
for (DBAttribute dbAttribute : schemaInfo.getAttributes()) {
POJOAttribute attribute = getPOJOAttribute(dbAttribute, true);
if (attribute != null) {
template.getAttributes().add(attribute);
}
}
/* Class Attribute */
for (DBAttribute dbAttribute : schemaInfo.getClassAttributes()) {
POJOAttribute attribute = getPOJOAttribute(dbAttribute, true);
if (attribute != null) {
template.getAttributes().add(attribute);
}
}
return getJavaPOJOString(template);
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class SQLGenerateUtils method getCreateSQL.
/**
*
* Get create table SQL
*
* @param schemaNode DefaultSchemaNode
*
* @return String
*/
public static String getCreateSQL(DatabaseInfo databaseInfo, String tableName) {
if (databaseInfo == null || tableName == null) {
return "";
}
SchemaDDL schemaDDL = new SchemaDDL(null, databaseInfo);
SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
if (schemaInfo == null) {
// LOGGER.debug("Can't get the SchemaInfo:" + tableName);
return "";
}
String sql = schemaDDL.getSchemaDDL(schemaInfo) + StringUtil.NEWLINE;
return sql;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class SQLGenerateUtils method generateCloneTableSql.
public static String generateCloneTableSql(DefaultSchemaNode schemaNode, String newName) {
CubridDatabase database = schemaNode.getDatabase();
String tableName = schemaNode.getName();
SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
if (schemaInfo == null) {
CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
LOGGER.debug("Can't get the SchemaInfo:" + tableName);
return "";
}
int columnCounts = schemaInfo == null ? 0 : schemaInfo.getAttributes().size();
StringBuilder columns = new StringBuilder();
if (columnCounts > 0) {
for (int i = 0; i < columnCounts; i++) {
DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
if (columns.length() > 0) {
columns.append(", ");
}
columns.append(QuerySyntax.escapeKeyword(da.getName()));
}
} else {
columns.append("*");
}
StringBuffer sql = new StringBuffer();
sql.append("CREATE TABLE ");
sql.append(QuerySyntax.escapeKeyword(newName));
sql.append(" AS ").append(StringUtil.NEWLINE).append("SELECT ");
sql.append(columns);
sql.append(StringUtil.NEWLINE).append("FROM ");
sql.append(QuerySyntax.escapeKeyword(tableName));
sql.append(";");
return format(sql.toString());
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class DatabaseInfoTest method testPutSchemaInfo.
/**
* Test method for
* {@link com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo#putSchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)}
* .
*/
public void testPutSchemaInfo() {
bean.putSchemaInfo(new SchemaInfo());
bean.clearSchemas();
bean.putSchemaInfo(new SchemaInfo());
bean.putSchemaInfo(new SchemaInfo());
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class DatabaseModelTest method testModelDatabaseInfo.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testModelDatabaseInfo() {
DatabaseInfo bean = new DatabaseInfo(testDbName, serverInfo);
bean.setDbName("dbName");
assertEquals(bean.getDbName(), "dbName");
bean.setLogined(true);
assertTrue(bean.isLogined());
bean.setDbDir("dbDir");
assertEquals(bean.getDbDir(), "dbDir");
bean.setRunningType(DbRunningType.CS);
assertEquals(bean.getRunningType(), DbRunningType.CS);
DbUserInfoList dbUserInfoList = new DbUserInfoList();
bean.setDbUserInfoList(dbUserInfoList);
assertTrue(bean.getDbUserInfoList() != null);
DbUserInfo dbUserInfo = new DbUserInfo();
bean.addDbUserInfo(dbUserInfo);
bean.removeDbUserInfo(dbUserInfo);
bean.setAuthLoginedDbUserInfo(dbUserInfo);
assertEquals(bean.getAuthLoginedDbUserInfo(), dbUserInfo);
bean.setBrokerPort("brokerPort");
assertEquals(bean.getBrokerPort(), "brokerPort");
bean.setTriggerList(new ArrayList());
assertEquals(bean.getTriggerList() != null, true);
bean.setUserTableInfoList(new ArrayList());
assertEquals(bean.getUserTableInfoList() != null, true);
bean.setUserViewInfoList(new ArrayList());
assertEquals(bean.getUserViewInfoList() != null, true);
bean.setSysTableInfoList(new ArrayList());
assertEquals(bean.getSysTableInfoList() != null, true);
bean.setSysViewInfoList(new ArrayList());
assertEquals(bean.getSysViewInfoList() != null, true);
bean.setPartitionedTableMap(new HashMap());
assertEquals(bean.getPartitionedTableMap() != null, true);
bean.setBackupPlanInfoList(new ArrayList());
assertEquals(bean.getBackupPlanInfoList() != null, true);
bean.setQueryPlanInfoList(new ArrayList());
assertEquals(bean.getQueryPlanInfoList() != null, true);
bean.setDbSpaceInfoList(new DbSpaceInfoList());
assertEquals(bean.getDbSpaceInfoList() != null, true);
bean.setDbUserInfoList(new DbUserInfoList());
assertEquals(bean.getDbUserInfoList() != null, true);
bean.setSpProcedureInfoList(new ArrayList());
assertEquals(bean.getSpProcedureInfoList() != null, true);
bean.setSpFunctionInfoList(new ArrayList());
assertEquals(bean.getSpFunctionInfoList() != null, true);
bean.setSerialInfoList(new ArrayList());
assertEquals(bean.getSerialInfoList() != null, true);
bean.setServerInfo(serverInfo);
assertEquals(bean.getServerInfo() != null, true);
bean.clear();
bean.setLogined(true);
assertEquals(bean.isLogined(), true);
bean.addDbUserInfo(new DbUserInfo());
bean.removeDbUserInfo(new DbUserInfo());
bean.getClassInfoList();
bean.addPartitionedTableList("dbname", null);
bean.addBackupPlanInfo(new BackupPlanInfo());
bean.removeBackupPlanInfo(new BackupPlanInfo());
bean.removeAllBackupPlanInfo();
bean.addQueryPlanInfo(new QueryPlanInfo());
bean.removeQueryPlanInfo(new QueryPlanInfo());
bean.removeAllQueryPlanInfo();
bean.addSpaceInfo(new DbSpaceInfo());
bean.removeSpaceInfo(new DbSpaceInfo());
bean.getSpInfoList();
bean.getSchemaInfo("tableName");
bean.putSchemaInfo(new SchemaInfo());
bean.clearSchemas();
bean.getErrorMessage();
bean.setDbUserInfoList(null);
assertEquals(bean.getDbUserInfoList(), null);
bean.addDbUserInfo(new DbUserInfo());
bean.removeDbUserInfo(new DbUserInfo());
}
Aggregations