Search in sources :

Example 6 with SchemaDDL

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL 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 7 with SchemaDDL

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL in project cubrid-manager by CUBRID.

the class TableSchemaCompareComposite method getTableAlterScript.

/**
	 * Returns table schema update/alter script
	 *
	 * @param sourceDatabase
	 * @param targetDatabase
	 * @param tableCompare
	 */
public String getTableAlterScript(CubridDatabase sourceDatabase, CubridDatabase targetDatabase, String tableCompare, SchemaInfo sourceSchemaInfo, SchemaInfo targetSchemaInfo) {
    // FIXME logic code move to core module
    String alterDDL = null;
    try {
        DatabaseInfo source_dbInfo = sourceDatabase.getDatabaseInfo();
        DatabaseInfo target_dbInfo = targetDatabase.getDatabaseInfo();
        if (sourceSchemaInfo == null || !"normal".equals(sourceSchemaInfo.getVirtual()))
            sourceSchemaInfo = null;
        if (targetSchemaInfo == null || !"normal".equals(targetSchemaInfo.getVirtual()))
            targetSchemaInfo = null;
        SchemaChangeManager sourceChangeManger = new SchemaChangeManager(source_dbInfo, false);
        SchemaDDL sourceSchemaDDL = new SchemaDDL(sourceChangeManger, sourceDatabase.getDatabaseInfo());
        SchemaChangeManager targetChangeManger = new SchemaChangeManager(target_dbInfo, false);
        SchemaDDL targetSchemaDDL = null;
        if (targetDatabase.isVirtual()) {
            WrappedDatabaseInfo info = ERXmlDatabaseInfoMapper.getWrappedDatabaseInfo(target_dbInfo);
            targetSchemaDDL = new SchemaDDL(targetChangeManger, info);
        } else {
            targetSchemaDDL = new SchemaDDL(targetChangeManger, targetDatabase.getDatabaseInfo());
        }
        TableSchemaCompareUpdateDDL tableCompareDDL = new TableSchemaCompareUpdateDDL(sourceChangeManger, sourceSchemaDDL, targetSchemaDDL, sourceSchemaInfo, targetSchemaInfo);
        alterDDL = tableCompareDDL.getTableSchemaAlterDDL();
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return alterDDL;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) SchemaChangeManager(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeManager) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) TableSchemaCompareUpdateDDL(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareUpdateDDL)

Example 8 with SchemaDDL

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL in project cubrid-manager by CUBRID.

the class ERSchemaEditor method compareDDL2DB.

public void compareDDL2DB() {
    DatabaseInfo info = database.getDatabaseInfo();
    if (info == null) {
        CommonUITool.openErrorBox(Messages.errNoDatabase);
        return;
    }
    if (!info.isLogined()) {
        CommonUITool.openErrorBox(Messages.msgDBNotLogin);
        return;
    }
    ServerInfo serverInfo = info.getServerInfo();
    if (serverInfo != null && !serverInfo.isConnected()) {
        CommonUITool.openErrorBox(Messages.msgDBNotLogin);
        return;
    }
    Map<String, SchemaInfo> schemaInfos = erSchema.getAllSchemaInfo();
    Map<String, TableSchema> tableSchemas = new HashMap<String, TableSchema>();
    WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info.getDbName(), info.getServerInfo());
    ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
    wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
    SchemaDDL ddl = new SchemaDDL(null, wrappedDatabaseInfo);
    for (String tableName : schemaInfos.keySet()) {
        SchemaInfo schemaInfo = schemaInfos.get(tableName);
        if (schemaInfo == null || !tableName.equals(schemaInfo.getClassname())) {
            continue;
        }
        // now do not support view table
        String strDDL = ddl.getSchemaDDL(schemaInfo, true, true);
        TableSchema tableSchema = new TableSchema(tableName, "");
        tableSchema.setSchemaInfo(strDDL);
        tableSchemas.put(tableSchema.getName(), tableSchema);
    }
    wrappedDatabaseInfo.addTableSchemas(tableSchemas);
    compareTableSchemas(getEditorInput().getName(), tableSchemas, schemaInfos);
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) ERVirtualDatabaseInfo(com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) HashMap(java.util.HashMap) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 9 with SchemaDDL

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL in project cubrid-manager by CUBRID.

the class TableEditorPart method init.

