Methods Summary |
---|
protected void | buildResult(oracle.toplink.essentials.queryframework.ReportQuery query, oracle.toplink.essentials.internal.sessions.AbstractRecord row, java.util.Vector toManyData)INTERNAL:
Create an array of attribute values (converted from raw field values using the mapping).
//GF_ISSUE_395
if (query.shouldDistinctBeUsed()){
this.key = new StringBuffer();
}
//end GF_ISSUE
int numberOfPrimaryKeyFields = 0;
Vector results = new Vector(query.getItems().size());
if (query.shouldRetrievePrimaryKeys()) {
numberOfPrimaryKeyFields = query.getDescriptor().getPrimaryKeyFields().size();
setPrimaryKeyValues(query.getDescriptor().getObjectBuilder().extractPrimaryKeyFromRow(row, query.getSession()));
// For bug 3115576 this is only used for EXISTS subselects so no result is needed.
} else if (query.shouldRetrieveFirstPrimaryKey()) {
numberOfPrimaryKeyFields = 1;
}
// CR 4240
// rowIndex is seperate as there may be place holders in the query that are not in the
// result set. So we can not compare the index to row size as there may be less
// objects in the row then there will be in the result set.
for (int index = 0; index < query.getItems().size(); index++) {
ReportItem item = (ReportItem)query.getItems().elementAt(index);
if (item.isContructorItem()){
ConstructorReportItem citem = (ConstructorReportItem)item;
Class[] constructorArgTypes = citem.getConstructorArgTypes();
List constructorMappings = citem.getConstructorMappings();
int numberOfItems = citem.getReportItems().size();
Object[] constructorArgs = new Object[numberOfItems];
if (constructorArgTypes==null){
constructorArgTypes = new Class[numberOfItems];
}
for (int i=0;i<numberOfItems;i++){
ReportItem ritem = (ReportItem)citem.getReportItems().get(i);
if (constructorArgTypes[i]==null){
if((constructorMappings != null)&&(constructorMappings.get(i)!=null)){
constructorArgTypes[i] = ((DatabaseMapping)constructorMappings.get(i)).getAttributeClassification();
}else if (ritem.getResultType() != null) {
constructorArgTypes[i] = ritem.getResultType();
}else if (ritem.getDescriptor() != null) {
constructorArgTypes[i] = ritem.getDescriptor().getJavaClass();
}
}
Object result = processItem(query, row, toManyData, (ReportItem)citem.getReportItems().get(i));
constructorArgs[i] = ConversionManager.getDefaultManager().convertObject(result, constructorArgTypes[i]);
//no type was specified, so use the object class itself.
if (constructorArgTypes[i]==null){
constructorArgTypes[i] = constructorArgs[i].getClass();
}
}
try{
java.lang.reflect.Constructor constructor = null;
Object returnValue = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
constructor = (Constructor)AccessController.doPrivileged(new PrivilegedGetConstructorFor(citem.getResultType(), constructorArgTypes, true));
returnValue = AccessController.doPrivileged(new PrivilegedInvokeConstructor(constructor, constructorArgs));
} catch (PrivilegedActionException exception) {
throw QueryException.exceptionWhileUsingConstructorExpression(exception.getException(), query); }
} else {
constructor = PrivilegedAccessHelper.getConstructorFor(citem.getResultType(), constructorArgTypes, true);
returnValue = PrivilegedAccessHelper.invokeConstructor(constructor, constructorArgs);
}
results.addElement(returnValue);
} catch (NoSuchMethodException exc){
throw QueryException.exceptionWhileUsingConstructorExpression(exc, query);
} catch (IllegalAccessException exc){
throw QueryException.exceptionWhileUsingConstructorExpression(exc, query);
} catch (java.lang.reflect.InvocationTargetException exc){
throw QueryException.exceptionWhileUsingConstructorExpression(exc, query);
} catch (InstantiationException exc){
throw QueryException.exceptionWhileUsingConstructorExpression(exc, query);
}
}else{
Object value = processItem(query, row, toManyData, item);
results.addElement(value);
}
}
setResults(results);
|
public void | clear()PUBLIC:
Clear the contents of the result.
this.names = new Vector();
this.results = new Vector();
|
public boolean | contains(java.lang.Object value)PUBLIC:
Check if the value is contained in the result.
return containsValue(value);
|
public boolean | containsKey(java.lang.Object key)PUBLIC:
Check if the key is contained in the result.
return getNames().contains(key);
|
public boolean | containsValue(java.lang.Object value)PUBLIC:
Check if the value is contained in the result.
return getResults().contains(value);
|
public java.util.Enumeration | elements()PUBLIC:
Return an enumeration of the result values.
return getResults().elements();
|
public java.util.Set | entrySet()PUBLIC:
Returns a set of the keys.
// bug 2669127
// implemented this method exactly the same way as DatabaseRow.entrySet()
int size = this.size();
Map tempMap = new HashMap(size);
for (int i = 0; i < size; i++) {
tempMap.put(this.getNames().elementAt(i), this.getResults().elementAt(i));
}
return tempMap.entrySet();
|
public boolean | equals(java.lang.Object anObject)PUBLIC:
Compare if the two results are equal.
if (anObject instanceof ReportQueryResult) {
return equals((ReportQueryResult)anObject);
}
return false;
|
public boolean | equals(oracle.toplink.essentials.queryframework.ReportQueryResult result)INTERNAL:
Used in testing to compare if results are correct.
if (this == result) {
return true;
}
if (!Helper.compareOrderedVectors(getResults(), result.getResults())) {
return false;
}
// Compare PKs
if (getPrimaryKeyValues() != null) {
if (result.getPrimaryKeyValues() == null) {
return false;
}
return Helper.compareOrderedVectors(getPrimaryKeyValues(), result.getPrimaryKeyValues());
}
return true;
|
public java.lang.Object | get(java.lang.Object name)PUBLIC:
Return the value for given item name.
if (name instanceof String) {
return get((String)name);
}
return null;
|
public java.lang.Object | get(java.lang.String name)PUBLIC:
Return the value for given item name.
int index = getNames().indexOf(name);
if (index == -1) {
return null;
}
return getResults().elementAt(index);
|
public java.lang.Object | getByIndex(int index)PUBLIC:
Return the indexed value from result.
return getResults().elementAt(index);
|
public java.util.Vector | getNames()PUBLIC:
Return the names of report items, provided to ReportQuery.
return names;
|
public java.util.Vector | getPrimaryKeyValues()PUBLIC:
Return the PKs for the corresponding object or null if not requested.
return primaryKeyValues;
|
public java.lang.String | getResultKey()INTERNAL:
Return the unique key for this result
if (this.key != null){
return this.key.toString();
}
return null;
|
public java.util.Vector | getResults()PUBLIC:
Return the results.
return results;
|
public boolean | isEmpty()PUBLIC:
Return if the result is empty.
return getNames().isEmpty();
|
public java.util.Set | keySet()PUBLIC:
Returns a set of the keys.
return new HashSet(getNames());
|
public java.util.Enumeration | keys()PUBLIC:
Return an enumeration of the result names.
return getNames().elements();
|
protected java.lang.Object | processItem(oracle.toplink.essentials.queryframework.ReportQuery query, oracle.toplink.essentials.internal.sessions.AbstractRecord row, java.util.Vector toManyData, oracle.toplink.essentials.internal.queryframework.ReportItem item)INTERNAL:
Return a value from an item and database row (converted from raw field values using the mapping).
JoinedAttributeManager joinManager = item.getJoinedAttributeManager();
if (joinManager.isToManyJoin()){
joinManager.setDataResults(toManyData, query.getSession());
}
DatabaseMapping mapping = item.getMapping();
Object value = null;
if (!item.isPlaceHolder()) {
if (mapping != null){
//if mapping is not null then it must be a direct mapping - see Reportitem.init
value = row.getValues().get(item.getResultIndex());
value = ((AbstractDirectMapping)mapping).getAttributeValue(value, query.getSession());
// GF_ISSUE_395
if (this.key != null){
this.key.append(value);
this.key.append("_");
}
// end GF_ISSUE
}else if (item.getDescriptor() != null){
//item is for an object result.
if (item.getDescriptor().getAllFields().size() + item.getResultIndex() > row.size()) {
throw QueryException.reportQueryResultSizeMismatch(item.getDescriptor().getAllFields().size() + item.getResultIndex(), row.size());
}
Vector trimedFields = Helper.copyVector(row.getFields(), item.getResultIndex(), row.size());
Vector trimedValues = Helper.copyVector(row.getValues(), item.getResultIndex(), row.size());
AbstractRecord subRow = new DatabaseRecord(trimedFields, trimedValues);
value = item.getDescriptor().getObjectBuilder().buildObject(query, subRow, joinManager);
// GF_ISSUE_395
if (this.key != null){
List list = item.getDescriptor().getObjectBuilder().extractPrimaryKeyFromRow(subRow, query.getSession());
if(list!=null){//GF bug3233, Distinct Processing fails with NPE when referenced target is null in database.
for (Iterator iterator = list.iterator(); iterator.hasNext();){
this.key.append(iterator.next());
this.key.append("-");
}
}
this.key.append("_");
}
// end GF_ISSUE
}else{
value = row.getValues().get(item.getResultIndex());
// GF_ISSUE_395
if (this.key != null){
this.key.append(value);
}
// end GF_ISSUE
}
}
return value;
|
public java.lang.Object | put(java.lang.Object name, java.lang.Object value)ADVANCED:
Set the value for given item name.
int index = getNames().indexOf(name);
if (index == -1) {
getNames().addElement(name);
getResults().addElement(value);
return null;
}
Object oldValue = getResults().elementAt(index);
getResults().setElementAt(value, index);
return oldValue;
|
public void | putAll(java.util.Map map)PUBLIC:
Add all of the elements.
Iterator entriesIterator = map.entrySet().iterator();
while (entriesIterator.hasNext()) {
Map.Entry entry = (Map.Entry)entriesIterator.next();
put(entry.getKey(), entry.getValue());
}
|
public java.lang.Object | readObject(java.lang.Class javaClass, oracle.toplink.essentials.sessions.Session session)PUBLIC:
If the PKs were retrieved with the attributes then this method can be used to read the real object from the database.
if (getPrimaryKeyValues() == null) {
throw QueryException.reportQueryResultWithoutPKs(this);
}
ReadObjectQuery query = new ReadObjectQuery(javaClass);
query.setSelectionKey(getPrimaryKeyValues());
return session.executeQuery(query);
|
public java.lang.Object | remove(java.lang.Object name)INTERNAL:
Remove the name key and value from the result.
int index = getNames().indexOf(name);
if (index >= 0) {
getNames().removeElementAt(index);
Object value = getResults().elementAt(index);
getResults().removeElementAt(index);
return value;
}
return null;
|
protected void | setNames(java.util.Vector names)
this.names = names;
|
protected void | setPrimaryKeyValues(java.util.Vector primaryKeyValues)INTERNAL:
Set the PK values for the result row's object.
this.primaryKeyValues = primaryKeyValues;
|
public void | setResults(java.util.Vector results)INTERNAL:
Set the results.
this.results = results;
|
public int | size()PUBLIC:
Return the number of name/value pairs in the result.
return getNames().size();
|
public java.lang.Object[] | toArray()INTERNAL:
Converts the ReportQueryResult to a simple array of values.
List list = getResults();
return (list == null) ? null : list.toArray();
|
public java.util.List | toList()INTERNAL:
Converts the ReportQueryResult to a simple list of values.
return this.getResults();
|
public java.lang.String | toString()
java.io.StringWriter writer = new java.io.StringWriter();
writer.write("ReportQueryResult(");
for (int index = 0; index < getResults().size(); index++) {
writer.write(String.valueOf(getResults().elementAt(index)));
if (index < (getResults().size() - 1)) {
writer.write(", ");
}
}
writer.write(")");
return writer.toString();
|
public java.util.Collection | values()PUBLIC:
Returns an collection of the values.
return getResults();
|