1 21 package oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors; 23 24 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor; 25 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataAccessibleObject; 26 27 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataJoinColumn; 28 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataJoinColumns; 29 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataPrimaryKeyJoinColumn; 30 31 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataConstants; 32 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor; 33 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataLogger; 34 35 import oracle.toplink.essentials.internal.helper.DatabaseField; 36 37 import oracle.toplink.essentials.mappings.OneToOneMapping; 38 39 import java.util.List ; 40 41 47 public abstract class ObjectAccessor extends RelationshipAccessor { 48 protected ObjectAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor) { 49 super(accessibleObject, classAccessor); 50 51 setIsOptional(true); 53 setFetchType(MetadataConstants.EAGER); 54 } 55 56 60 protected OneToOneMapping initOneToOneMapping() { 61 OneToOneMapping mapping = new OneToOneMapping(); 62 mapping.setIsReadOnly(false); 63 mapping.setIsPrivateOwned(false); 64 mapping.setIsOptional(isOptional()); 65 mapping.setAttributeName(getAttributeName()); 66 mapping.setReferenceClassName(getReferenceClassName()); 67 68 boolean usesIndirection = (m_project.enableLazyForOneToOne()) ? usesIndirection() : false; 71 mapping.setUsesIndirection(usesIndirection); 72 73 setAccessorMethods(mapping); 76 77 processCascadeTypes(mapping); 79 80 return mapping; 81 } 82 83 88 protected void processOwningMappingKeys(OneToOneMapping mapping) { 89 if (isOneToOnePrimaryKeyRelationship()) { 90 processOneToOnePrimaryKeyRelationship(mapping); 91 } else { 92 processOneToOneForeignKeyRelationship(mapping); 93 } 94 } 95 96 104 protected void processOneToOneForeignKeyRelationship(OneToOneMapping mapping) { 105 String defaultPKFieldName = getReferenceDescriptor().getPrimaryKeyFieldName(); 108 109 String defaultFKFieldName = getUpperCaseAttributeName() + "_" + defaultPKFieldName; 114 115 List <MetadataJoinColumn> joinColumns = processJoinColumns(); 117 118 for (MetadataJoinColumn joinColumn : joinColumns) { 120 DatabaseField pkField = joinColumn.getPrimaryKeyField(); 121 pkField.setName(getName(pkField, defaultPKFieldName, MetadataLogger.PK_COLUMN)); 122 pkField.setTableName(getReferenceDescriptor().getPrimaryTableName()); 123 124 DatabaseField fkField = joinColumn.getForeignKeyField(); 125 fkField.setName(getName(fkField, defaultFKFieldName, MetadataLogger.FK_COLUMN)); 126 if (fkField.getTableName().equals("")) { 128 fkField.setTableName(m_descriptor.getPrimaryTableName()); 129 } 130 131 mapping.addForeignKeyField(fkField, pkField); 133 134 if (fkField.isReadOnly()) { 137 mapping.setIsReadOnly(true); 138 } 139 } 140 } 141 142 150 protected void processOneToOnePrimaryKeyRelationship(OneToOneMapping mapping) { 151 MetadataDescriptor referenceDescriptor = getReferenceDescriptor(); 153 List <MetadataPrimaryKeyJoinColumn> primaryKeyJoinColumns = processPrimaryKeyJoinColumns(getPrimaryKeyJoinColumns(referenceDescriptor.getPrimaryTableName(), m_descriptor.getPrimaryTableName())); 154 155 for (MetadataPrimaryKeyJoinColumn primaryKeyJoinColumn : primaryKeyJoinColumns) { 157 DatabaseField pkField = primaryKeyJoinColumn.getPrimaryKeyField(); 160 pkField.setName(getName(pkField, referenceDescriptor.getPrimaryKeyFieldName(), m_logger.PK_COLUMN)); 161 162 DatabaseField fkField = primaryKeyJoinColumn.getForeignKeyField(); 165 fkField.setName(getName(fkField, m_descriptor.getPrimaryKeyFieldName(), m_logger.FK_COLUMN)); 166 167 mapping.addForeignKeyField(fkField, pkField); 169 170 mapping.setIsReadOnly(true); 172 } 173 } 174 175 179 239 } 240 | Popular Tags |