Search in sources :

Example 6 with ModelVetoException

use of com.sun.jdo.api.persistence.model.ModelVetoException in project Payara by payara.

the class RelationshipElementImpl method changeInverseRelationship.

/**
 * Changes the inverse relationship element for this relationship element.
 * This method is invoked for both sides from
 * {@link RelationshipElement#setInverseRelationship} and should handle the
 * vetoable change events, property change events, and setting the internal
 * variable.
 * @param inverseRelationship - a relationship element to be used as the
 * inverse for this relationship element or <code>null</code> if this
 * relationship element does not participate in a two-way relationship.
 * @exception ModelException if impossible
 */
public void changeInverseRelationship(RelationshipElement inverseRelationship) throws ModelException {
    String newName = ((inverseRelationship != null) ? inverseRelationship.getName() : null);
    String oldName = getInverseRelationshipName();
    try {
        fireVetoableChange(PROP_INVERSE_FIELD, oldName, newName);
        _inverseRelationshipName = newName;
        firePropertyChange(PROP_INVERSE_FIELD, oldName, newName);
    } catch (PropertyVetoException e) {
        throw new ModelVetoException(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelVetoException(com.sun.jdo.api.persistence.model.ModelVetoException)

Example 7 with ModelVetoException

use of com.sun.jdo.api.persistence.model.ModelVetoException in project Payara by payara.

the class MappingReferenceKeyElementImpl method removeColumnPairs.

/**
 * Remove some column pairs from the holder.  This method can be used to
 * remove pairs by name when they cannot be resolved to actual pairs.
 * @param pairNames the relative names of the column pairs to remove
 * @throws ModelException if impossible
 */
public void removeColumnPairs(ArrayList pairNames) throws ModelException {
    ArrayList refKey = getReferencingKey();
    ArrayList key = getTable().getKey();
    int i, count = ((pairNames != null) ? pairNames.size() : 0);
    for (i = 0; i < count; i++) {
        String pairName = (String) pairNames.get(i);
        int index = getIndexOfColumnPair(pairName);
        if (pairName != null) {
            try {
                Object remove1 = null, remove2 = null;
                fireVetoableChange(PROP_KEY_COLUMNS, null, null);
                remove1 = key.remove(index);
                remove2 = refKey.remove(index);
                if ((remove1 == null) || (remove2 == null)) {
                    // if only 1 failed, put the other one back
                    if (remove1 != null)
                        key.add(index, remove1);
                    else if (remove2 != null)
                        refKey.add(index, remove2);
                    throw new ModelException(I18NHelper.getMessage(getMessages(), // NOI18N
                    "mapping.element.element_not_removed", pairName));
                }
                firePropertyChange(PROP_KEY_COLUMNS, null, null);
            } catch (PropertyVetoException e) {
                throw new ModelVetoException(e);
            }
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelException(com.sun.jdo.api.persistence.model.ModelException) ModelVetoException(com.sun.jdo.api.persistence.model.ModelVetoException) ArrayList(java.util.ArrayList)

Example 8 with ModelVetoException

use of com.sun.jdo.api.persistence.model.ModelVetoException in project Payara by payara.

the class MappingReferenceKeyElementImpl method addKeyColumn.

/**
 * Adds a column to the list of key columns in this referencing key.
 * This method is only called privately from addColumnPairs and assumes
 * that the column is not <code>null</code>.
 * @param column column element to be added
 * @exception ModelException if impossible
 */
private void addKeyColumn(ColumnElement column) throws ModelException {
    ArrayList referencingKey = getReferencingKey();
    String columnName = NameUtil.getRelativeMemberName(column.getName().getFullName());
    try {
        fireVetoableChange(PROP_KEY_COLUMNS, null, null);
        referencingKey.add(columnName);
        firePropertyChange(PROP_KEY_COLUMNS, null, null);
    } catch (PropertyVetoException e) {
        throw new ModelVetoException(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelVetoException(com.sun.jdo.api.persistence.model.ModelVetoException) ArrayList(java.util.ArrayList)

Example 9 with ModelVetoException

use of com.sun.jdo.api.persistence.model.ModelVetoException in project Payara by payara.

the class MappingRelationshipElementImpl method addAssociatedColumn.

/**
 * Adds a column to the list of associated columns mapped by this mapping
 * field.  Call this method instead of <code>addColumn</code> when mapping
 * join tables.  This method is used to map between the join table column
 * and the foreign table column, while <code>addLocalColumn</code> is used
 * to map between the local table and the join table.
 * @param column column pair element to be added to the mapping
 * @exception ModelException if impossible
 * @see MappingFieldElement#addColumn
 * @see #addLocalColumn
 */
public void addAssociatedColumn(ColumnPairElement column) throws ModelException {
    if (column != null) {
        ArrayList columns = getAssociatedColumns();
        String columnName = NameUtil.getRelativeMemberName(column.getName().getFullName());
        // double check that this pair is not already in the column list
        if (!columns.contains(columnName)) {
            try {
                fireVetoableChange(PROP_ASSOCIATED_COLUMNS, null, null);
                columns.add(columnName);
                firePropertyChange(PROP_ASSOCIATED_COLUMNS, null, null);
                // sync up runtime's object list too
                _associatedColumnObjects = null;
            } catch (PropertyVetoException e) {
                throw new ModelVetoException(e);
            }
        } else {
            throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.column.column_defined", // NOI18N
            columnName));
        }
    } else {
        throw new ModelException(I18NHelper.getMessage(getMessages(), // NOI18N
        "mapping.element.null_argument"));
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelException(com.sun.jdo.api.persistence.model.ModelException) ModelVetoException(com.sun.jdo.api.persistence.model.ModelVetoException)

Example 10 with ModelVetoException

use of com.sun.jdo.api.persistence.model.ModelVetoException in project Payara by payara.

the class MappingTableElementImpl method addKeyColumnInternal.

/**
 * Adds a column to the primary key of columns in this mapping table.
 * This method is used internally to manipulate primary key columns
 * that have passed the null and duplicate tests in addKeyColumn and
 * secondary table key columns when pairs are being set up and ignoring
 * duplicates is done at the pair level.
 * @param column column element to be added
 * @exception ModelException if impossible
 */
protected void addKeyColumnInternal(ColumnElement column) throws ModelException {
    ArrayList key = getKey();
    String columnName = NameUtil.getRelativeMemberName(column.getName().getFullName());
    try {
        fireVetoableChange(PROP_KEY_COLUMNS, null, null);
        key.add(columnName);
        firePropertyChange(PROP_KEY_COLUMNS, null, null);
        // sync up runtime's object list too
        // @olsen: rather clear objects instead of maintaining them
        // getKeyObjects().add(column);
        _keyObjects = null;
    } catch (PropertyVetoException e) {
        throw new ModelVetoException(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelVetoException(com.sun.jdo.api.persistence.model.ModelVetoException)

Aggregations

ModelVetoException (com.sun.jdo.api.persistence.model.ModelVetoException)26 PropertyVetoException (java.beans.PropertyVetoException)24 ModelException (com.sun.jdo.api.persistence.model.ModelException)4 ArrayList (java.util.ArrayList)2 MappingTableElement (com.sun.jdo.api.persistence.model.mapping.MappingTableElement)1