/** * Allows {@link OneToOneMapping} (@OneToOne and @ManyToOne) mappings to be * added to a dynamic type through API. This method can be used on a new * {@link DynamicTypeImpl} that has yet to be added to a session and have * its descriptor initialized, or it can be called on an active * (initialized) descriptor. * <p> * There is no support currently for having the EclipseLink * {@link SchemaManager} generate ALTER TABLE calls so any new columns * expected must be added without the help of EclipseLink or use the * {@link SchemaManager#replaceObject(org.eclipse.persistence.tools.schemaframework.DatabaseObjectDefinition)} * to DROP and CREATE the table. WARNING: This will cause data loss. */ public OneToOneMapping addOneToOneMapping(String name, DynamicType refType, String... fkFieldNames) { if (fkFieldNames == null) { throw new IllegalArgumentException("Invalid FK field names: 'null' for target: " + refType); } if (refType.getDescriptor().getPrimaryKeyFields().size() != fkFieldNames.length) { throw new IllegalArgumentException("Invalid FK field names: " + Arrays.asList(fkFieldNames) + " for target: " + refType); } OneToOneMapping mapping = new OneToOneMapping(); mapping.setAttributeName(name); mapping.setReferenceClass(refType.getJavaClass()); for (int index = 0; index < fkFieldNames.length; index++) { String targetField = refType.getDescriptor().getPrimaryKeyFields().get(index).getName(); mapping.addForeignKeyFieldName(fkFieldNames[index], targetField); } return (OneToOneMapping) addMapping(mapping); }
/** * Allows {@link OneToOneMapping} (@OneToOne and @ManyToOne) mappings to be * added to a dynamic type through API. This method can be used on a new * {@link DynamicTypeImpl} that has yet to be added to a session and have * its descriptor initialized, or it can be called on an active * (initialized) descriptor. * <p> * There is no support currently for having the EclipseLink * {@link SchemaManager} generate ALTER TABLE calls so any new columns * expected must be added without the help of EclipseLink or use the * {@link SchemaManager#replaceObject(org.eclipse.persistence.tools.schemaframework.DatabaseObjectDefinition)} * to DROP and CREATE the table. WARNING: This will cause data loss. */ public OneToOneMapping addOneToOneMapping(String name, DynamicType refType, String... fkFieldNames) { if (fkFieldNames == null || refType.getDescriptor().getPrimaryKeyFields().size() != fkFieldNames.length) { throw new IllegalArgumentException("Invalid FK field names: " + fkFieldNames + " for target: " + refType); } OneToOneMapping mapping = new OneToOneMapping(); mapping.setAttributeName(name); mapping.setReferenceClass(refType.getJavaClass()); for (int index = 0; index < fkFieldNames.length; index++) { String targetField = refType.getDescriptor().getPrimaryKeyFields().get(index).getName(); mapping.addForeignKeyFieldName(fkFieldNames[index], targetField); } return (OneToOneMapping) addMapping(mapping); }
/** * Allows {@link OneToOneMapping} (@OneToOne and @ManyToOne) mappings to be * added to a dynamic type through API. This method can be used on a new * {@link DynamicTypeImpl} that has yet to be added to a session and have * its descriptor initialized, or it can be called on an active * (initialized) descriptor. * <p> * There is no support currently for having the EclipseLink * {@link SchemaManager} generate ALTER TABLE calls so any new columns * expected must be added without the help of EclipseLink or use the * {@link SchemaManager#replaceObject(org.eclipse.persistence.tools.schemaframework.DatabaseObjectDefinition)} * to DROP and CREATE the table. WARNING: This will cause data loss. */ public OneToOneMapping addOneToOneMapping(String name, DynamicType refType, String... fkFieldNames) { if (fkFieldNames == null || refType.getDescriptor().getPrimaryKeyFields().size() != fkFieldNames.length) { throw new IllegalArgumentException("Invalid FK field names: " + fkFieldNames + " for target: " + refType); } OneToOneMapping mapping = new OneToOneMapping(); mapping.setAttributeName(name); mapping.setReferenceClass(refType.getJavaClass()); for (int index = 0; index < fkFieldNames.length; index++) { String targetField = refType.getDescriptor().getPrimaryKeyFields().get(index).getName(); mapping.addForeignKeyFieldName(fkFieldNames[index], targetField); } return (OneToOneMapping) addMapping(mapping); }