Search in sources :

Example 56 with DatabaseRecord

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

the class PLSQLTestModel method getCollectionTestSuite.

public static TestSuite getCollectionTestSuite() {
    TestSuite suite = new TestSuite();
    suite.setName("PLSQLCollectionTestSuite");
    suite.setDescription("This suite tests calling PLSQL procedures that take collections.");
    Address address = new Address();
    address.setId(new BigDecimal(123));
    address.setNumber(17);
    address.setStreet("Bank");
    address.setCity("Ottawa");
    address.setState("ON");
    Phone phone = new Phone();
    phone.setAreaCode("613");
    phone.setNumber("7927711");
    Employee employee = new Employee();
    employee.setId(new BigDecimal(123));
    employee.setName("Bob Jones");
    employee.setAddress(address);
    employee.getPhones().add(phone);
    List args = new ArrayList();
    DatabaseRecord result = new DatabaseRecord();
    List collection = new ArrayList();
    collection.add("Ottawa");
    result.put("P_CITY_LIST", collection);
    result.put("P_CITY", "Nepean");
    PLSQLTest test = new PLSQLTest("CityListOut", Address.class, args, result);
    test.setName("CityListOutTest");
    suite.addTest(test);
    args = new ArrayList();
    collection = new ArrayList(Arrays.asList("Ottawa", "Toronto"));
    args.add(collection);
    args.add("Nepean");
    result = new DatabaseRecord();
    result.put("P_CITY_LIST", collection);
    result.put("P_CITY", "Nepean");
    test = new PLSQLTest("CityListInOut", Address.class, args, result);
    test.setName("CityListInOutTest");
    suite.addTest(test);
    args = new ArrayList();
    args.add(new Object[] { address, address });
    args.add("Nepean");
    test = new PLSQLTest("AddressListIn", Address.class, args);
    test.setName("AddressListInTest");
    suite.addTest(test);
    args = new ArrayList();
    result = new DatabaseRecord();
    result.put("P_ADDRESS_LIST", new ArrayList());
    result.put("P_CITY", "Nepean");
    test = new PLSQLTest("AddressListOut", Address.class, args, result);
    test.setName("AddressListOutTest");
    suite.addTest(test);
    args = new ArrayList();
    collection = new ArrayList(Arrays.asList(address, address));
    args.add(collection);
    args.add("Nepean");
    result = new DatabaseRecord();
    result.put("P_ADDRESS_LIST", collection);
    result.put("P_CITY", "Nepean");
    test = new PLSQLTest("AddressListInOut", Address.class, args, result);
    test.setName("AddressListInOutTest");
    suite.addTest(test);
    args = new ArrayList();
    args.add(new Object[] { employee, employee });
    args.add("Nepean");
    test = new PLSQLTest("EmployeeListIn", Employee.class, args);
    test.setName("EmployeeListInTest");
    suite.addTest(test);
    args = new ArrayList();
    result = new DatabaseRecord();
    result.put("P_EMP_LIST", new ArrayList());
    result.put("P_CITY", "Nepean");
    test = new PLSQLTest("EmployeeListOut", Employee.class, args, result);
    test.setName("EmployeeListOutTest");
    suite.addTest(test);
    args = new ArrayList();
    collection = new ArrayList(Arrays.asList(employee, employee));
    args.add(collection);
    args.add("Nepean");
    result = new DatabaseRecord();
    result.put("P_EMP_LIST", collection);
    result.put("P_CITY", "Nepean");
    test = new PLSQLTest("EmployeeListInOut", Employee.class, args, result);
    test.setName("EmployeeListInOutTest");
    suite.addTest(test);
    return suite;
}
Also used : Employee(org.eclipse.persistence.testing.models.plsql.Employee) Address(org.eclipse.persistence.testing.models.plsql.Address) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) Phone(org.eclipse.persistence.testing.models.plsql.Phone) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 57 with DatabaseRecord

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

the class Address method getData.

static Vector<DatabaseRecord> getData(ClassDescriptor desc) {
    Vector<DatabaseRecord> rows = new Vector<>();
    Vector<DatabaseField> fields = desc.getAllFields();
    DatabaseField[] fieldsArray = fields.toArray(new DatabaseField[0]);
    rows.add(new ArrayRecord(fields, fieldsArray, new Object[] { 51, "Calgary", "Canada", "J5J2B5", "ALB", "1111 Moose Rd." }));
    rows.add(new ArrayRecord(fields, fieldsArray, new Object[] { 52, "Metcalfe", "Canada", "Y4F7V6", "ONT", "2 Anderson Rd." }));
    rows.add(new ArrayRecord(fields, fieldsArray, new Object[] { 53, "Montreal", "Canada", "Q2S5Z5", "QUE", "1 Habs Place" }));
    return rows;
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) ArrayRecord(org.eclipse.persistence.internal.sessions.ArrayRecord) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Vector(java.util.Vector)

