protected boolean canWeaveValueHolders(Class clz, List mappings) { // we intend to change to fetch=LAZY 1:1 attributes to ValueHolders boolean weaveValueHolders = true; boolean foundOTOM = false; for (Iterator j = mappings.iterator(); j.hasNext();) { DatabaseMapping dm = (DatabaseMapping)j.next(); String attributeName = dm.getAttributeName(); if (dm.isOneToOneMapping()) { OneToOneMapping otom = (OneToOneMapping)dm; Class typeClz = getAttributeTypeFromClass(clz, attributeName, dm, true); if (otom.getIndirectionPolicy().usesIndirection() && typeClz != null && !typeClz.isAssignableFrom( ValueHolderInterface.class)) { foundOTOM = true; weaveValueHolders = true; } } } // did we actually <b>find</b> any attributes to change? return weaveValueHolders & foundOTOM; }
/** * INTERNAL: * Iterates through all one to one mappings and checks if any of them use joining. * <p> * By caching the result query execution in the case where there are no joined * attributes can be improved. */ public void initializeJoinedAttributes() { // For concurrency don't worry about doing this work twice, just make sure // if it happens don't add the same joined attributes twice. Vector<String> joinedAttributes = null; Vector mappings = getDescriptor().getMappings(); for (int i = 0; i < mappings.size(); i++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(i); if (mapping.isOneToOneMapping() && (mapping.isRelationalMapping()) && ((OneToOneMapping)mapping).shouldUseJoining()) { if (joinedAttributes == null) { joinedAttributes = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); } joinedAttributes.add(mapping.getAttributeName()); } } this.joinedAttributes = joinedAttributes; }
/** * INTERNAL: * This method is for processing a single FieldResult, returning the DatabaseField it refers to. */ public DatabaseField processValueFromRecordForMapping(ClassDescriptor descriptor, String[] attributeNames, int currentLoc){ DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeNames[currentLoc]); if (mapping==null){throw QueryException.mappingForFieldResultNotFound(attributeNames,currentLoc);} currentLoc++; if (attributeNames.length!=currentLoc){ ClassDescriptor currentDescriptor = mapping.getReferenceDescriptor(); DatabaseField df= processValueFromRecordForMapping(currentDescriptor, attributeNames, currentLoc); if (mapping.isOneToOneMapping()){ return (DatabaseField)(((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(df)); } return df; }else{ //this is it.. return this mapping's field return (DatabaseField) mapping.getFields().firstElement(); } }
/** * INTERNAL: * This method is for processing all FieldResults for a mapping. Adds DatabaseFields to the passed in entityRecord */ public void getValueFromRecordForMapping(DatabaseRecord entityRecord,DatabaseMapping mapping, FieldResult fieldResult, DatabaseRecord databaseRecord){ ClassDescriptor currentDescriptor = mapping.getReferenceDescriptor(); /** check if this FieldResult contains any other FieldResults, process it if it doesn't */ if (fieldResult.getFieldResults()==null){ DatabaseField dbfield = processValueFromRecordForMapping(currentDescriptor,fieldResult.getMultipleFieldIdentifiers(),1); /** If it is a 1:1 mapping we need to do the target to source field conversion. If it is an aggregate, it is fine as it is*/ if (mapping.isOneToOneMapping()){ dbfield = (DatabaseField)(((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(dbfield)); } entityRecord.put(dbfield, databaseRecord.get(fieldResult.getColumnName())); return; } /** This processes each FieldResult stored in the collection of FieldResults individually */ Iterator fieldResults = fieldResult.getFieldResults().iterator(); while (fieldResults.hasNext()){ FieldResult tempFieldResult = ((FieldResult)fieldResults.next()); DatabaseField dbfield = processValueFromRecordForMapping(currentDescriptor,tempFieldResult.getMultipleFieldIdentifiers(),1); if (mapping.isOneToOneMapping()){ dbfield = (DatabaseField)(((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(dbfield)); } entityRecord.put(dbfield, databaseRecord.get(tempFieldResult.getColumnName())); } }
if (typeClz == null){ attributeDetails.setAttributeOnSuperClass(true); if (dm.isOneToOneMapping()){ unMappedAttributes.add(dm); } else if (dm.isOneToOneMapping()) { OneToOneMapping otom = (OneToOneMapping)dm; attributeDetails.referenceClass = otom.getReferenceClassName();
OneToManyMapping otm = (OneToManyMapping)mapping; foreignKeys = otm.getTargetForeignKeyToSourceKeys(); } else if (mapping.isOneToOneMapping()) { OneToOneMapping oto = (OneToOneMapping)mapping; foreignKeys = oto.getSourceToTargetKeyFields(); if (mapping.isOneToOneMapping()) { printer.getWriter().write("PRIOR " + tableName + "." + source.getName()); printer.getWriter().write(" = " + tableName + "." + target.getName()); target = (DatabaseField)foreignKeys.get(source); if (mapping.isOneToOneMapping()) { printer.getWriter().write("PRIOR " + tableName + "." + source.getName()); printer.getWriter().write(" = " + tableName + "." + target.getName());
/** * Build additional table/field definitions for the dscriptor, like relation table * and direct-collection, direct-map table, as well as reset LOB type for serialized * object mapping and type conversion maping for LOB usage */ private void postInitTableSchema(ClassDescriptor desc) { Iterator mappingIter = desc.getMappings().iterator(); while (mappingIter.hasNext()) { DatabaseMapping mapping = (DatabaseMapping) mappingIter.next(); if (mapping.isManyToManyMapping()) { buildRelationTableDefinition((ManyToManyMapping) mapping); } else if (mapping.isDirectCollectionMapping()) { buildDirectCollectionTableDefinition((DirectCollectionMapping) mapping, desc); } else if (mapping.isAggregateCollectionMapping()) { //need to figure out the target foreign key field and add it into the aggregate target table addForeignkeyFieldToAggregateTargetTable((AggregateCollectionMapping) mapping); } else if (mapping.isForeignReferenceMapping()) { if (mapping.isOneToOneMapping()) addForeignKeyFieldToSourceTargetTable((OneToOneMapping) mapping); else if (mapping.isOneToManyMapping()) addForeignKeyFieldToSourceTargetTable((OneToManyMapping) mapping); } } processAdditionalTablePkFields(desc); }
Vector values; Vector baseExpressions; if(mapping != null && mapping.isOneToOneMapping()) { fields = mapping.getFields(); int fieldsSize = fields.size();
DatabaseMapping mapping = aggregateDescriptor.getMappingForAttributeName(name); if (mapping != null && mapping.isOneToOneMapping()) { int index = 0;
for (Enumeration keyMappingsEnum = getPrimaryKeyMappings().elements(); keyMappingsEnum.hasMoreElements();) { if (((DatabaseMapping)keyMappingsEnum.nextElement()).isOneToOneMapping()) { hasOneToOne = true;
/** * INTERNAL: * Process a @OneToOne or one-to-one element into a TopLink OneToOne * mapping. */ public void process() { // Initialize our mapping now with what we found. OneToOneMapping mapping = initOneToOneMapping(); if (getMappedBy().equals("")) { // Owning side, look for JoinColumns or PrimaryKeyJoinColumns. processOwningMappingKeys(mapping); } else { // Non-owning side, process the foreign keys from the owner. OneToOneMapping ownerMapping = null; if (getOwningMapping().isOneToOneMapping()){ ownerMapping = (OneToOneMapping)getOwningMapping(); } else { // If improper mapping encountered, throw an exception. getValidator().throwInvalidMappingEncountered(getJavaClass(), getReferenceClass()); } mapping.setSourceToTargetKeyFields(ownerMapping.getTargetToSourceKeyFields()); mapping.setTargetToSourceKeyFields(ownerMapping.getSourceToTargetKeyFields()); } // Add the mapping to the descriptor. m_descriptor.addMapping(mapping); } }
if (getOwningMapping().isOneToOneMapping()){ ownerMapping = (OneToOneMapping) getOwningMapping(); } else {
if (shouldUseOuterJoin && (!(mapping.isOneToOneMapping() || mapping.isOneToManyMapping() || mapping.isManyToManyMapping() || mapping.isAggregateCollectionMapping() || mapping.isDirectCollectionMapping()))) { throw QueryException.outerJoinIsOnlyValidForOneToOneMappings(getMapping());