Search in sources :

Example 66 with SchemaInfo

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);
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) POJOTemplate(com.cubrid.cubridmanager.core.cubrid.table.model.POJOTemplate) POJOAttribute(com.cubrid.cubridmanager.core.cubrid.table.model.POJOAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 67 with SchemaInfo

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;
}
Also used : SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 68 with SchemaInfo

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());
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 69 with SchemaInfo

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());
}
Also used : SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 70 with 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());
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) HashMap(java.util.HashMap) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) ArrayList(java.util.ArrayList) DbSpaceInfo(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfo) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) QueryPlanInfo(com.cubrid.cubridmanager.core.cubrid.jobauto.model.QueryPlanInfo) BackupPlanInfo(com.cubrid.cubridmanager.core.cubrid.jobauto.model.BackupPlanInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)136 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)57 Constraint (com.cubrid.common.core.common.model.Constraint)56 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)15 List (java.util.List)15 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)10 Connection (java.sql.Connection)10 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)9 SQLException (java.sql.SQLException)9 TableItem (org.eclipse.swt.widgets.TableItem)9 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)8 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)7 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 DBResolution (com.cubrid.common.core.common.model.DBResolution)6 Map (java.util.Map)5