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 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 test() {
    Session session = getSession();
    UnitOfWork uow = session.acquireUnitOfWork();
    uow.setShouldNewObjectsBeCached(true);

    Weather weather = new Weather();
    weather.setStormPattern("Something really bad");
    weather.id = 0;
    ReadObjectQuery query = new ReadObjectQuery(weather);
    query.checkCacheOnly();
    Weather weatherClone = (Weather) uow.registerObject(weather);
    weather = (Weather) uow.executeQuery(query);
    zeroFailed = weather == null;

    Weather weatherNeg = new Weather();
    weatherNeg.setStormPattern("Something really bad below zero");
    weatherNeg.id = -1;
    ReadObjectQuery queryNeg = new ReadObjectQuery(weatherNeg);
    queryNeg.checkCacheOnly();
    Weather weatherNegClone = (Weather) uow.registerObject(weatherNeg);
    weatherNeg = (Weather) uow.executeQuery(queryNeg);
    negativeFailed = weatherNeg == null;

    if (keepSequencing) {
      uow.assignSequenceNumbers();
      zeroOverridden = weatherClone.id != 0;
      negativeOverridden = weatherNegClone.id != -1;
    }
  }
 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 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 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 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 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 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 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 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 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;
 }
  protected void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    ReadObjectQuery query = new ReadObjectQuery(Employee.class);
    query.setLockMode(ObjectLevelReadQuery.LOCK_NOWAIT);
    Employee emp = (Employee) uow.executeQuery(query);

    emp.setSalary(emp.getSalary() + 1);
    uow.commit();
  }
 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;
 }
  /**
   * 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 void test() {

    ReadObjectQuery query = new ReadObjectQuery();
    query.setReferenceClass(Employee.class);
    query.setExampleObject(employee);
    query.setQueryByExamplePolicy(policy);
    Employee emp = new Employee();
    emp = (Employee) getSession().executeQuery(query);
    if (!(emp.getFirstName().charAt(0) == 'J')
        && (emp.getFirstName().charAt(3) == 'l')
        && (emp.getLastName().charAt(0) == 'M')) {
      throw (new TestErrorException("Error in using specail operators."));
    }
    if (!(emp.getSalary() < 60000)) {
      throw (new TestErrorException("Error is using spcial operators."));
    }
  }
  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;
  }
  public void setup() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    getAbstractSession().beginTransaction();

    descriptor = getSession().getProject().getDescriptors().get(Employee.class);

    // Read Object
    readObjectQuery = descriptor.getQueryManager().getReadObjectQuery();
    QueryRedirector redirector =
        new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "readObject");
    ReadObjectQuery roq = new ReadObjectQuery(descriptor.getJavaClass());
    roq.setRedirector(redirector);
    descriptor.getQueryManager().setReadObjectQuery(roq);

    // Read All
    readAllQuery = descriptor.getQueryManager().getReadAllQuery();
    redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "readAll");
    ReadAllQuery raq = new ReadAllQuery(descriptor.getJavaClass());
    raq.setRedirector(redirector);
    descriptor.getQueryManager().setReadAllQuery(raq);

    // Delete Object
    deleteObjectQuery = descriptor.getQueryManager().getDeleteQuery();
    redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "deleteObject");
    DeleteObjectQuery doq = new DeleteObjectQuery();
    doq.setRedirector(redirector);
    descriptor.getQueryManager().setDeleteQuery(doq);

    // Insert Object
    insertQuery = descriptor.getQueryManager().getInsertQuery();
    redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "insertObject");
    InsertObjectQuery ioq = new InsertObjectQuery();
    ioq.setRedirector(redirector);
    descriptor.getQueryManager().setInsertQuery(ioq);

    // Update Object
    updateQuery = descriptor.getQueryManager().getUpdateQuery();
    redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "updateObject");
    UpdateObjectQuery uoq = new UpdateObjectQuery();
    uoq.setRedirector(redirector);
    descriptor.getQueryManager().setUpdateQuery(uoq);
  }
  public void setup() {
    project = new EmployeeProject();
    ClassDescriptor descriptor =
        (ClassDescriptor)
            project
                .getDescriptors()
                .get(org.eclipse.persistence.testing.models.employee.domain.Employee.class);

    descriptor.disableCacheHits();

    //	ReadObjectQuery query = new ReadObjectQuery(Employee.class);
    //	descriptor.getQueryManager().addQuery("UndefinedQuery", query);

    ReadObjectQuery query = new ReadObjectQuery(Employee.class);
    query.maintainCache();
    descriptor.getQueryManager().addQuery("TrueQuery", query);

    query = new ReadObjectQuery(Employee.class);
    query.dontMaintainCache();
    descriptor.getQueryManager().addQuery("FalseQuery", query);
  }
  public void verify() {
    ClassDescriptor descriptor =
        (ClassDescriptor)
            project
                .getDescriptors()
                .get(org.eclipse.persistence.testing.models.employee.domain.Employee.class);

    // Here we test the maintainCache setting.  This should override any other settings.
    ReadObjectQuery query = (ReadObjectQuery) descriptor.getQueryManager().getQuery("TrueQuery");
    if /*getSession()*/ (!query.shouldMaintainCache() || !query.shouldMaintainCache()) {
      throw new TestErrorException(
          "Project read from XML should be set to maintainCache, but is not.");
    }

    // Here we test the donMaintainceCacheSetting.  This should override other settings.
    query = (ReadObjectQuery) descriptor.getQueryManager().getQuery("FalseQuery");
    if /*getSession()*/ (query.shouldMaintainCache() || query.shouldMaintainCache()) {
      throw new TestErrorException(
          "Project read from XML should be set not to maintainCache, but it does.");
    }
  }
 /** INTERNAL: Select one object of any concrete subclass. */
 protected Object selectOneObject(ReadObjectQuery query) throws DescriptorException {
   ReadObjectQuery concreteQuery = (ReadObjectQuery) query.clone();
   Class javaClass = descriptor.getJavaClass();
   concreteQuery.setReferenceClass(javaClass);
   concreteQuery.setDescriptor(descriptor);
   return query.getSession().executeQuery(concreteQuery, concreteQuery.getTranslationRow());
 }
 protected Object readObjectFromRow(Session session, ClassDescriptor desc, Record row) {
   if (desc.hasInheritance()) {
     Class newClass =
         desc.getInheritancePolicy().classFromRow((DatabaseRecord) row, (AbstractSession) session);
     desc = session.getClassDescriptor(newClass);
   }
   Object object = desc.getObjectBuilder().buildNewInstance();
   ReadObjectQuery query = new ReadObjectQuery();
   query.setSession((AbstractSession) session);
   for (Enumeration mappings = desc.getMappings().elements(); mappings.hasMoreElements(); ) {
     DatabaseMapping mapping = (DatabaseMapping) mappings.nextElement();
     mapping.readFromRowIntoObject(
         (DatabaseRecord) row,
         query.getJoinedAttributeManager(),
         object,
         null,
         query,
         query.getSession(),
         true);
   }
   return object;
 }
 public void executeUntilStopped() {
   Session session =
       ConcurrentTestRefreshWithOptimisticLocking.server.serverSession.acquireClientSession();
   DeadLockAddress address =
       (DeadLockAddress)
           session.readObject(
               org.eclipse.persistence.testing.tests.clientserver.DeadLockAddress.class);
   DeadLockEmployee employee = (DeadLockEmployee) session.readObject(DeadLockEmployee.class);
   ReadObjectQuery query;
   if ((this.index % 2) != 0) {
     query = new ReadObjectQuery(address);
     query.refreshIdentityMapResult();
     query.setCascadePolicy(DatabaseQuery.CascadeAllParts);
   } else {
     query = new ReadObjectQuery(employee);
     query.refreshIdentityMapResult();
     query.setCascadePolicy(DatabaseQuery.CascadeAllParts);
   }
   while (ConcurrentTestRefreshWithOptimisticLocking.execute) {
     ConcurrentTestRefreshWithOptimisticLocking.timeList[this.index] = System.currentTimeMillis();
     session.executeQuery(query);
   }
   // System.out.println("BeingShutDown");
 }
 public void buildReadOnlyQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   namedQuery.setIsReadOnly(true);
   queryManager.addQuery("readOnlyQuery", namedQuery);
 }
 public void buildRefreshIdentityMapResultsQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   namedQuery.setShouldRefreshIdentityMapResult(true);
   queryManager.addQuery("refreshIdentityMapResultsQuery", namedQuery);
 }
 public void buildCacheQueryResultsQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   namedQuery.setQueryResultsCachePolicy(new QueryResultsCachePolicy());
   queryManager.addQuery("cacheQueryResultsQuery", namedQuery);
 }
 public void buildMemoryQueryThrowExceptionQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   namedQuery.setInMemoryQueryIndirectionPolicy(new InMemoryQueryIndirectionPolicy(0));
   queryManager.addQuery("memoryQueryThrowExceptionQuery", namedQuery);
 }