public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    TableEditorInput tableInfoEditorInput = (TableEditorInput) input;
    this.database = tableInfoEditorInput.getDatabase();
    this.editedTableNode = tableInfoEditorInput.getEditedTableNode();
    this.isNewTableFlag = tableInfoEditorInput.isNewTableFlag();
    this.dbUserList = tableInfoEditorInput.getDbUserList();
    this.showDefaultType = tableInfoEditorInput.getType();
    this.collationList = tableInfoEditorInput.getCollationList();
    if (collationList != null) {
        Collation emptyCollation = new Collation();
        emptyCollation.setCharset("");
        emptyCollation.setName("");
        collationList.add(0, emptyCollation);
    }
    this.oldSchemaInfo = tableInfoEditorInput.getSchemaInfo();
    this.supportCharset = CompatibleUtil.isSupportCreateDBByCharset(database.getDatabaseInfo());
    if (isNewTableFlag) {
        newSchemaInfo = new SchemaInfo();
        //$NON-NLS-1$
        newSchemaInfo.setClassname("");
        newSchemaInfo.setOwner(database.getUserName());
        newSchemaInfo.setDbname(database.getName());
        newSchemaInfo.setType(Messages.userSchema);
        newSchemaInfo.setVirtual(Messages.schemaTypeClass);
        if (database.getDatabaseInfo() != null) {
            newSchemaInfo.setCollation(database.getDatabaseInfo().getCollation());
        }
    } else {
        newSchemaInfo = null;
        if (tableInfoEditorInput.getSchemaInfo() != null) {
            newSchemaInfo = tableInfoEditorInput.getSchemaInfo().clone();
            originalConstraints.addAll(newSchemaInfo.getConstraints());
        }
    }
    if (supportCharset) {
        columnProperites = new String[] { IAttributeColumn.COL_EMPTY, IAttributeColumn.COL_FLAG, IAttributeColumn.COL_NAME, IAttributeColumn.COL_DATATYPE, IAttributeColumn.COL_DEFAULT, IAttributeColumn.COL_AUTO_INCREMENT, IAttributeColumn.COL_NOT_NULL, IAttributeColumn.COL_PK, IAttributeColumn.COL_UK, IAttributeColumn.COL_SHARED, IAttributeColumn.COL_COLLATION, IAttributeColumn.COL_MEMO };
    } else {
        columnProperites = new String[] { IAttributeColumn.COL_EMPTY, IAttributeColumn.COL_FLAG, IAttributeColumn.COL_NAME, IAttributeColumn.COL_DATATYPE, IAttributeColumn.COL_DEFAULT, IAttributeColumn.COL_AUTO_INCREMENT, IAttributeColumn.COL_NOT_NULL, IAttributeColumn.COL_PK, IAttributeColumn.COL_UK, IAttributeColumn.COL_SHARED, IAttributeColumn.COL_MEMO };
    }
    Connection conn = null;
    try {
        conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        IDatabaseSpec dbSpec = database.getDatabaseInfo();
        isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
        database.getDatabaseInfo().setSupportTableComment(isSupportTableComment);
        if (isSupportTableComment && !isNewTableFlag && newSchemaInfo != null) {
            Map<String, SchemaComment> map = SchemaCommentHandler.loadDescription(dbSpec, conn, newSchemaInfo.getClassname());
            for (DBAttribute attr : newSchemaInfo.getAttributes()) {
                SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), attr.getName());
                if (schemaComment != null) {
                    attr.setDescription(schemaComment.getDescription());
                }
            }
            // get description for index
            for (Constraint cons : newSchemaInfo.getConstraints()) {
                if (CompatibleUtil.isCommentSupports(dbSpec)) {
                    String indexName = cons.getName();
                    SchemaComment indexComment = SchemaCommentHandler.loadObjectDescription(dbSpec, conn, indexName, CommentType.INDEX);
                    if (indexComment != null) {
                        cons.setDescription(indexComment.getDescription());
                    }
                }
            }
            SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), null);
            if (schemaComment != null) {
                newSchemaInfo.setDescription(schemaComment.getDescription());
            }
        }
    } catch (SQLException e) {
        LOGGER.error("", e);
    } catch (Exception e) {
        LOGGER.error("", e);
    } finally {
        QueryUtil.freeQuery(conn);
    }
    schemaChangeMgr = new SchemaChangeManager(database.getDatabaseInfo(), isNewTableFlag);
    schemaDDL = new SchemaDDL(schemaChangeMgr, database.getDatabaseInfo());
    if (database != null) {
        isSupportChange = CompatibleUtil.isSupportChangeColumn(database.getDatabaseInfo());
    }
    setSite(site);
    setInput(input);
    setPartName(input.getName());
    setTitleToolTip(input.getName());
    setTitleImage(CommonUIPlugin.getImage("icons/navigator/schema_table.png"));
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) SQLException(java.sql.SQLException) SchemaChangeManager(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeManager) Connection(java.sql.Connection) Collation(com.cubrid.cubridmanager.core.cubrid.database.model.Collation) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 10 with SchemaDDL

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL in project cubrid-manager by CUBRID.

the class ExportSQLDataTask method execute.

public void execute() {
    DatabaseInfo databaseInfo = erSchema.getCubridDatabase().getDatabaseInfo();
    SchemaDDL schemaDDL = new SchemaDDL(new SchemaChangeManager(databaseInfo, true), databaseInfo);
    Map<String, SchemaInfo> tables = erSchema.getAllSchemaInfo();
    StringBuilder text = new StringBuilder("");
    for (SchemaInfo table : tables.values()) {
        String sql = schemaDDL.getSchemaDDL(table, isContainIndex);
        text.append(sql);
        text.append("\n");
    }
    isSuccess = FileUtil.writeToFile(fileFullName, text.toString(), fileCharset, false);
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SchemaChangeManager(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeManager) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)10 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)5 WrappedDatabaseInfo (com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo)4 SchemaChangeManager (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeManager)4 HashMap (java.util.HashMap)4 TableSchema (com.cubrid.common.ui.compare.schema.model.TableSchema)3 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 PartInitException (org.eclipse.ui.PartInitException)2 Constraint (com.cubrid.common.core.common.model.Constraint)1 IDatabaseSpec (com.cubrid.common.core.common.model.IDatabaseSpec)1 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)1 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)1 TableSchemaCompareModel (com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)1 TableSchemaCompareUpdateDDL (com.cubrid.common.ui.compare.schema.model.TableSchemaCompareUpdateDDL)1 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)1 ERVirtualDatabaseInfo (com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo)1