use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class RemoveAttributeAction method removeDbAttributes.
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);
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class DbAttribute method setPrimaryKey.
/**
* 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));
}
}
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class DbEntity method addAttribute.
/**
* 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));
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class DbAttribute method setGenerated.
/**
* 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));
}
}
}
use of org.apache.cayenne.map.event.AttributeEvent in project cayenne by apache.
the class DbEntity method removeAttribute.
/**
* 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));
}
Aggregations