public void testStackContainerPolicy() {
    DataReadQuery query = this.buildNewQuery();
    query.useCollectionClass(Stack.class);

    stack = (Stack) getSession().executeQuery(query);
    // if we get here, we must not have generated a ClassCastException
    Record row = (Record) stack.peek();
    if (row.get("CUSTNAME") == null) {
      throw new TestErrorException("missing data");
    }
  }
  public void getChange(
      Record row,
      DatabaseMapping mapping,
      Session session,
      Object object1,
      Object object2,
      boolean useUOW,
      WriteType writeType) {
    if (mapping.isAggregateObjectMapping()) {
      Object aggregate1 = mapping.getAttributeValueFromObject(object1);
      Object aggregate2 = mapping.getAttributeValueFromObject(object2);
      if (aggregate1 == null && aggregate2 == null) {
        if (!useUOW) {
          mapping.writeFromObjectIntoRow(
              object2, (DatabaseRecord) row, (AbstractSession) session, writeType);
        }
      } else if (aggregate1 != null
          && aggregate2 != null
          && aggregate1.getClass().equals(aggregate2.getClass())) {
        ClassDescriptor desc = ((AggregateObjectMapping) mapping).getReferenceDescriptor();
        getChange(row, session, aggregate1, aggregate2, desc, useUOW, writeType);
      } else {
        mapping.writeFromObjectIntoRow(
            object2, (DatabaseRecord) row, (AbstractSession) session, writeType);
      }
    } else {
      Record row1 = new DatabaseRecord();
      Record row2 = new DatabaseRecord();
      mapping.writeFromObjectIntoRow(
          object1, (DatabaseRecord) row1, (AbstractSession) session, writeType);
      mapping.writeFromObjectIntoRow(
          object2, (DatabaseRecord) row2, (AbstractSession) session, writeType);

      for (int i = 0; i < row1.size(); i++) {
        DatabaseField field = (DatabaseField) ((DatabaseRecord) row1).getFields().elementAt(i);
        Object valueBefore = ((DatabaseRecord) row1).getValues().elementAt(i);
        Object valueAfter = row2.get(field);
        boolean changed;
        if (valueAfter == null) {
          changed = valueBefore != null;
        } else {
          changed = !valueAfter.equals(valueBefore);
        }
        if (changed) {
          row.put(field, valueAfter);
        }
      }
    }
  }
Example #3
0
  /**
   * Builds the normalHours Vector. IMPORTANT: This method builds the value but does not set it. The
   * mapping will set it using method or direct access as defined in the descriptor.
   */
  public Time[] buildNormalHours(Record row, Session session) {
    Time[] hours = new Time[2];

    /**
     * This conversion allows for the database type not to match, i.e. may be a Timestamp or String.
     */
    hours[0] =
        (Time)
            session
                .getDatasourcePlatform()
                .convertObject(row.get("START_TIME"), java.sql.Time.class);
    hours[1] =
        (Time)
            session.getDatasourcePlatform().convertObject(row.get("END_TIME"), java.sql.Time.class);
    return hours;
  }
 public Object getObjectForUpdate(
     Session session,
     Object objectToUpdateBeforeChange,
     Object objectToUpdateAfterChange,
     boolean useUOW) {
   ClassDescriptor desc = session.getClassDescriptor(objectToUpdateBeforeChange);
   Record rowBeforeChange =
       desc.getObjectBuilder()
           .buildRow(objectToUpdateBeforeChange, (AbstractSession) session, WriteType.UPDATE);
   Record rowAfterChange =
       desc.getObjectBuilder()
           .buildRow(objectToUpdateAfterChange, (AbstractSession) session, WriteType.UPDATE);
   Record rowChange = new DatabaseRecord();
   getChange(
       rowChange,
       session,
       objectToUpdateBeforeChange,
       objectToUpdateAfterChange,
       desc,
       useUOW,
       WriteType.UPDATE);
   Record rowReturn = getRowForUpdate(rowChange);
   if (rowReturn != null && !rowReturn.isEmpty()) {
     Record row = new DatabaseRecord(rowAfterChange.size());
     row.putAll(rowAfterChange);
     row.putAll(rowReturn);
     return readObjectFromRow(session, desc, row);
   } else {
     return objectToUpdateAfterChange;
   }
 }
  /** assume the stack has already been populated by the previous test */
  public void testCursoredStreamPolicy() {
    ValueReadQuery sizeQuery = new ValueReadQuery("select count(*) from ORD");

    DataReadQuery query = this.buildNewQuery();
    query.useCursoredStream(5, 5, sizeQuery);

    CursoredStream stream = (CursoredStream) getSession().executeQuery(query);

    // if we get here, we must not have generated a ClassCastException
    int count = 0;
    while (stream.hasMoreElements()) {
      count++;
      Record row = (Record) stream.nextElement();
      if (row.get("CUSTNAME") == null) {
        throw new TestErrorException("missing data");
      }
    }
    if (count != stack.size()) {
      throw new TestErrorException(
          "stream does not match stack - " + "expected: " + stack.size() + " actual: " + count);
    }
  }
 public Object getObjectForInsert(Session session, Object objectToInsert) {
   ClassDescriptor desc = session.getClassDescriptor(objectToInsert);
   Record rowToInsert =
       desc.getObjectBuilder()
           .buildRow(objectToInsert, (AbstractSession) session, WriteType.INSERT);
   Record rowReturn = getRowForInsert(rowToInsert);
   if (rowReturn != null && !rowReturn.isEmpty()) {
     Record row = new DatabaseRecord(rowToInsert.size());
     row.putAll(rowToInsert);
     row.putAll(rowReturn);
     return readObjectFromRow(session, desc, row);
   } else {
     return objectToInsert;
   }
 }
Example #7
0
 /** Calculates and sets the rate based on the values in the database row. */
 public void calculateRate(Record row) {
   this.rate = 0;
   if (((Boolean) row.get("HAS_LOCAL")).booleanValue()) this.rate += LOCAL_FLAG;
   if (((Boolean) row.get("HAS_LONG_DISTANCE")).booleanValue()) this.rate += LONG_DISTANCE_FLAG;
   if (((Boolean) row.get("HAS_DSL")).booleanValue()) this.rate += DSL_FLAG;
 }
  public String[] buildAttributeValue(Record record, Object object, Session session) {
    String startTime = (String) record.get("normal-hours/start-time/text()");
    String endTime = (String) record.get("normal-hours/end-time/text()");

    return new String[] {startTime, endTime};
  }