use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class MergerFactoryIT method attr.
private static DbAttribute attr(DbEntity dbEntity, String name, int type, boolean mandatory, boolean primaryKey) {
DbAttribute column1 = new DbAttribute(name, type, dbEntity);
column1.setMandatory(mandatory);
column1.setPrimaryKey(primaryKey);
dbEntity.addAttribute(column1);
return column1;
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class ObjAttributeTableModel method getValueAt.
public Object getValueAt(int row, int column) {
ObjAttributeWrapper attribute = getAttribute(row);
DbAttribute dbAttribute = attribute.getDbAttribute();
switch(column) {
case INHERITED:
return attribute.isInherited();
case OBJ_ATTRIBUTE:
return attribute.getName();
case OBJ_ATTRIBUTE_TYPE:
return attribute.getType();
case LOCKING:
return attribute.isUsedForLocking() ? Boolean.TRUE : Boolean.FALSE;
case DB_ATTRIBUTE:
return getDBAttribute(attribute, dbAttribute);
case DB_ATTRIBUTE_TYPE:
return getDBAttributeType(attribute, dbAttribute);
case COMMENT:
return getComment(attribute.getValue());
default:
return null;
}
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class DbAttributeTableModel method setUpdatedValueAt.
public void setUpdatedValueAt(Object newVal, int row, int col) {
DbAttribute attr = getAttribute(row);
if (attr == null) {
return;
}
AttributeEvent e = new AttributeEvent(eventSource, attr, entity);
switch(col) {
case DB_ATTRIBUTE_NAME:
e.setOldName(attr.getName());
attr.setName((String) newVal);
attr.getEntity().dbAttributeChanged(e);
fireTableCellUpdated(row, col);
break;
case DB_ATTRIBUTE_TYPE:
setAttributeType((String) newVal, attr);
break;
case DB_ATTRIBUTE_PRIMARY_KEY:
if (!setPrimaryKey(((Boolean) newVal), attr, row)) {
return;
}
break;
case DB_ATTRIBUTE_SCALE:
setScale((String) newVal, attr);
break;
case DB_ATTRIBUTE_MANDATORY:
setMandatory((Boolean) newVal, attr);
break;
case DB_ATTRIBUTE_MAX:
setMaxLength((String) newVal, attr);
break;
case DB_ATTRIBUTE_COMMENT:
setComment((String) newVal, attr);
break;
}
mediator.fireDbAttributeEvent(e);
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class BoxCellRenderer method setUpdatedValueAt.
@Override
public void setUpdatedValueAt(Object value, int row, int col) {
EmbeddableAttribute attribute = getEmbeddableAttribute(row);
if (col == DB_ATTRIBUTE) {
attribute.setDbAttributeName(value != null ? value.toString() : null);
fireTableCellUpdated(row, col);
this.isAttributeOverrideChange = true;
((ObjAttributeInfoDialogView) ((ObjAttributeInfoDialog) eventSource).getView()).getSaveButton().setEnabled(true);
if (value != null) {
DbEntity currentEnt = ((ObjEntity) attr.getEntity()).getDbEntity();
if (currentEnt != null) {
DbAttribute dbAttr = (DbAttribute) currentEnt.getAttribute(value.toString());
if (dbAttr != null) {
fireTableCellUpdated(DB_ATTRIBUTE_TYPE, col);
}
}
}
fireTableRowsUpdated(row, row);
}
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class CreateAttributeAction method performAction.
/**
* Creates ObjAttribute, DbAttribute depending on context.
*/
@Override
public void performAction(ActionEvent e) {
ProjectController mediator = getProjectController();
if (getProjectController().getCurrentEmbeddable() != null) {
Embeddable embeddable = mediator.getCurrentEmbeddable();
EmbeddableAttribute attr = new EmbeddableAttribute();
attr.setName(NameBuilder.builder(attr, embeddable).name());
createEmbAttribute(embeddable, attr);
application.getUndoManager().addEdit(new CreateEmbAttributeUndoableEdit(embeddable, new EmbeddableAttribute[] { attr }));
}
if (getProjectController().getCurrentObjEntity() != null) {
ObjEntity objEntity = mediator.getCurrentObjEntity();
ObjAttribute attr = new ObjAttribute();
attr.setName(NameBuilder.builder(attr, objEntity).name());
createObjAttribute(mediator.getCurrentDataMap(), objEntity, attr);
application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), objEntity, attr));
} else if (getProjectController().getCurrentDbEntity() != null) {
DbEntity dbEntity = getProjectController().getCurrentDbEntity();
DbAttribute attr = new DbAttribute();
attr.setName(NameBuilder.builder(attr, dbEntity).name());
attr.setType(TypesMapping.NOT_DEFINED);
attr.setEntity(dbEntity);
createDbAttribute(mediator.getCurrentDataMap(), dbEntity, attr);
application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), dbEntity, attr));
}
}
Aggregations