use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class CubridTableParser method buildERTables.
/**
* Build the ER tables node information and its relationship. If its
* relationship tables are not added, donot build these relationship for
* efficiency. <br>
* This method only build and add , donot fire listener for UI updating
*
* @param schemaInfos Collection<schemaInfo> should be built and added
* tables
* @param successTables be built successfully
* @param startX startX > 0. if it is less than 0, the param will be
* omitted.
* @param startY
* @param isPartitionLayout if it is true, omit the startX and startY. These
* table will be arranged at the bottom of the canvas.
* @throws Exception If throw exception, then all of input table donot be
* built
*/
public void buildERTables(Collection<SchemaInfo> schemaInfos, int startX, int startY, boolean isPartitionLayout) {
if (schemaInfos == null || schemaInfos.size() == 0) {
return;
}
for (SchemaInfo schemaInfo : schemaInfos) {
if (erSchema.getTable(schemaInfo.getClassname()) != null) {
existedTableNames.add(schemaInfo.getClassname());
continue;
}
this.schemaInfos.put(schemaInfo.getClassname(), schemaInfo);
}
Set<String> tables = this.schemaInfos.keySet();
for (String name : tables) {
SchemaInfo schemaInfo = this.schemaInfos.get(name);
ERTable erTable = null;
try {
if (erSchema.getTable(schemaInfo.getClassname()) != null) {
// the table has been built by referenced table
erTable = erSchema.getTable(schemaInfo.getClassname());
} else {
erTable = new ERTable(schemaInfo, erSchema);
boolean success = erSchema.addTable(erTable);
if (success && !successTables.contains(erTable)) {
successTables.add(erTable);
}
buildERTable(erTable, schemaInfo);
}
if (isPartitionLayout) {
erTable.setNeedPartitionLayout(true);
} else if (startX > -1 && startY > -1) {
erTable.setBounds(new Rectangle(startX, startY, erTable.getMinWidth(), erTable.getMinHeight()));
startY += erTable.getMinHeight() + DEFAULT_VERTICAL_DISTANCE;
}
} catch (Exception e) {
failedTables.put(name, e);
erSchema.deleteTableAndFire(erTable);
successTables.remove(erTable);
LOGGER.warn(e.getMessage());
}
}
this.schemaInfos.clear();
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class CubridTableParser method addFKShip.
public void addFKShip(ERTable erTable, SchemaInfo schemaInfo, Constraint fkConstaint) throws Exception {
String referencedTableName = getReferencedTableName(fkConstaint);
SchemaInfo referencedTable = getReferencedTable(fkConstaint);
List<String> referenceNames = getReferenceColumns(fkConstaint);
List<String> referredPkColumnNames = getReferredColumns(schemaInfo, fkConstaint);
boolean isSelfRef = false;
if (referencedTable == null) {
// If the referenced Table do not be added to the ERShema. Do not
// load it and do not build the relationship and delete the
// constraint
schemaInfo.removeFKConstraint(fkConstaint);
addEle2RemovedFKConstraints(schemaInfo.getClassname(), fkConstaint);
return;
}
if (StringUtil.isEqualNotIgnoreNull(referencedTableName, erTable.getName())) {
// self reference FK
isSelfRef = true;
}
if (referenceNames.size() != referredPkColumnNames.size()) {
throw new ERException(Messages.bind(Messages.errFKColumnMatch, new String[] { schemaInfo.getClassname(), fkConstaint.getName() }));
}
ERTable referencedT = erSchema.getTable(referencedTable.getClassname());
boolean needBuildRefedTable = false;
if (referencedT == null && !isSelfRef) {
referencedT = new ERTable(referencedTable, erSchema);
needBuildRefedTable = true;
} else {
// the referenceTable has been built, do not build again.
}
if (isSelfRef) {
erTable.setHasSelfFKRef(true);
return;
}
Relationship ship = new Relationship(fkConstaint.getName(), erTable, referencedT);
for (int i = 0; i < referenceNames.size(); i++) {
ship.addRelation(referenceNames.get(i), referredPkColumnNames.get(i));
}
erTable.addForeignKeyShipAndFire(ship);
if (needBuildRefedTable) {
buildERTable(referencedT, referencedTable);
boolean success = erSchema.addTable(referencedT);
if (success && !successTables.contains(referencedT)) {
successTables.add(referencedT);
}
}
referencedT.FireTargeted(ship);
return;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class SchemaContainerEditPolicy method getCreateCommand.
@Override
protected Command getCreateCommand(CreateRequest request) {
Object newObject = request.getNewObject();
if (!(newObject instanceof ERTable)) {
return null;
}
Point location = request.getLocation();
SchemaDiagramPart schemaPart = (SchemaDiagramPart) getHost();
ERSchema erSchema = schemaPart.getSchema();
ERTable erTable = (ERTable) newObject;
ERSchemaEditor editor = schemaPart.getEditor();
int offsetX = 0;
int offsetY = 0;
if (editor != null) {
offsetX = editor.getHorizontalScrollWidth();
offsetY = editor.getVerticalScrollHeight();
}
erTable.setBounds(new Rectangle(location.x + offsetX, location.y + offsetY, erTable.getMinWidth(), erTable.getMinHeight()));
AddTableCommand addTableCommand = new AddTableCommand();
addTableCommand.setSchema(erSchema);
SchemaInfo schemaInfo = ERTable.createEmptySchemaInfo(erTable.getName(), erTable.getCubridDatabase().getName());
addTableCommand.setTable(erTable, schemaInfo);
return addTableCommand;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ColumnProposalAdvisor method loadProposal.
/**
* Load proposal for table
*
* @param databaseInfo
* @param tableName
* @param proposal
*/
private void loadProposal(final DatabaseInfo databaseInfo, final String tableName, final ColumnProposal proposal) {
Job job = new Job("Load schema information job") {
protected IStatus run(IProgressMonitor monitor) {
LOGGER.info("Load table info in ColumnProposalHandler");
GetSchemaTask getSchemaTask = null;
try {
getSchemaTask = new GetSchemaTask(databaseInfo, tableName, monitor);
getSchemaTask.setNeedCollationInfo(false);
getSchemaTask.execute();
if (getSchemaTask.isSuccess()) {
SchemaInfo schemaInfo = getSchemaTask.getSchema();
if (schemaInfo != null) {
List<ColumnProposalDetailInfo> columnList = new ArrayList<ColumnProposalDetailInfo>();
for (DBAttribute attr : schemaInfo.getAttributes()) {
columnList.add(new ColumnProposalDetailInfo(schemaInfo, attr));
}
proposal.addSchemaInfo(tableName, schemaInfo, columnList);
}
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
getSchemaTask.finish();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class WorkbenchContrItem method openEditorOrView.
/**
* Open and reopen the editor or view part of this cubrid node
*
* @param cubridNode the ICubridNode object
*/
public void openEditorOrView(ICubridNode cubridNode) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
if (cubridNode instanceof ISchemaNode) {
ISchemaNode schemaNode = (ISchemaNode) cubridNode;
if (schemaNode.getDatabase() != null && !schemaNode.getDatabase().isLogined()) {
return;
}
}
//close the editor part that has been open
String editorId = cubridNode.getEditorId();
String viewId = cubridNode.getViewId();
if (editorId != null && editorId.trim().length() > 0) {
IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, editorId);
if (editorPart != null) {
window.getActivePage().closeEditor(editorPart, false);
}
} else if (viewId != null && viewId.trim().length() > 0) {
IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, viewId);
if (viewPart != null) {
window.getActivePage().hideView(viewPart);
}
}
if (editorId != null && editorId.trim().length() > 0) {
try {
//if open the table schema editor,firstly load the schema
if (editorId.equals(SchemaInfoEditorPart.ID) && cubridNode instanceof ISchemaNode) {
CubridDatabase database = ((ISchemaNode) cubridNode).getDatabase();
SchemaInfo newSchema = database.getDatabaseInfo().getSchemaInfo(cubridNode.getName());
if (null == newSchema) {
CommonUITool.openErrorBox(database.getDatabaseInfo().getErrorMessage());
return;
}
}
window.getActivePage().openEditor(cubridNode, editorId, true, IWorkbenchPage.MATCH_ID & IWorkbenchPage.MATCH_INPUT);
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
} else if (viewId != null && viewId.trim().length() > 0) {
try {
window.getActivePage().showView(viewId);
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
}
}
Aggregations