/** Returns a PersistenceClassElement created from the mapping class. * @param mappingClass the mapping class element to which the persistence * class is associated * @return the PersistenceClassElement for mappingClass, * <code>null</code> if an error occurs or none exists * @see #getMappingClass */ protected PersistenceClassElement getPersistenceClass ( MappingClassElement mappingClass) { return ((mappingClass == null) ? null : ((MappingClassElementImpl)mappingClass).getPersistenceElement()); }
/** Removes a field from the list of fields in this mapping class. * @param field field element to be removed * @exception ModelException if impossible */ public void removeField (MappingFieldElement field) throws ModelException { try { fireVetoableChange(PROP_FIELDS, null, null); if (!getFields().remove(field)) { throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.element.element_not_removed", field)); // NOI18N } firePropertyChange(PROP_FIELDS, null, null); } catch (PropertyVetoException e) { throw new ModelVetoException(e); } }
/** Set the consistency level of this mapping class. * @param level an integer indicating the consistency level, one of: * {@link #NONE_CONSISTENCY},{@link #CHECK_MODIFIED_AT_COMMIT_CONSISTENCY}, * {@link #CHECK_ALL_AT_COMMIT_CONSISTENCY}, * {@link #LOCK_WHEN_MODIFIED_CONSISTENCY}, * {@link #LOCK_WHEN_MODIFIED_CHECK_ALL_AT_COMMIT_CONSISTENCY}, * {@link #LOCK_WHEN_LOADED_CONSISTENCY}, or * {@link #VERSION_CONSISTENCY}. * @exception ModelException if impossible. */ public void setConsistencyLevel (int level) throws ModelException { Integer old = new Integer(getConsistencyLevel()); Integer newLevel = new Integer(level); try { fireVetoableChange(PROP_CONSISTENCY, old, newLevel); _consistencyLevel = level; firePropertyChange(PROP_CONSISTENCY, old, newLevel); } catch (PropertyVetoException e) { throw new ModelVetoException(e); } }
/** Adds a field to the list of fields in this mapping class. * @param field field element to be added * @exception ModelException if impossible */ public void addField (MappingFieldElement field) throws ModelException { ArrayList fields = getFields(); if (!fields.contains(field)) { try { fireVetoableChange(PROP_FIELDS, null, null); fields.add(field); firePropertyChange(PROP_FIELDS, null, null); } catch (PropertyVetoException e) { throw new ModelVetoException(e); } } }
/** Returns the list of version fields (MappingFieldElements) in this * mapping class. This list only includes fields if the consistency * level is {@link #VERSION_CONSISTENCY}. * @return the version fields in this mapping class */ public List getVersionFields () { List versionFields = new ArrayList(); if (VERSION_CONSISTENCY == getConsistencyLevel()) { Iterator iterator = getFields().iterator(); while (iterator.hasNext()) { MappingFieldElement fieldCandidate = (MappingFieldElement)iterator.next(); if (fieldCandidate.isVersion()) versionFields.add(fieldCandidate); } } return versionFields; }
Collection tables = getTables(); Iterator iterator = null; boolean found = false; fireVetoableChange(PROP_TABLES, null, null); found = tables.remove(table); firePropertyChange(PROP_TABLES, null, null); iterator = getFields().iterator(); while (iterator.hasNext()) boolean versionField = mappingField.isVersion(); removeField(mappingField); mappingField.getName(), this); mappingField.setVersion(true); addField(mappingField); throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.element.element_not_removed", table)); // NOI18N throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.element.null_argument")); // NOI18N
ArrayList tables = getTables(); throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.table.primary_table_defined", table)); // NOI18N new MappingTableElementImpl(table, this); SchemaElement schema = table.getDeclaringSchema(); String currentRoot = getDatabaseRoot(); setDatabaseRoot(schema); else if (!currentRoot.equals(schema.getName().getFullName())) getMessages(), "mapping.table.schema_mismatch", // NOI18N table.toString(), currentRoot)); fireVetoableChange(PROP_TABLES, null, null); tables.add(mappingTable); firePropertyChange(PROP_TABLES, null, null);
parentTable, TableElement table) throws ModelException ArrayList tables = getTables(); throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.element.null_argument")); // NOI18N throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.table.parent_table_not_found", // NOI18N parentTable.getTable())); getMessages(), "mapping.table.secondary_table_defined", // NOI18N new Object[]{table, parentTable.getTable()})); fireVetoableChange(PROP_TABLES, null, null); parentTable.addReferencingKey(key); tables.add(mappingTable); firePropertyChange(PROP_TABLES, null, null);
ArrayList tables = getTables(); setPrimaryTable(table); else (MappingTableElement)iterator.next(); MappingReferenceKeyElement refKey = addSecondaryTable(mappingTable, table); getMessages(), "mapping.table.foreign_key_not_found", table)); // NOI18N throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.table.null_argument")); // NOI18N
/** Set the navigable flag for this mapping class to flag. * @param flag if <code>true</code>, lazy initialization will be used; * if <code>false</code>, access to a non-fetched field will result in an * exception. * @exception ModelException if impossible */ public void setNavigable (boolean flag) throws ModelException { Boolean old = JavaTypeHelper.valueOf(isNavigable()); Boolean newFlag = JavaTypeHelper.valueOf(flag); try { fireVetoableChange(PROP_NAVIGABLE, old, newFlag); _properties = (flag) ? (_properties | NAVIGABLE) : (_properties & ~NAVIGABLE); firePropertyChange(PROP_NAVIGABLE, old, newFlag); } catch (PropertyVetoException e) { throw new ModelVetoException(e); } }
/** Set the database root for this MappingClassElement. * The root represents the database used by the tables mapped to * this mapping class. * @param root the new database root * @exception ModelException if impossible */ public void setDatabaseRoot (SchemaElement root) throws ModelException { String old = getDatabaseRoot(); String newRoot = ((root != null) ? root.getName().getFullName() : null); try { fireVetoableChange(PROP_DATABASE_ROOT, old, newRoot); _databaseRoot = newRoot; firePropertyChange(PROP_DATABASE_ROOT, old, newRoot); } catch (PropertyVetoException e) { throw new ModelVetoException(e); } }
/** This method is called after a MappingClassElement is unarchived * from a .mapping file. This method provides a hook to do any checking * (version number checking) and conversion after unarchiving. * @exception ModelException if impossible */ public void postUnarchive () throws ModelException { // check version number switch (versionNo) { case 0: // outdated version number case 1: // outdated version number throw new ModelException (I18NHelper.getMessage(getMessages(), "file.incompatible_version", getName())); //NOI18N case 2: // Boston format => convert to Pilsen format stripSchemaName(); break; case 3: // same as 4 except package names are different case 4: // same as 5 except version field not a choice for MFE case MappingClassElementImpl.CURRENT_VERSION_NO: // OK break; default: // version number is unknown throw new ModelException (I18NHelper.getMessage(getMessages(), "file.incompatible_version", getName())); //NOI18N } }
/** * Create mapping class and associated table and PC class * @param pcClass PC class that mapping class associated * @param table table element that mapping class associated * @return MappingClassElement associated with table and PC class * @throws ModelException */ private MappingClassElement createMappingClass( PersistenceClassElement pcClass, TableElement table) throws ModelException { MappingClassElement mappingClass = new MappingClassElementImpl(pcClass); mappingClass.setDatabaseRoot(schema); mappingClass.addTable(table); return mappingClass; }
/** Set the modified flag for this mapping class to flag. This is usually * set to <code>true</code> by property changes and <code>false</code> * after a save. * @param flag if <code>true</code>, this class is marked as modified; * if <code>false</code>, it is marked as unmodified. */ public void setModified (boolean flag) { boolean oldFlag = isModified(); if (flag != oldFlag) { _isModified = flag; firePropertyChange(PROP_MODIFIED, JavaTypeHelper.valueOf(oldFlag), JavaTypeHelper.valueOf(flag)); } }
/** Fires vetoable change event. This method overrides that of * MappingElementImpl to give listeners a chance to block * changes on the mapping class element modified status. * @param name property name * @param o old value * @param n new value * @exception PropertyVetoException when the change is vetoed by a listener */ protected final void fireVetoableChange (String name, Object o, Object n) throws PropertyVetoException { // even though o == null and n == null will signify a change, that // is consistent with PropertyChangeSupport's behavior and is // necessary for this to work boolean noChange = ((o != null) && (n != null) && o.equals(n)); super.fireVetoableChange(name, o, n); if (!(PROP_MODIFIED.equals(name)) && !noChange) fireVetoableChange(PROP_MODIFIED, Boolean.FALSE, Boolean.TRUE); }
/** Scans through this mapping class looking for a field whose * name matches the name passed in. * @param name name of the field to find. * @return the mapping field whose name matches the name parameter */ public MappingFieldElement getField (String name) { Iterator fieldIterator = getFields().iterator(); while (fieldIterator.hasNext()) { MappingFieldElement field = (MappingFieldElement)fieldIterator.next(); if (name.equals(field.getName())) return field; } return null; }
Collection tables = getTables(); Iterator iterator = null; boolean found = false; fireVetoableChange(PROP_TABLES, null, null); found = tables.remove(table); firePropertyChange(PROP_TABLES, null, null); iterator = getFields().iterator(); while (iterator.hasNext()) boolean versionField = mappingField.isVersion(); removeField(mappingField); mappingField.getName(), this); mappingField.setVersion(true); addField(mappingField); throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.element.element_not_removed", table)); // NOI18N throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.element.null_argument")); // NOI18N
ArrayList tables = getTables(); throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.table.primary_table_defined", table)); // NOI18N new MappingTableElementImpl(table, this); SchemaElement schema = table.getDeclaringSchema(); String currentRoot = getDatabaseRoot(); setDatabaseRoot(schema); else if (!currentRoot.equals(schema.getName().getFullName())) getMessages(), "mapping.table.schema_mismatch", // NOI18N table.toString(), currentRoot)); fireVetoableChange(PROP_TABLES, null, null); tables.add(mappingTable); firePropertyChange(PROP_TABLES, null, null);
parentTable, TableElement table) throws ModelException ArrayList tables = getTables(); throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.element.null_argument")); // NOI18N throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.table.parent_table_not_found", // NOI18N parentTable.getTable())); getMessages(), "mapping.table.secondary_table_defined", // NOI18N new Object[]{table, parentTable.getTable()})); fireVetoableChange(PROP_TABLES, null, null); parentTable.addReferencingKey(key); tables.add(mappingTable); firePropertyChange(PROP_TABLES, null, null);
ArrayList tables = getTables(); setPrimaryTable(table); else (MappingTableElement)iterator.next(); MappingReferenceKeyElement refKey = addSecondaryTable(mappingTable, table); getMessages(), "mapping.table.foreign_key_not_found", table)); // NOI18N throw new ModelException(I18NHelper.getMessage(getMessages(), "mapping.table.null_argument")); // NOI18N