Search in sources :

Example 51 with DbAttribute

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;
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 52 with DbAttribute

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;
    }
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) ObjAttributeWrapper(org.apache.cayenne.modeler.editor.wrapper.ObjAttributeWrapper)

Example 53 with DbAttribute

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);
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 54 with DbAttribute

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);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute)

Example 55 with DbAttribute

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));
    }
}
Also used : CreateEmbAttributeUndoableEdit(org.apache.cayenne.modeler.undo.CreateEmbAttributeUndoableEdit) ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbEntity(org.apache.cayenne.map.DbEntity) CreateAttributeUndoableEdit(org.apache.cayenne.modeler.undo.CreateAttributeUndoableEdit) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) Embeddable(org.apache.cayenne.map.Embeddable)

Aggregations

DbAttribute (org.apache.cayenne.map.DbAttribute)194 DbEntity (org.apache.cayenne.map.DbEntity)109 Test (org.junit.Test)67 ObjEntity (org.apache.cayenne.map.ObjEntity)36 DbRelationship (org.apache.cayenne.map.DbRelationship)35 ObjAttribute (org.apache.cayenne.map.ObjAttribute)32 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)21 DbJoin (org.apache.cayenne.map.DbJoin)18 HashMap (java.util.HashMap)16 ObjRelationship (org.apache.cayenne.map.ObjRelationship)16 ArrayList (java.util.ArrayList)14 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)12 DataMap (org.apache.cayenne.map.DataMap)11 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)10 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)10 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)10 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)10 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)10 ObjectId (org.apache.cayenne.ObjectId)9 Expression (org.apache.cayenne.exp.Expression)8