use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class JoinedAttributeManager method processDataResults.
/**
* Process the data-results for joined data for a 1-m join.
* This allows all the data to be processed once, instead of n times for each object.
*/
protected void processDataResults(AbstractSession session) {
this.dataResultsByPrimaryKey = new HashMap();
int size = this.dataResults.size();
Object firstKey = null;
Object lastKey = null;
List<AbstractRecord> childRows = null;
ObjectBuilder builder = getDescriptor().getObjectBuilder();
int parentIndex = getParentResultIndex();
Vector<DatabaseField> trimedFields = null;
for (int dataResultsIndex = 0; dataResultsIndex < size; dataResultsIndex++) {
AbstractRecord row = this.dataResults.get(dataResultsIndex);
AbstractRecord parentRow = row;
// Must adjust for the parent index to ensure the correct pk is extracted.
if (parentIndex > 0) {
if (trimedFields == null) {
// The fields are always the same, so only build once.
trimedFields = new NonSynchronizedSubVector<>(row.getFields(), parentIndex, row.size());
}
Vector trimedValues = new NonSynchronizedSubVector(row.getValues(), parentIndex, row.size());
parentRow = new DatabaseRecord(trimedFields, trimedValues);
}
// Extract the primary key of the source object, to filter only the joined rows for that object.
Object sourceKey = builder.extractPrimaryKeyFromRow(parentRow, session);
// May be any outer-join so ignore null.
if (sourceKey != null) {
if (firstKey == null) {
firstKey = sourceKey;
}
if ((lastKey != null) && lastKey.equals(sourceKey)) {
childRows.add(row);
if (shouldFilterDuplicates()) {
// Also null out the row because it is a duplicate to avoid object building processing it.
this.dataResults.set(dataResultsIndex, null);
}
} else {
childRows = this.dataResultsByPrimaryKey.get(sourceKey);
if (childRows == null) {
childRows = new ArrayList();
this.dataResultsByPrimaryKey.put(sourceKey, childRows);
} else {
if (shouldFilterDuplicates()) {
// Also null out the row because it is a duplicate to avoid object building processing it.
this.dataResults.set(dataResultsIndex, null);
}
}
childRows.add(row);
lastKey = sourceKey;
}
}
}
// This will cause them to build normally by executing a query.
if (this.isToManyJoin) {
if ((lastKey != null) && (this.baseQuery.getMaxRows() > 0)) {
this.dataResultsByPrimaryKey.remove(lastKey);
}
if ((firstKey != null) && (this.baseQuery.getFirstResult() > 0)) {
this.dataResultsByPrimaryKey.remove(firstKey);
}
}
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class NojiNoTestSet method runQuery.
@SuppressWarnings("unchecked")
@Test
public void runQuery() {
DatabaseSession s = project.createDatabaseSession();
s.dontLogMessages();
s.login();
Object o = null;
Vector queryArgs = new NonSynchronizedVector();
queryArgs.add("test");
boolean worked = false;
String msg = null;
try {
o = s.executeQuery("NojiNo", Empty.class, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertTrue("invocation NojiNo failed: " + msg, worked);
Vector results = (Vector) o;
DatabaseRecord record = (DatabaseRecord) results.get(0);
BigDecimal bint2bigdec = (BigDecimal) record.get("X");
assertTrue("wrong bint2bigdec value", bint2bigdec.intValue() == 42);
Integer bool2int = (Integer) record.get("Z");
assertTrue("wrong bool2int value", bool2int == 1);
s.logout();
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class jiNiojiTestSet method runQuery.
@SuppressWarnings("unchecked")
@Test
public void runQuery() {
DatabaseSession s = project.createDatabaseSession();
s.dontLogMessages();
s.login();
Object o = null;
Vector queryArgs = new NonSynchronizedVector();
queryArgs.add("snicker-doodle");
queryArgs.add(102);
queryArgs.add(103);
boolean worked = false;
String msg = null;
try {
o = s.executeQuery("jiNioji", Empty.class, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertTrue("invocation jiNioji failed: " + msg, worked);
Vector results = (Vector) o;
DatabaseRecord record = (DatabaseRecord) results.get(0);
BigDecimal y = (BigDecimal) record.get("Y");
assertTrue("wrong y value", y.intValue() == 149);
s.logout();
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class jiNoTestSet method runQuery.
@SuppressWarnings("unchecked")
@Test
public void runQuery() {
DatabaseSession s = project.createDatabaseSession();
s.dontLogMessages();
s.login();
Object o = null;
Vector queryArgs = new NonSynchronizedVector();
queryArgs.add("test");
boolean worked = false;
String msg = null;
try {
o = s.executeQuery("jiNo", Empty.class, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertTrue("invocation jino failed: " + msg, worked);
Vector results = (Vector) o;
DatabaseRecord record = (DatabaseRecord) results.get(0);
Integer bool2int = (Integer) record.get("Y");
assertTrue("wrong bool2int value", bool2int == 0);
s.logout();
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class jiNojiTestSet method runQuery.
@SuppressWarnings("unchecked")
@Test
public void runQuery() {
DatabaseSession s = project.createDatabaseSession();
s.dontLogMessages();
s.login();
Object o = null;
Vector queryArgs = new NonSynchronizedVector();
queryArgs.add("test");
queryArgs.add(15);
boolean worked = false;
String msg = null;
try {
o = s.executeQuery("jiNoji", Empty.class, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertTrue("invocation jiNoji failed: " + msg, worked);
Vector results = (Vector) o;
DatabaseRecord record = (DatabaseRecord) results.get(0);
BigDecimal y = (BigDecimal) record.get("Y");
assertTrue("wrong y value", y.intValue() == 44);
s.logout();
}
Aggregations