Search in sources :

Example 1 with ModelException

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

the class JDOConcreteBean20Generator method generateCMRGetSetBodies.

/**
 * Generate bodies of getters and setters for CMR field
 * @param fieldInfo the field information as FieldInfo instance.
 * @param cmrcleanbodyBuf the StringBuffer to append code for CMR cleanup
 * if necessary.
 */
private void generateCMRGetSetBodies(FieldInfo fieldInfo, StringBuffer cmrcleanbodyBuf) throws IOException {
    RelationshipElement rel = (RelationshipElement) fieldInfo.pfe;
    String otherPC = model.getRelatedClass(rel);
    boolean manySide = model.isCollection(fieldInfo.type);
    if (logger.isLoggable(Logger.FINE)) {
        RelationshipElement otherField = rel.getInverseRelationship(model);
        String otherFieldName = ((otherField != null) ? nameMapper.getEjbFieldForPersistenceField(otherPC, otherField.getName()) : null);
        // NOI18N
        logger.fine("manySide: " + manySide);
        // NOI18N
        logger.fine("Field: " + otherFieldName);
    }
    String otherEJB = nameMapper.getEjbNameForPersistenceClass(otherPC);
    String otherImpl = nameMapper.getConcreteBeanClassForEjbName(otherEJB);
    MessageFormat mformat = null;
    if (manySide) {
        threeParams[0] = fieldInfo.getter;
        threeParams[1] = fieldInfo.name;
        threeParams[2] = otherImpl;
        gbody = CMP20TemplateFormatter.cmrCgformatter.format(threeParams);
        fourParams[0] = otherImpl;
        fourParams[1] = fieldInfo.setter;
        fourParams[2] = fieldInfo.getter;
        fourParams[3] = fieldInfo.name;
        sbody = CMP20TemplateFormatter.cmrCsformatter.format(fourParams);
        mformat = CMP20TemplateFormatter.cmrcdCformatter;
        twoParams[0] = fieldInfo.type;
        twoParams[1] = fieldInfo.name;
        CMP20TemplateFormatter.addPrivateField(CMP20TemplateFormatter.cmrvformatter.format(twoParams), 0, concreteImplWriter);
        oneParam[0] = fieldInfo.name;
        cmrcleanbodyBuf.append(CMP20TemplateFormatter.cleancmrformatter.format(oneParam));
    } else {
        // 1 side
        fourParams[0] = otherPC;
        fourParams[1] = fieldInfo.getter;
        fourParams[2] = fieldInfo.type;
        fourParams[3] = otherImpl;
        gbody = CMP20TemplateFormatter.cmrgformatter.format(fourParams);
        threeParams[0] = otherPC;
        threeParams[1] = otherImpl;
        threeParams[2] = fieldInfo.setter;
        sbody = CMP20TemplateFormatter.cmrsformatter.format(threeParams);
        mformat = CMP20TemplateFormatter.cmrcdformatter;
    }
    if (rel.getDeleteAction() == RelationshipElement.CASCADE_ACTION) {
        twoParams[0] = fieldInfo.getter;
        twoParams[1] = otherImpl;
        cascadeDelete.append(mformat.format(twoParams));
        try {
            // Reset DeleteAction to NONE to suppress it in PM.deletePersistent().
            rel.setDeleteAction(RelationshipElement.NONE_ACTION);
        } catch (ModelException me) {
            logger.log(Logger.SEVERE, I18NHelper.getMessage(messages, "CMG.ModelExceptionOnDeleteAction", // NOI18N
            me));
        }
    }
}
Also used : MessageFormat(java.text.MessageFormat) ModelException(com.sun.jdo.api.persistence.model.ModelException)

Example 2 with ModelException

use of com.sun.jdo.api.persistence.model.ModelException 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 3 with ModelException

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

the class MappingTableElementImpl method removeReference.

/**
 * Removes the referencing key for the supplied table element from list
 * of keys in this mapping table.
 * @param table mapping table element for which to remove referencing keys
 * @exception ModelException if impossible
 */
