/** * Adds a new attribute to this entity. * * @throws IllegalArgumentException if Attribute has no name or there is an existing attribute * with the same name * @throws IllegalArgumentException if a relationship has the same name as this attribute * @since 3.0 */ public void addAttribute(DbAttribute attr) { super.addAttribute(attr); this.dbAttributeAdded(new AttributeEvent(this, attr, this, MapEvent.ADD)); }
/** * Updates attribute "primaryKey" property. */ public void setPrimaryKey(boolean primaryKey) { if (this.primaryKey != primaryKey) { this.primaryKey = primaryKey; Entity e = this.getEntity(); if (e instanceof DbAttributeListener) { ((DbAttributeListener) e).dbAttributeChanged(new AttributeEvent(this, this, e)); } } }
/** * Overrides super to fire an AttributeEvent. */ public void addAttribute(Attribute attr) { super.addAttribute(attr); this.dbAttributeAdded(new AttributeEvent(this, attr, this, MapEvent.ADD)); }
public void clearAttributes() { super.clearAttributes(); // post dummy event for no specific attribute this.dbAttributeRemoved(new AttributeEvent(this, null, this, MapEvent.REMOVE)); }
@Override public void clearAttributes() { super.clearAttributes(); // post dummy event for no specific attribute this.dbAttributeRemoved(new AttributeEvent(this, null, this, MapEvent.REMOVE)); }
/** * Updates attribute "generated" property. * * @since 1.2 */ public void setGenerated(boolean generated) { if (this.generated != generated) { this.generated = generated; Entity e = this.getEntity(); if (e instanceof DbAttributeListener) { ((DbAttributeListener) e).dbAttributeChanged(new AttributeEvent(this, this, e)); } } }
/** * Updates attribute "primaryKey" property. */ public void setPrimaryKey(boolean primaryKey) { if (this.primaryKey != primaryKey) { this.primaryKey = primaryKey; Entity e = this.getEntity(); if (e instanceof DbAttributeListener) { ((DbAttributeListener) e).dbAttributeChanged(new AttributeEvent( this, this, e)); } } }
/** * Updates attribute "generated" property. * * @since 1.2 */ public void setGenerated(boolean generated) { if (this.generated != generated) { this.generated = generated; Entity e = this.getEntity(); if (e instanceof DbAttributeListener) { ((DbAttributeListener) e).dbAttributeChanged(new AttributeEvent( this, this, e)); } } } }
/** * Fires events when an obj attribute was added */ static void fireObjAttributeEvent(Object src, ProjectController mediator, DataMap map, ObjEntity objEntity, ObjAttribute attr) { mediator.fireObjAttributeEvent(new AttributeEvent(src, attr, objEntity, MapEvent.ADD)); DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode(); AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, objEntity, map, domain); mediator.fireObjAttributeDisplayEvent(ade); }
/** * Fires events when a db attribute was added */ static void fireDbAttributeEvent(Object src, ProjectController mediator, DataMap map, DbEntity dbEntity, DbAttribute attr) { mediator.fireDbAttributeEvent(new AttributeEvent(src, attr, dbEntity, MapEvent.ADD)); AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, dbEntity, map, (DataChannelDescriptor) mediator.getProject().getRootNode()); mediator.fireDbAttributeDisplayEvent(ade); }
@Override public void execute(MergerContext mergerContext) { DbEntity e = getEntity(); for (DbAttribute attr : e.getAttributes()) { boolean wasPrimaryKey = attr.isPrimaryKey(); boolean willBePrimaryKey = primaryKeyNewAttributeNames.contains(attr .getName() .toUpperCase()); if (wasPrimaryKey != willBePrimaryKey) { attr.setPrimaryKey(willBePrimaryKey); e.dbAttributeChanged(new AttributeEvent(this, attr, e)); mergerContext.getDelegate().dbAttributeModified(attr); } } } }
/** * Removes attribute from the entity, removes any relationship joins * containing this attribute. Does nothing if the attribute name is not * found. * * @see org.apache.cayenne.map.Entity#removeAttribute(String) */ @Override public void removeAttribute(String attrName) { Attribute attr = getAttribute(attrName); if (attr == null) { return; } DataMap map = getDataMap(); if (map != null) { for (DbEntity ent : map.getDbEntities()) { for (DbRelationship relationship : ent.getRelationships()) { Iterator<DbJoin> joins = relationship.getJoins().iterator(); while (joins.hasNext()) { DbJoin join = joins.next(); if (join.getSource() == attr || join.getTarget() == attr) { joins.remove(); } } } } } super.removeAttribute(attrName); this.dbAttributeRemoved(new AttributeEvent(this, attr, this, MapEvent.REMOVE)); }
public void removeDbAttributes(DataMap dataMap, DbEntity entity, DbAttribute[] attribs) { ProjectController mediator = getProjectController(); for (DbAttribute attrib : attribs) { entity.removeAttribute(attrib.getName()); AttributeEvent e = new AttributeEvent( Application.getFrame(), attrib, entity, MapEvent.REMOVE); mediator.fireDbAttributeEvent(e); } ProjectUtil.cleanObjMappings(dataMap); }
if(oldNameEmbeddableToNewName.size()>0 && oldNameEmbeddableToNewName.containsKey(attribute.getType())){ attribute.setType(oldNameEmbeddableToNewName.get(attribute.getType())); AttributeEvent ev = new AttributeEvent(this, attribute, entity); mediator.fireObjAttributeEvent(ev);
public void removeObjAttributes(ObjEntity entity, ObjAttribute[] attribs) { ProjectController mediator = getProjectController(); for (ObjAttribute attrib : attribs) { entity.removeAttribute(attrib.getName()); AttributeEvent e = new AttributeEvent( Application.getFrame(), attrib, entity, MapEvent.REMOVE); mediator.fireObjAttributeEvent(e); Collection<ObjEntity> objEntities = ProjectUtil.getCollectionOfChildren((ObjEntity) e.getEntity()); for (ObjEntity objEntity: objEntities) { objEntity.removeAttributeOverride(e.getAttribute().getName()); } } }
private void removeObjAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, ObjAttribute[] objAttrs) { if (objAttrs != null && objAttrs.length > 0) { if ((objAttrs.length == 1 && dialog.shouldDelete("DbAttribute", objAttrs[0].getName())) || (objAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) { ObjEntity entity = mediator.getCurrentObjEntity(); application.getUndoManager() .addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs)); for (ObjAttribute attrib : objAttrs) { entity.removeAttribute(attrib.getName()); AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE); mediator.fireObjAttributeEvent(e); } ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap()); } } }
private void removeDbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, DbAttribute[] dbAttrs) { if (dbAttrs != null && dbAttrs.length > 0) { if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0].getName())) || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) { DbEntity entity = mediator.getCurrentDbEntity(); application.getUndoManager() .addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs)); for (DbAttribute attrib : dbAttrs) { entity.removeAttribute(attrib.getName()); AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE); mediator.fireDbAttributeEvent(e); } ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap()); } } }
AttributeEvent e = new AttributeEvent(eventSource, attr, entity);
@Override public void setUpdatedValueAt(Object value, int row, int column) { ObjAttributeWrapper attribute = getAttribute(row); attribute.resetEdits(); AttributeEvent event = new AttributeEvent(eventSource, attribute.getValue(), entity); if (column == OBJ_ATTRIBUTE) { event.setOldName(attribute.getName()); setObjAttribute(attribute, value); fireTableCellUpdated(row, column); } else if (column == OBJ_ATTRIBUTE_TYPE) { setObjAttributeType(attribute, value); fireTableCellUpdated(row, column); } else if (column == LOCKING) { setColumnLocking(attribute, value); fireTableCellUpdated(row, column); } else { if (column == DB_ATTRIBUTE) { setDbAttribute(attribute, value); } fireTableRowsUpdated(row, row); } mediator.fireObjAttributeEvent(event); }
private void changeAttributeObject() { if (attributeSaved instanceof EmbeddedAttribute && embeddableModel.isAttributeOverrideChange()) { Map<String, String> overrides = ((EmbeddedAttribute) attributeSaved).getAttributeOverrides(); Map<String, String> currentOverrAttr = getCurrentOverrideAttribute(); compareAndSetOverrideInEmbeddedAttribute(attributeSaved, overrides, currentOverrAttr); } if (attributeSaved instanceof EmbeddedAttribute) { attributeSaved.setDbAttributePath(null); model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3); } model.getEntity().removeAttribute(attribute.getName()); model.getEntity().addAttribute(attributeSaved); mediator.fireObjEntityEvent(new EntityEvent(this, model.getEntity(), MapEvent.CHANGE)); EntityDisplayEvent event = new EntityDisplayEvent(this, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()); mediator.fireObjEntityDisplayEvent(event); mediator.fireObjAttributeEvent(new AttributeEvent(this, attributeSaved, model.getEntity(), MapEvent.CHANGE)); AttributeDisplayEvent eventAttr = new AttributeDisplayEvent(this, attributeSaved, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator .getProject().getRootNode()); mediator.fireObjAttributeDisplayEvent(eventAttr); }