Query query = em.createNamedQuery("findMe"); Session session = em.unwrap(JpaEntityManager.class).getActiveSession(); DatabaseQuery databaseQuery = ((EJBQueryImpl)query).getDatabaseQuery(); databaseQuery.prepareCall(session, new DatabaseRecord()); String sqlString = databaseQuery.getSQLString();
/** * INTERNAL: * This method is a convenience method for extracting values from Results */ public Object getValueFromRecord(DatabaseRecord record, ResultSetMappingQuery query){ return record.get(this.column); }
DatabaseRecord recordWithValues= new DatabaseRecord(); recordWithValues.add(new DatabaseField("param1"), "someValue"); String sqlStringWithArgs = databaseQuery.getTranslatedSQLString(session, recordWithValues);
/** * INTERNAL: * This method is used to store the FK values used for this mapping in the cachekey. * This is used when the mapping is protected but we have retrieved the fk values and will cache * them for use when the entity is cloned. */ public void cacheForeignKeyValues(AbstractRecord databaseRecord, CacheKey cacheKey, AbstractSession session) { Set<DatabaseField> foreignKeys = this.descriptor.getForeignKeyValuesForCaching(); if (foreignKeys.isEmpty()) { return; } DatabaseRecord cacheRecord = new DatabaseRecord(foreignKeys.size()); for (DatabaseField field : foreignKeys) { cacheRecord.put(field, databaseRecord.get(field)); } cacheKey.setProtectedForeignKeys(cacheRecord); }
DatabaseRecord dr = new DatabaseRecord(); if (paramFlds.size() > 0) { for (int i=0; i < ((ArrayList) value).size(); i++) { dr.add(paramFlds.get(i), ((ArrayList) value).get(i)); dr.add(new DatabaseField(RESULT_STR), ((ArrayList) value).get(0)); } else { records = new Vector<DatabaseRecord>(); DatabaseRecord dr = new DatabaseRecord(); dr.add(new DatabaseField(RESULT_STR), ((Vector)value).firstElement()); records.add(dr); DatabaseRecord dr = new DatabaseRecord(); dr.add(new DatabaseField(RESULT_STR), value); records.add(dr); for (DatabaseRecord dr : records) { Element rowElement = TEMP_DOC.createElement(tempXMLTag); for (DatabaseField field : (Vector<DatabaseField>)dr.getFields()) { xrService.getXMLContext().createMarshaller().marshal(dr.get(field), rowElement); continue; Object fieldValue = dr.get(field); if (fieldValue != null) { if (fieldValue instanceof Calendar) {
+ (this.entityClass != null ? this.entityClass.getName() : "null")); DatabaseRecord entityRecord = new DatabaseRecord(descriptor.getFields().size()); if (descriptor.hasInheritance()) { Object value = null; if (this.discriminatorColumn == null) { value = record.get(descriptor.getInheritancePolicy().getClassIndicatorField()); } else { value = record.getIndicatingNoEntry(this.discriminatorColumn); if (value == AbstractRecord.noEntry){ throw QueryException.discriminatorColumnNotSelected(this.discriminatorColumn.getName(), getSQLResultMapping().getName()); entityRecord.put(descriptor.getInheritancePolicy().getClassIndicatorField(), value); if (fieldResult != null){ if (mapping.getFields().size() == 1 ) { entityRecord.put(mapping.getFields().firstElement(), record.get(fieldResult.getColumn())); } else if (mapping.getFields().size() >1){ getValueFromRecordForMapping(entityRecord,mapping,fieldResult,record); for (Iterator fields = mapping.getFields().iterator(); fields.hasNext();) { DatabaseField field = (DatabaseField)fields.next(); entityRecord.put(field, record.get(field));
DatabaseRecord entityRecord = new DatabaseRecord(descriptor.getFields().size()); if (descriptor.hasInheritance()) { if (this.discriminatorColumn != null) { Object value = record.get(this.discriminatorColumn); if (value == null){ throw QueryException.discriminatorColumnNotSelected(this.discriminatorColumn, query.getSQLResultSetMapping().getName()); entityRecord.put(descriptor.getInheritancePolicy().getClassIndicatorField(), record.get(this.discriminatorColumn)); } else { entityRecord.put(descriptor.getInheritancePolicy().getClassIndicatorField(), record.get(descriptor.getInheritancePolicy().getClassIndicatorField())); if (fieldResult != null){ if (mapping.getFields().size() == 1 ) { entityRecord.put(mapping.getFields().firstElement(), record.get(fieldResult.getColumnName())); } else if (mapping.getFields().size() >1){ getValueFromRecordForMapping(entityRecord,mapping,fieldResult,record); for (Iterator fields = mapping.getFields().iterator(); fields.hasNext();) { DatabaseField field = (DatabaseField)fields.next(); entityRecord.put(field, record.get(field));
/** * 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 = (((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(dbfield)); } entityRecord.put(dbfield, databaseRecord.get(fieldResult.getColumn())); 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 = (((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(dbfield)); } entityRecord.put(dbfield, databaseRecord.get(tempFieldResult.getColumn())); } }
/** * INTERNAL: * Add the field-value pair to the row. Will not check, * will simply add to the end of the row */ public void add(DatabaseField key, Object value) { checkValues(); this.fieldsArray = null; this.valuesArray = null; super.add(key, value); }
/** * INTERNAL: * Add the field-value pair to the row. */ public Object put(DatabaseField key, Object value) { checkValues(); this.fieldsArray = null; this.valuesArray = null; return super.put(key, value); }
DatabaseRecord record = (DatabaseRecord)iterator.next(); results.add(record.values().toArray());
/** * INTERNAL: */ public Vector getFields() { checkValues(); return super.getFields(); }
/** * INTERNAL: * Clone the row and its values. */ public AbstractRecord clone() { checkValues(); return super.clone(); }
/** * PUBLIC: * Clear the contents of the row. */ public void clear() { this.fieldsArray = null; this.valuesArray = null; super.clear(); }
/** * INTERNAL: * Check if the field is contained in the row. */ public boolean containsKey(DatabaseField key) { if (this.fieldsArray != null) { // Optimize check. int index = key.index; if ((index >= 0) && (index < this.size)) { DatabaseField field = this.fieldsArray[index]; if ((field == key) || field.equals(key)) { return true; } } for (DatabaseField field : this.fieldsArray) { if ((field == key) || field.equals(key)) { return true; } } return false; } else { return super.containsKey(key); } }
/** * INTERNAL: * This method is used to store the FK values used for this mapping in the cachekey. * This is used when the mapping is protected but we have retrieved the fk values and will cache * them for use when the entity is cloned. */ public void cacheForeignKeyValues(Object source, CacheKey cacheKey, ClassDescriptor descriptor, AbstractSession session) { Set<DatabaseField> foreignKeys = this.descriptor.getForeignKeyValuesForCaching(); if (foreignKeys.isEmpty()) { return; } DatabaseRecord cacheRecord = new DatabaseRecord(foreignKeys.size()); for (DatabaseField field : foreignKeys) { cacheRecord.put(field, extractValueFromObjectForField(source, field, session)); } cacheKey.setProtectedForeignKeys(cacheRecord); }
DatabaseRecord dr = new DatabaseRecord(); if (paramFlds.size() > 0) { for (int i=0; i < ((ArrayList<?>) value).size(); i++) { dr.add(paramFlds.get(i), ((ArrayList<?>) value).get(i)); dr.add(new DatabaseField(RESULT_STR), ((ArrayList<?>) value).get(0)); } else { records = new Vector<DatabaseRecord>(); DatabaseRecord dr = new DatabaseRecord(); dr.add(new DatabaseField(RESULT_STR), ((Vector<?>)value).firstElement()); records.add(dr); DatabaseRecord dr = new DatabaseRecord(); dr.add(new DatabaseField(RESULT_STR), value); records.add(dr); for (DatabaseRecord dr : records) { Element rowElement = TEMP_DOC.createElement(tempXMLTag); for (DatabaseField field : dr.getFields()) { xrService.getXMLContext().createMarshaller().marshal(dr.get(field), rowElement); continue; Object fieldValue = dr.get(field); if (fieldValue != null) { if (fieldValue instanceof Calendar) {
+ (this.entityClass != null ? this.entityClass.getName() : "null")); DatabaseRecord entityRecord = new DatabaseRecord(descriptor.getFields().size()); if (descriptor.hasInheritance()) { Object value = null; if (this.discriminatorColumn == null) { value = record.get(descriptor.getInheritancePolicy().getClassIndicatorField()); } else { value = record.getIndicatingNoEntry(this.discriminatorColumn); if (value == AbstractRecord.noEntry){ throw QueryException.discriminatorColumnNotSelected(this.discriminatorColumn.getName(), getSQLResultMapping().getName()); entityRecord.put(descriptor.getInheritancePolicy().getClassIndicatorField(), value); if (fieldResult != null){ if (mapping.getFields().size() == 1 ) { entityRecord.put(mapping.getFields().firstElement(), record.get(fieldResult.getColumn())); } else if (mapping.getFields().size() >1){ getValueFromRecordForMapping(entityRecord,mapping,fieldResult,record); for (Iterator fields = mapping.getFields().iterator(); fields.hasNext();) { DatabaseField field = (DatabaseField)fields.next(); entityRecord.put(field, record.get(field));
/** * 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 = (((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 = (((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(dbfield)); } entityRecord.put(dbfield, databaseRecord.get(tempFieldResult.getColumnName())); } }
/** * INTERNAL: * Add the field-value pair to the row. Will not check, * will simply add to the end of the row */ public void add(DatabaseField key, Object value) { checkValues(); this.fieldsArray = null; this.valuesArray = null; super.add(key, value); }