use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class ERTable method updateSchemaInfoMode.
/**
* Update the schemaInfo object in the <code>ERTable</code>, and update the
* Attribute in all of the <code>ERTableColumn</code>
*
* @param schemaInfo
*/
public void updateSchemaInfoMode(SchemaInfo schemaInfo) {
this.schemaInfo = schemaInfo;
for (ERTableColumn column : columns) {
DBAttribute newAttr = schemaInfo.getDBAttributeByName(column.getName(), false);
if (newAttr == null) {
LOGGER.warn("Cannot update the column model : " + column.getName());
continue;
}
column.setAttr(newAttr);
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class ERAttributeLabelProvider method getColumnImage.
public Image getColumnImage(Object element, int columnIndex) {
if (element == null) {
return null;
}
ERTableColumn erColumn = (ERTableColumn) element;
DBAttribute dbAttribute = erColumn.getAttr();
if (dbAttribute == null || dbAttribute.getInherit() == null || schema == null) {
return null;
}
String property = editorAdaptor.getColumnProperty(columnIndex);
if (StringUtil.isEqual(property, IAttributeColumn.COL_PK)) {
String attrName = dbAttribute.getName();
Constraint pk = schema.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
return PK_IMAGE;
}
return editableMode ? UNCHECK_IMAGE : null;
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL)) {
String attrName = dbAttribute.getName();
Constraint pk = schema.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
return DISABLED_CHECK_IMAGE;
}
if (dbAttribute.isNotNull()) {
return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
} else {
return editableMode ? UNCHECK_IMAGE : null;
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
String attrName = dbAttribute.getName();
Constraint pk = schema.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
return DISABLED_CHECK_IMAGE;
}
if (dbAttribute.isUnique() && schema.isAttributeUnique(dbAttribute, supers)) {
return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
} else {
return editableMode ? UNCHECK_IMAGE : DISABLED_UNCHECK_IMAGE;
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_SHARED)) {
if (dbAttribute.isShared()) {
return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
} else {
return editableMode ? UNCHECK_IMAGE : null;
}
}
return null;
}
use of com.cubrid.common.core.common.model.DBAttribute 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.DBAttribute in project cubrid-manager by CUBRID.
the class WorkbenchContrItem method getStmtSQL.
/**
* Create select statement SQL
*
* @param schemaNode DefaultSchemaNode
* @return String
*/
protected String getStmtSQL(DefaultSchemaNode schemaNode) {
// FIXME move this logic to core module
if (schemaNode == null) {
return "";
}
CubridDatabase db = schemaNode.getDatabase();
DatabaseInfo dbInfo = db.getDatabaseInfo();
GetAllAttrTask task = new GetAllAttrTask(dbInfo);
task.setClassName(schemaNode.getName());
task.getAttrList();
if (task.getErrorMsg() != null) {
return "";
}
List<DBAttribute> allAttrList = task.getAllAttrList();
return SQLGenerateUtils.getSelectSQLWithLimit(schemaNode.getName(), allAttrList);
}
use of com.cubrid.common.core.common.model.DBAttribute 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);
}
Aggregations