/** * INTERNAL: */ protected void addSelectionQuery(ForeignReferenceMapping cloneMapping, ForeignReferenceMapping sourceMapping, AbstractSession session) { // Set the new reference class cloneMapping.setReferenceClass(getDescriptor().getJavaClass()); cloneMapping.setReferenceClassName(getDescriptor().getJavaClassName()); // Force the selection criteria to be re-built. cloneMapping.setForceInitializationOfSelectionCriteria(true); // Now initialize the mapping cloneMapping.initialize(session); // The selection query should be initialized with all the right // goodies now, cache it for quick retrieval. ObjectLevelReadQuery selectionQuery = (ObjectLevelReadQuery) cloneMapping.getSelectionQuery(); selectionQuery.getExpressionBuilder().setQueryClassAndDescriptor(descriptor.getJavaClass(), descriptor); // By default its source mapping will be the cloned mapping, we // need to set the actual source mapping so that we can look it // back up correctly. selectionQuery.setSourceMapping(sourceMapping); // Cache the selection query for this source mapping. selectionQueriesForAllObjects.put(sourceMapping, selectionQuery); }
/** * INTERNAL: * Select one object of any concrete subclass. */ @Override protected Object selectOneObject(ReadObjectQuery query) throws DescriptorException { // If we came from a source mapping the execute the selection query // we prepared from it. if (selectionQueriesForAllObjects.containsKey(query.getSourceMapping())) { return query.getExecutionSession().executeQuery(selectionQueriesForAllObjects.get(query.getSourceMapping()), query.getTranslationRow()); } else { // Assuming we're doing a find by primary key ... // We have to update the translation row to be to the correct field. AbstractRecord translationRow = (AbstractRecord) query.getTranslationRow().clone(); Vector allFields = new Vector(); for (DatabaseField field : (Vector<DatabaseField>) translationRow.getFields()) { // Remove the table and let the descriptor figure it out. allFields.add(new DatabaseField(field.getName())); } translationRow.getFields().clear(); translationRow.getFields().addAll(allFields); return query.getSession().executeQuery(getDescriptor().getQueryManager().getReadObjectQuery(), translationRow); } } }