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;
}
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;
}
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);
}
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"));
}
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);
}
Aggregations