Search in sources :

Example 96 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class SimpleConcatTestWithConstantsLiteralFirst method setup.

@Override
public void setup() {
    Employee emp = (Employee) getSomeEmployees().firstElement();
    String partOne;
    String ejbqlString;
    partOne = emp.getFirstName();
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause = builder.literal("'Smith'").concat(builder.get("firstName")).like("Smith" + partOne);
    ReadAllQuery raq = new ReadAllQuery();
    raq.setReferenceClass(Employee.class);
    raq.setSelectionCriteria(whereClause);
    Vector employees = (Vector) getSession().executeQuery(raq);
    ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE ";
    ejbqlString = ejbqlString + "CONCAT(\"Smith\",emp.firstName) LIKE ";
    ejbqlString = ejbqlString + "\"Smith" + partOne + "\"";
    setEjbqlString(ejbqlString);
    setOriginalOject(employees);
    super.setup();
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Expression(org.eclipse.persistence.expressions.Expression) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector)

Example 97 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class OracleNativeSeqInitTest method setup.

@Override
public void setup() {
    if (!getSession().getPlatform().supportsSequenceObjects()) {
        throw new TestWarningException("This test requires a platform that supports sequence objects");
    }
    ClassDescriptor descriptor = getSession().getDescriptor(Employee.class);
    if (!descriptor.usesSequenceNumbers()) {
        throw new TestWarningException("Employee doesn't use sequencing");
    }
    originalSequence = getSession().getPlatform().getSequence(descriptor.getSequenceNumberName());
    usesNativeSequencingOriginal = (originalSequence instanceof NativeSequence || (originalSequence instanceof DefaultSequence && getSession().getPlatform().getDefaultSequence() instanceof NativeSequence)) && !originalSequence.shouldAcquireValueAfterInsert();
    if (!usesNativeSequencingOriginal) {
        NativeSequence newSequence = new NativeSequence(originalSequence.getName(), originalSequence.getPreallocationSize());
        newSequence.onConnect(originalSequence.getDatasourcePlatform());
        getAbstractSession().getPlatform().addSequence(newSequence);
        sequence = newSequence;
    } else {
        sequence = originalSequence;
    }
    seqPreallocationSizeOriginal = originalSequence.getPreallocationSize();
    lastSeqNumberOriginal = getSession().getNextSequenceNumberValue(Employee.class).intValue() - 1;
    usesBatchWritingOriginal = getSession().getPlatform().usesBatchWriting();
    shouldCacheAllStatementsOriginal = getSession().getPlatform().shouldCacheAllStatements();
    getDatabaseSession().getSequencingControl().initializePreallocated();
    sequenceDefinition = new SequenceObjectDefinition(sequence);
    sequenceDefinition.setQualifier(getSession().getLogin().getTableQualifier());
    if (shouldUseSchemaManager) {
        schemaManager = new SchemaManager(getDatabaseSession());
        // make sure that upcoming DROP and CREATE haven't been cached
        // and therefore for sure will go through
        getSession().getPlatform().setShouldCacheAllStatements(false);
        // This is the worst case scenario settings - SchemaManager should handle it.
        getSession().getPlatform().setUsesBatchWriting(true);
        getSession().getPlatform().setShouldCacheAllStatements(true);
    } else {
        getSession().getPlatform().setUsesBatchWriting(false);
        getSession().getPlatform().setShouldCacheAllStatements(false);
    }
    // all three modes start with dropping an existing sequence (if any)
    try {
        drop();
    } catch (DatabaseException exception) {
    // Ignore already deleted
    }
    if (mode == DROP_CREATE) {
        // sequence doesn't exist.
        // create sequence with seqPreallocationSize.
        // note that both increment and starting value are set to
        // sequenceDefinition.getIncrement()
        sequence.setInitialValue(1);
        sequence.setPreallocationSize(seqPreallocationSize);
        create();
        // next available sequence number.
        idExpected = 1;
    } else if (mode == CREATE_CREATE) {
        // sequence doesn't exist,
        // create sequence with seqPreallocationSizeOld
        // note that both increment and starting value are set to
        // sequenceDefinition.getIncrement()
        sequence.setInitialValue(1);
        sequence.setPreallocationSize(seqPreallocationSizeOld);
        create();
        // now sequence exists,
        // create sequence with seqPreallocationSize
        // Note that createOnDatabase will call alterOnDatabase
        sequence.setInitialValue(1);
        sequence.setPreallocationSize(seqPreallocationSize);
        create();
        // next available sequence number.
        // note that the second createOnDatabase selects NEXTVAL during existance check,
        // because it is the first call to NEXTVAL, the starting sequence value is returned,
        // and this value was set to seqPreallocationSizeOld by the first createOnDatabase
        idExpected = 1 + seqPreallocationSizeOld;
    } else if (mode == NEXTVAL_ALTER) {
        // sequence doesn't exist,
        // create sequence with seqPreallocationSizeOld
        // note that both increment and starting value are set to
        // sequenceDefinition.getIncrement()
        sequence.setInitialValue(1);
        sequence.setPreallocationSize(seqPreallocationSizeOld);
        create();
        // now sequence exists,
        // select NEXTVAL
        // because it is the first call to NEXTVAL, the starting sequence value is returned,
        // and this value was set to seqPreallocationSizeOld by the first createOnDatabase
        sequenceDefinition.checkIfExist((AbstractSession) getSession());
        // alter increment of sequence with seqPreallocationSize.
        sequence.setInitialValue(1);
        sequence.setPreallocationSize(seqPreallocationSize);
        alter();
        // next available sequence number.
        // because there was just one call to NEXTVAL, the starting sequence value is returned,
        // and this value was set to seqPreallocationSizeOld by createOnDatabase
        idExpected = 1 + seqPreallocationSizeOld;
    } else if (mode == CREATE_ALTER) {
        // sequence doesn't exist,
        // create sequence with seqPreallocationSizeOld
        // note that both increment and starting value are set to
        // sequenceDefinition.getIncrement()
        sequence.setInitialValue(1);
        sequence.setPreallocationSize(seqPreallocationSizeOld);
        create();
        // alter increment of sequence with seqPreallocationSize.
        sequence.setInitialValue(1);
        sequence.setPreallocationSize(seqPreallocationSize);
        alter();
        // next available sequence number.
        idExpected = 1;
    }
    getSession().getPlatform().getSequence(descriptor.getSequenceNumberName()).setPreallocationSize(seqPreallocationSize);
}
Also used : NativeSequence(org.eclipse.persistence.sequencing.NativeSequence) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DefaultSequence(org.eclipse.persistence.sequencing.DefaultSequence) SequenceObjectDefinition(org.eclipse.persistence.tools.schemaframework.SequenceObjectDefinition) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager)

