public void test() {

    UnitOfWork uow = getSession().acquireUnitOfWork();
    UnitOfWork nestedUow1 = uow.acquireUnitOfWork();
    UnitOfWork nestedNestedUOW = nestedUow1.acquireUnitOfWork();

    Employee employee = (Employee) new EmployeePopulator().basicEmployeeExample1();
    employee.setId(new BigDecimal(15));
    Employee nestedEmployee = (Employee) nestedNestedUOW.registerObject(employee);
    nestedNestedUOW.commit();
    nestedUow1.commit();

    nestedUow1 = uow.acquireUnitOfWork();
    nestedNestedUOW = nestedUow1.acquireUnitOfWork();

    ReadObjectQuery query = new ReadObjectQuery();
    query.setReferenceClass(Employee.class);
    query.setSelectionCriteria(
        new org.eclipse.persistence.expressions.ExpressionBuilder()
            .get("id")
            .equal(new BigDecimal(15)));
    query.conformResultsInUnitOfWork();
    nestedEmployee = (Employee) nestedNestedUOW.executeQuery(query);

    nestedNestedUOW.deleteObject(nestedEmployee);
    nestedNestedUOW.commit();
    nestedUow1.commit();
    if (!((UnitOfWorkImpl) uow).getNewObjectsCloneToOriginal().isEmpty()) {
      throw new TestErrorException("Failed to unregister the Object in the nested unit of work");
    }
  }
 public static DatabaseQuery buildPersistenceTestEqualByteQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(ConversionDataObject.class);
   Expression expression = builder.get("aByte").equal(new Byte((byte) 3));
   ReadObjectQuery query = new ReadObjectQuery(ConversionDataObject.class);
   query.setSelectionCriteria(expression);
   return query;
 }
  public void setup() {
    if (getSession().getPlatform().isDB2()) {
      throw new TestWarningException(
          "This test is not supposed to work with DB2. "
              + org.eclipse.persistence.internal.helper.Helper.cr()
              + "\t\tBecause as expected, sql string contains (t0.F_NAME = NULL) when the query is executed the second time with argument null, and '=NULL' is illegal syntax on DB2."
              + org.eclipse.persistence.internal.helper.Helper.cr()
              + "\t\tHence, executing the query would result in runtime exception.");
    }
    query =
        (ReadObjectQuery)
            getSession()
                .getDescriptor(
                    org.eclipse.persistence.testing.models.employee.domain.Employee.class)
                .getQueryManager()
                .getQuery("shouldPrepareQuery");

    queryCopy = (ReadObjectQuery) query.clone();
    ExpressionBuilder ex = new ExpressionBuilder();
    queryCopy.setSelectionCriteria(ex.get("firstName").equal(ex.getParameter("firstName1")));
    queryCopy.addArgument("firstName1");

    vec = new Vector();
    vec.add("Bob");
    getSession().executeQuery(queryCopy, vec);
  }
 public static DatabaseQuery buildPersistenceTestGetLessThanEqualQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(Employee.class);
   Expression expression = builder.get("salary").lessThanEqual(15);
   ReadObjectQuery query = new ReadObjectQuery(Employee.class);
   query.setSelectionCriteria(expression);
   return query;
 }
 public static DatabaseQuery buildPersistenceTestGetNotNullQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(Employee.class);
   Expression expression = builder.get("firstName").notNull();
   ReadObjectQuery query = new ReadObjectQuery(Employee.class);
   query.setSelectionCriteria(expression);
   return query;
 }
 public static DatabaseQuery buildPersistenceTestGetNotLikeQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(Employee.class);
   Expression expression = builder.get("address").get("city").notLike("Toronto");
   ReadObjectQuery query = new ReadObjectQuery(Employee.class);
   query.setSelectionCriteria(expression);
   return query;
 }
 public static DatabaseQuery buildPersistenceTestEqualPByteArrayQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(ConversionDataObject.class);
   Expression expression = builder.get("aPByteArray").equal(new byte[] {7, 8, 9});
   ReadObjectQuery query = new ReadObjectQuery(ConversionDataObject.class);
   query.setSelectionCriteria(expression);
   return query;
 }
 public void verify() {
   getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
   holder = (DirectEntityMapHolder) getSession().readObject(holder);
   if (!compareObjects(holder, changedHolder)) {
     throw new TestErrorException("Objects do not match reinitialize");
   }
   if (holder.getDirectToEntityMap().size() != 2) {
     throw new TestErrorException("Incorrect Number of MapEntityValues was read.");
   }
   EntityMapValue value = (EntityMapValue) holder.getDirectToEntityMap().get(new Integer(33));
   if (value.getId() != 3) {
     throw new TestErrorException("MapEntityValue was not added properly.");
   }
   value = (EntityMapValue) holder.getDirectToEntityMap().get(11);
   if (value != null) {
     throw new TestErrorException("Deleted EntityMapValue still around.");
   }
   if (mapping.isPrivateOwned()) {
     ReadObjectQuery query = new ReadObjectQuery(EntityMapValue.class);
     ExpressionBuilder values = new ExpressionBuilder();
     Expression criteria = values.get("id").equal(1);
     query.setSelectionCriteria(criteria);
     value = (EntityMapValue) getSession().executeQuery(query);
     if (value != null) {
       throw new TestErrorException("PrivateOwned EntityMapValue was not deleted.");
     }
   }
 }
 public static DatabaseQuery buildPersistenceTestEmptyStringAndNull() {
   ExpressionBuilder builder = new ExpressionBuilder(Employee.class);
   Expression expression =
       builder.get("firstName").lessThan(null).or(builder.get("firstName").equal(""));
   ReadObjectQuery query = new ReadObjectQuery(Employee.class);
   query.setSelectionCriteria(expression);
   return query;
 }
 public static DatabaseQuery buildPersistenceTestEqualTimeQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(ConversionDataObject.class);
   java.sql.Time date = new java.sql.Time(994007776134L);
   Expression expression = builder.get("aTime").equal(date);
   ReadObjectQuery query = new ReadObjectQuery(ConversionDataObject.class);
   query.setSelectionCriteria(expression);
   return query;
 }
 public static DatabaseQuery buildPersistenceTestEqualBigIntegerQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(ConversionDataObject.class);
   java.math.BigInteger num = new java.math.BigInteger("9");
   Expression expression = builder.get("aBigInteger").equal(num);
   ReadObjectQuery query = new ReadObjectQuery(ConversionDataObject.class);
   query.setSelectionCriteria(expression);
   return query;
 }
 public static DatabaseQuery buildPersistenceTestGreaterThanEqualDateQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(Employee.class);
   GregorianCalendar month = new GregorianCalendar();
   month.set(2001, 6, 1, 11, 24, 36);
   Expression expression = builder.get("period").get("startDate").greaterThanEqual(month);
   ReadObjectQuery query = new ReadObjectQuery(Employee.class);
   query.setSelectionCriteria(expression);
   return query;
 }
 public static DatabaseQuery buildPersistenceTestEqualCalendarQuery() {
   ExpressionBuilder builder = new ExpressionBuilder(ConversionDataObject.class);
   GregorianCalendar month = new GregorianCalendar();
   month.set(2001, 6, 1, 11, 24, 36);
   Expression expression = builder.get("aCalendar").equal(month);
   ReadObjectQuery query = new ReadObjectQuery(ConversionDataObject.class);
   query.setSelectionCriteria(expression);
   return query;
 }
  /**
   * INTERNAL: Return the value of the field from the row or a value holder on the query to obtain
   * the object. Check for batch + aggregation reading.
   */
  @Override
  public Object valueFromRow(
      AbstractRecord row,
      JoinedAttributeManager joinManager,
      ObjectBuildingQuery sourceQuery,
      AbstractSession executionSession)
      throws DatabaseException {
    // If any field in the foreign key is null then it means there are no referenced objects
    for (Enumeration enumeration = getFields().elements(); enumeration.hasMoreElements(); ) {
      DatabaseField field = (DatabaseField) enumeration.nextElement();
      if (row.get(field) == null) {
        return getIndirectionPolicy().nullValueFromRow();
      }
    }

    if (getTypeField() != null) {
      // If the query used batched reading, return a special value holder,
      // or retrieve the object from the query property.
      if (sourceQuery.isReadAllQuery()
          && (((ReadAllQuery) sourceQuery).isAttributeBatchRead(getDescriptor(), getAttributeName())
              || shouldUseBatchReading())) {
        return batchedValueFromRow(row, ((ReadAllQuery) sourceQuery));
      }

      // If the field is empty we cannot load the object because we do not know what class it will
      // be
      if (row.get(getTypeField()) == null) {
        return getIndirectionPolicy().nullValueFromRow();
      }
      Class implementerClass =
          (Class) getImplementorForType(row.get(getTypeField()), executionSession);
      ReadObjectQuery query = (ReadObjectQuery) getSelectionQuery().clone();
      query.setReferenceClass(implementerClass);
      query.setSelectionCriteria(getSelectionCriteria());
      query.setDescriptor(null); // Must set to null so the right descriptor is used

      if (sourceQuery.isObjectLevelReadQuery()
          && (sourceQuery.shouldCascadeAllParts()
              || (sourceQuery.shouldCascadePrivateParts() && isPrivateOwned())
              || (sourceQuery.shouldCascadeByMapping() && this.cascadeRefresh))) {
        query.setShouldRefreshIdentityMapResult(sourceQuery.shouldRefreshIdentityMapResult());
        query.setCascadePolicy(sourceQuery.getCascadePolicy());
        query.setShouldMaintainCache(sourceQuery.shouldMaintainCache());
        // For flashback.
        if (((ObjectLevelReadQuery) sourceQuery).hasAsOfClause()) {
          query.setAsOfClause(((ObjectLevelReadQuery) sourceQuery).getAsOfClause());
        }

        // CR #4365 - used to prevent infinit recursion on refresh object cascade all
        query.setQueryId(sourceQuery.getQueryId());
      }

      return getIndirectionPolicy().valueFromQuery(query, row, executionSession);
    } else {
      return super.valueFromRow(row, joinManager, sourceQuery, executionSession);
    }
  }
 /** Read employee and clear the cache, test database read. */
 public void test() throws Exception {
   ReadObjectQuery query = new ReadObjectQuery(Employee.class);
   ExpressionBuilder employee = new ExpressionBuilder();
   query.setSelectionCriteria(
       employee
           .get("firstName")
           .equal("Brendan")
           .and(employee.get("salary").equal(100000))
           .and(employee.get("address").get("city").like("%pean%"))
           .and(employee.anyOf("phoneNumbers").get("type").equal("Home")));
   query.checkCacheOnly();
   Employee result = (Employee) getSession().executeQuery(query);
 }
 protected void test() throws Throwable {
   // query to read emp_1
   ReadObjectQuery query = new ReadObjectQuery(Employee.class);
   ExpressionBuilder builder = query.getExpressionBuilder();
   Expression exp =
       builder.get("firstName").equal(firstName).and(builder.get("lastName").equal("1"));
   query.setSelectionCriteria(exp);
   // executing the query used to cause StackOverflow
   Employee empRead = (Employee) getSession().executeQuery(query);
   // the following line is provided just in case you need to put a break point after query
   // execution
   empRead.getManagedEmployees().size();
   query = null;
 }
  public static ReadObjectTest getReadInterfaceObjectTest() {
    TestSuite suite = new TestSuite();
    PopulationManager manager = PopulationManager.getDefaultManager();
    Contact contact = ((Employee) manager.getObject(Employee.class, "example1")).getContact();

    ExpressionBuilder builder = new ExpressionBuilder();
    Expression expression = builder.get("id").equal(contact.getEmp().getId());

    ReadObjectQuery query = new ReadObjectQuery();
    query.setReferenceClass(ContactHolder.class);
    query.setSelectionCriteria(expression);

    ReadObjectTest test = new ReadObjectTest(contact.getEmp());
    test.setQuery(query);

    return test;
  }