public void removeReference(MappingTableElement table) throws ModelException {
    if (table != null) {
        Iterator keyIterator = getReferencingKeys().iterator();
        while (keyIterator.hasNext()) {
            MappingReferenceKeyElement nextKey = (MappingReferenceKeyElement) keyIterator.next();
            if (nextKey.getTable().equals(table)) {
                try {
                    fireVetoableChange(PROP_REFERENCING_KEYS, null, null);
                    keyIterator.remove();
                    firePropertyChange(PROP_REFERENCING_KEYS, null, null);
                } catch (PropertyVetoException e) {
                    throw new ModelVetoException(e);
                }
            }
        }
    } 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 4 with ModelException

use of com.sun.jdo.api.persistence.model.ModelException 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 5 with ModelException

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

the class JDOConcreteBean20Generator method generateCMRGetSetBodies.

/**
 * Generate bodies of getters and setters for CMR field
 * @param fieldInfo the field information as FieldInfo instance.
 * @param cmrcleanbodyBuf the StringBuilder to append code for CMR cleanup
 * if necessary.
 */
private void generateCMRGetSetBodies(FieldInfo fieldInfo, StringBuilder cmrcleanbodyBuf) throws IOException {
    RelationshipElement rel = (RelationshipElement) fieldInfo.pfe;
    String otherPC = model.getRelatedClass(rel);
    boolean manySide = model.isCollection(fieldInfo.type);
    if (logger.isLoggable(Logger.FINE)) {
        RelationshipElement otherField = rel.getInverseRelationship(model);
        String otherFieldName = ((otherField != null) ? nameMapper.getEjbFieldForPersistenceField(otherPC, otherField.getName()) : null);
        // NOI18N
        logger.fine("manySide: " + manySide);
        // NOI18N
        logger.fine("Field: " + otherFieldName);
    }
    String otherEJB = nameMapper.getEjbNameForPersistenceClass(otherPC);
    String otherImpl = nameMapper.getConcreteBeanClassForEjbName(otherEJB);
    MessageFormat mformat = null;
    if (manySide) {
        threeParams[0] = fieldInfo.getter;
        threeParams[1] = fieldInfo.name;
        threeParams[2] = otherImpl;
        gbody = CMP20TemplateFormatter.cmrCgformatter.format(threeParams);
        fourParams[0] = otherImpl;
        fourParams[1] = fieldInfo.setter;
        fourParams[2] = fieldInfo.getter;
        fourParams[3] = fieldInfo.name;
        sbody = CMP20TemplateFormatter.cmrCsformatter.format(fourParams);
        mformat = CMP20TemplateFormatter.cmrcdCformatter;
        twoParams[0] = fieldInfo.type;
        twoParams[1] = fieldInfo.name;
        CMP20TemplateFormatter.addPrivateField(CMP20TemplateFormatter.cmrvformatter.format(twoParams), 0, concreteImplWriter);
        oneParam[0] = fieldInfo.name;
        cmrcleanbodyBuf.append(CMP20TemplateFormatter.cleancmrformatter.format(oneParam));
    } else {
        // 1 side
        fourParams[0] = otherPC;
        fourParams[1] = fieldInfo.getter;
        fourParams[2] = fieldInfo.type;
        fourParams[3] = otherImpl;
        gbody = CMP20TemplateFormatter.cmrgformatter.format(fourParams);
        threeParams[0] = otherPC;
        threeParams[1] = otherImpl;
        threeParams[2] = fieldInfo.setter;
        sbody = CMP20TemplateFormatter.cmrsformatter.format(threeParams);
        mformat = CMP20TemplateFormatter.cmrcdformatter;
    }
    if (rel.getDeleteAction() == RelationshipElement.CASCADE_ACTION) {
        twoParams[0] = fieldInfo.getter;
        twoParams[1] = otherImpl;
        cascadeDelete.append(mformat.format(twoParams));
        try {
            // Reset DeleteAction to NONE to suppress it in PM.deletePersistent().
            rel.setDeleteAction(RelationshipElement.NONE_ACTION);
        } catch (ModelException me) {
            logger.log(Logger.SEVERE, I18NHelper.getMessage(messages, "CMG.ModelExceptionOnDeleteAction", // NOI18N
            me));
        }
    }
}
Also used : MessageFormat(java.text.MessageFormat) ModelException(com.sun.jdo.api.persistence.model.ModelException) RelationshipElement(com.sun.jdo.api.persistence.model.jdo.RelationshipElement)

Aggregations

ModelException (com.sun.jdo.api.persistence.model.ModelException)6 ModelVetoException (com.sun.jdo.api.persistence.model.ModelVetoException)4 PropertyVetoException (java.beans.PropertyVetoException)4 MessageFormat (java.text.MessageFormat)2 RelationshipElement (com.sun.jdo.api.persistence.model.jdo.RelationshipElement)1 ArrayList (java.util.ArrayList)1