Example 98 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class LowerCaseForCaseInsensitiveTest method testEqualsIgnoreCase.

public void testEqualsIgnoreCase(boolean checkCacheOnly) {
    String value = "s" + uUmlaut + sharpS + "IG";
    ReadAllQuery query = new ReadAllQuery(Employee.class);
    if (checkCacheOnly) {
        query.checkCacheOnly();
    }
    query.setSelectionCriteria(new ExpressionBuilder().get("lastName").equalsIgnoreCase(value));
    Vector<Employee> results = (Vector<Employee>) getSession().executeQuery(query);
    assertEquals("One result expected (checkCacheOnly=" + checkCacheOnly + ")", 1, results.size());
    assertTrue("Persisted employee expected in results (checkCacheOnly=" + checkCacheOnly + ")", results.contains(employee));
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector)

Example 99 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class QueryTimeoutBatchDescriptorQueryManagerTest method registerObjects.

/**
 * Iterate and register a number of objects in the unitOfWork
 */
@Override
protected List<Employee> registerObjects(UnitOfWork uow) {
    List<Employee> objectListForEditing = new ArrayList<Employee>();
    Address address = null;
    Employee employee = null;
    for (int i = 0; i < getNumberOfInserts(); i++) {
        address = new Address();
        address.setCity(new StringBuffer("city").append(i).toString());
        address.setProvince(new StringBuffer("province").append(i).toString());
        employee = new Employee();
        employee.setFirstName(new StringBuffer("first").append(i).toString());
        employee.setLastName(new StringBuffer("last").append(i).toString());
        // employee.setId(new java.math.BigDecimal(i));
        employee.setAddress(address);
        uow.registerObject(employee);
        // Use the return clone for editing
        objectListForEditing.add(employee);
        // Test framework callback
        // Set the timeout at the descriptor level for each object
        setDescriptorLevelQueryTimeout(uow.getDescriptor(employee).getDescriptorQueryManager());
        setDescriptorLevelQueryTimeout(uow.getDescriptor(address).getDescriptorQueryManager());
        // Test framework callback
        // Set the timeout on each query object (already defined)
        setQueryLevelQueryTimeout(uow, employee);
        setQueryLevelQueryTimeout(uow, address);
        // Add custom insertQuery
        InsertObjectQuery query = new InsertObjectQuery();
        // queryCount++;
        // insert into employee (emp_id, version) SELECT 40003, SUM(e.address_id) as version from address e, address b, address b, address c, address c;
        StringBuffer sBuffer = new StringBuffer(getQuerySQLPrefix());
        sBuffer.append(getCurrentIDSequence() + i);
        // sBuffer.append(i);
        sBuffer.append(getQuerySQLPostfix());
        query.setSQLString(sBuffer.toString());
        // Override parent
        query.setQueryTimeout(getChildQueryTimeout());
        // We don't set the f_name parameter so Ignore: WARNING: Missing Query parameter for named argument: 1 null will be substituted.
        uow.getDescriptor(employee).getDescriptorQueryManager().setInsertQuery(query);
    }
    return objectListForEditing;
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Address(org.eclipse.persistence.testing.models.employee.domain.Address) ArrayList(java.util.ArrayList) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 100 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class LowerCaseForCaseInsensitiveTest method setup.

@Override
public void setup() {
    // set the Expression default upper case value to lower case
    Expression.shouldUseUpperCaseForIgnoreCase = false;
    UnitOfWork uow = getSession().acquireUnitOfWork();
    employee = new Employee();
    Employee employeeClone = (Employee) uow.registerObject(employee);
    employeeClone.setFirstName("Heinz");
    employeeClone.setLastName("S\u00fc\u00dfig");
    employeeClone.setMale();
    uow.commit();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee)

Aggregations

Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)220 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)79 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)52 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)40 Vector (java.util.Vector)34 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)32 SmallProject (org.eclipse.persistence.testing.models.employee.domain.SmallProject)29 Address (org.eclipse.persistence.testing.models.employee.domain.Address)24 PhoneNumber (org.eclipse.persistence.testing.models.employee.domain.PhoneNumber)22 Expression (org.eclipse.persistence.expressions.Expression)21 LargeProject (org.eclipse.persistence.testing.models.employee.domain.LargeProject)18 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)16 TestSuite (org.eclipse.persistence.testing.framework.TestSuite)15 PopulationManager (org.eclipse.persistence.tools.schemaframework.PopulationManager)15 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)14 Project (org.eclipse.persistence.testing.models.employee.domain.Project)14 EmployeePopulator (org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator)11 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)9 ValidationException (org.eclipse.persistence.exceptions.ValidationException)9 EmploymentPeriod (org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod)9