Search in sources :

Example 41 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class ReadQuery method remoteExecute.

/**
 * INTERNAL:
 * Return if this is a read query.
 */
@Override
public Object remoteExecute(AbstractSession session) throws DatabaseException {
    if (shouldCacheQueryResults()) {
        AbstractRecord arguments = new DatabaseRecord();
        if (translationRow != null) {
            arguments = translationRow;
        }
        Object queryResults = getQueryResults(session, arguments, true);
        if (queryResults != null) {
            return queryResults;
        }
        queryResults = super.remoteExecute(session);
        if (queryResults != null) {
            setQueryResults(queryResults, arguments, session);
        }
        return queryResults;
    }
    return super.remoteExecute(session);
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord)

Example 42 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class PLSQLStoredProcedureCall method buildOutputRow.

/**
 * Translate the SQL procedure output row, into the row
 * expected by the PLSQL procedure.
 * This handles re-ordering parameters.
 */
@Override
public AbstractRecord buildOutputRow(CallableStatement statement, DatabaseAccessor accessor, AbstractSession session) throws SQLException {
    AbstractRecord outputRow = super.buildOutputRow(statement, accessor, session);
    if (!shouldBuildOutputRow) {
        // fake-out Oracle executeUpdate rowCount, always 1
        outputRow.put("", 1);
        return outputRow;
    }
    // re-order elements in outputRow to conform to original indices
    Vector<DatabaseField> outputRowFields = outputRow.getFields();
    Vector outputRowValues = outputRow.getValues();
    DatabaseRecord newOutputRow = new DatabaseRecord();
    List<PLSQLargument> outArguments = getArguments(arguments, OUT);
    outArguments.addAll(getArguments(arguments, INOUT));
    Collections.sort(outArguments, new Comparator<PLSQLargument>() {

        @Override
        public int compare(PLSQLargument o1, PLSQLargument o2) {
            return o1.originalIndex - o2.originalIndex;
        }
    });
    for (PLSQLargument outArg : outArguments) {
        outArg.databaseType.buildOutputRow(outArg, outputRow, newOutputRow, outputRowFields, outputRowValues);
    }
    return newOutputRow;
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) Vector(java.util.Vector)

Example 43 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class NojiTestSet method runQuery.

@SuppressWarnings("unchecked")
@Test
public void runQuery() {
    DatabaseSession s = project.createDatabaseSession();
    s.dontLogMessages();
    s.login();
    Vector queryArgs = new NonSynchronizedVector();
    queryArgs.add("testsdfsdfasdfsdfsdfsdfsdfsdfdfsdfsdffds");
    boolean worked = false;
    String msg = null;
    Object o = null;
    try {
        o = s.executeQuery("Noji", Empty.class, queryArgs);
        worked = true;
    } catch (Exception e) {
        msg = e.getMessage();
    }
    assertTrue("invocation noji failed: " + msg, worked);
    assertNotNull("result is supposed to be not-null", o);
    Vector results = (Vector) o;
    DatabaseRecord record = (DatabaseRecord) results.get(0);
    BigDecimal x = (BigDecimal) record.get("X");
    assertTrue("wrong x value", x.intValue() == 33);
    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 44 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class NijioNijioTestSet 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(107);
    queryArgs.add(108);
    queryArgs.add(1);
    queryArgs.add("MERV");
    boolean worked = false;
    String msg = null;
    try {
        o = s.executeQuery("NijioNijio", Empty.class, queryArgs);
        worked = true;
    } catch (Exception e) {
        msg = e.getMessage();
    }
    assertTrue("invocation NijioNijio 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() == 158);
    String aa = (String) record.get("AA");
    assertTrue("wrong aa value", aa.equals("MERVISH"));
    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 45 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class DatabaseQuery method rowFromArguments.

/**
 * INTERNAL: Translate argumentValues into a database row.
 */
public AbstractRecord rowFromArguments(List argumentValues, AbstractSession session) throws QueryException {
    List<DatabaseField> argumentFields = this.argumentFields;
    // query is not prepared.
    if (!isPrepared() || (argumentFields == null)) {
        argumentFields = buildArgumentFields();
    }
    if (argumentFields.size() != argumentValues.size()) {
        throw QueryException.argumentSizeMismatchInQueryAndQueryDefinition(this);
    }
    int argumentsSize = argumentFields.size();
    AbstractRecord row = new DatabaseRecord(argumentsSize);
    for (int index = 0; index < argumentsSize; index++) {
        row.put(argumentFields.get(index), argumentValues.get(index));
    }
    return row;
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord)

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