Example 58 with DatabaseRecord

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

the class IndirectListTest method setUp.

/**
 * set up the test fixture:
 * 1. an IndirectList based on a Vector
 */
@Before
public void setUp() {
    list = setUpList();
    Object temp = new Vector<>(list);
    ValueHolderInterface vh = new QueryBasedValueHolder(new ReadAllQuery(), new DatabaseRecord(), new TestSession(temp));
    if (cls == null) {
        testList = IndirectCollectionsFactory.createIndirectList();
    } else {
        try {
            testList = cls.getConstructor().newInstance();
        } catch (ReflectiveOperationException e) {
            throw new RuntimeException(e);
        }
    }
    testList.setValueHolder(vh);
    if (useListener) {
        testListLsn = new Listener();
        testList._persistence_setPropertyChangeListener(testListLsn);
    }
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) ValueHolderInterface(org.eclipse.persistence.indirection.ValueHolderInterface) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) Vector(java.util.Vector) QueryBasedValueHolder(org.eclipse.persistence.internal.indirection.QueryBasedValueHolder) Before(org.junit.Before)

Example 59 with DatabaseRecord

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

the class IndirectMapTest method setUp.

/**
 * set up the test fixture:
 * 1. an IndirectMap based on a Hashtable
 */
@Before
public void setUp() {
    map = this.setUpMap();
    Object temp = new Hashtable(map);
    ValueHolderInterface vh = new QueryBasedValueHolder(new ReadAllQuery(), new DatabaseRecord(), new TestSession(temp));
    if (cls == null) {
        testMap = IndirectCollectionsFactory.createIndirectMap();
    } else {
        try {
            testMap = cls.getConstructor().newInstance();
        } catch (ReflectiveOperationException e) {
            throw new RuntimeException(e);
        }
    }
    testMap.setValueHolder(vh);
    if (useListener) {
        testMapLsn = new Listener();
        testMap._persistence_setPropertyChangeListener(testMapLsn);
    }
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) ValueHolderInterface(org.eclipse.persistence.indirection.ValueHolderInterface) Hashtable(java.util.Hashtable) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) QueryBasedValueHolder(org.eclipse.persistence.internal.indirection.QueryBasedValueHolder) Before(org.junit.Before)

Example 60 with DatabaseRecord

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

the class MappedInteraction method buildRow.

/**
 * Build a database row from the record returned from the interaction.
 */
@Override
public AbstractRecord buildRow(jakarta.resource.cci.Record record, EISAccessor accessor) {
    if (record == null) {
        return null;
    }
    AbstractRecord row = null;
    if (record instanceof IndexedRecord) {
        IndexedRecord indexedRecord = (IndexedRecord) record;
        if (indexedRecord.isEmpty()) {
            return null;
        }
        if (indexedRecord.get(0) instanceof jakarta.resource.cci.Record) {
            return buildRow((jakarta.resource.cci.Record) indexedRecord.get(0), accessor);
        }
    }
    // If not a mapped record then just put it as a result value in the row.
    if (!(record instanceof MappedRecord)) {
        row = new DatabaseRecord(1);
        row.put(getOutputResultPath(), record);
        return row;
    }
    MappedRecord mappedRecord = (MappedRecord) record;
    // or a translation of the output with the output arguments.
    if (hasOutputArguments()) {
        row = new DatabaseRecord(getOutputArgumentNames().size());
        for (int index = 0; index < getOutputArgumentNames().size(); index++) {
            DatabaseField field = getOutputArguments().get(index);
            row.put(field, mappedRecord.get(getOutputArgumentNames().get(index)));
        }
        return row;
    } else if (getOutputResultPath().length() > 0) {
        // Extract the desired nested record from the output.
        mappedRecord = (MappedRecord) mappedRecord.get(getOutputResultPath());
    }
    // Wrapped the record in a database to avoid lossing any information in conversion to database row,
    // also gets around problem of some adatpers not supporting keySet or entrySet.
    row = new EISMappedRecord(mappedRecord, accessor);
    return row;
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) jakarta.resource(jakarta.resource) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) jakarta.resource.cci(jakarta.resource.cci) 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