Search in sources :

Example 71 with DatabaseRecord

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);
        }
    }
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) HashMap(java.util.HashMap) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) ArrayList(java.util.ArrayList) ObjectBuilder(org.eclipse.persistence.internal.descriptors.ObjectBuilder) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) NonSynchronizedSubVector(org.eclipse.persistence.internal.helper.NonSynchronizedSubVector) Vector(java.util.Vector) NonSynchronizedSubVector(org.eclipse.persistence.internal.helper.NonSynchronizedSubVector)

Example 72 with DatabaseRecord

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();
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) Vector(java.util.Vector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 73 with DatabaseRecord

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();
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) Vector(java.util.Vector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 74 with DatabaseRecord

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();
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) Vector(java.util.Vector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) Test(org.junit.Test)

Example 75 with DatabaseRecord

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();
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) Vector(java.util.Vector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)110 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)44 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)43 Vector (java.util.Vector)31 ArrayList (java.util.ArrayList)17 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)17 BigDecimal (java.math.BigDecimal)14 List (java.util.List)14 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)14 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)14 Test (org.junit.Test)14 Expression (org.eclipse.persistence.expressions.Expression)12 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)12 HashMap (java.util.HashMap)11 Map (java.util.Map)10 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)7 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)7 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)6 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)6 SQLUpdateStatement (org.eclipse.persistence.internal.expressions.SQLUpdateStatement)6