コード例 #1
0
 @Override
 void writeObject(Object o, EntityOutput output, boolean rawAccess) {
   if (rawAccess) {
     proxyFormat.writeObject(o, output, true);
   } else {
     PersistentProxy proxy = (PersistentProxy) proxyFormat.newInstance(null, false);
     proxy.initializeProxy(o);
     proxyFormat.writeObject(proxy, output, false);
   }
 }
コード例 #2
0
  private boolean assignPrimaryKeyInternal(Object entity, DatabaseEntry key)
      throws DatabaseException, RefreshException {

    /*
     * The keyFieldFormat is the format of a simple integer field.  For a
     * composite key class it is the contained integer field.  By writing
     * the Long sequence value using that format, the output data can then
     * be read to construct the actual key instance, whether it is a simple
     * or composite key class, and assign it to the primary key field in
     * the entity object.
     */
    if (entityFormat.isPriKeyNullOrZero(entity, rawAccess)) {
      Long value = sequence.get(null, 1);
      RecordOutput output = new RecordOutput(catalog, rawAccess);
      keyFieldFormat.writeObject(value, output, rawAccess);
      TupleBase.outputToEntry(output, key);
      EntityInput input =
          new RecordInput(
              catalog, rawAccess, null, 0, key.getData(), key.getOffset(), key.getSize());
      entityFormat.getReader().readPriKey(entity, input, rawAccess);
      return true;
    } else {
      return false;
    }
  }
  /**
   * Writes the formatId and object, and returns the bytes.
   *
   * <p>This is a special case of EntityOutput.writeObject for a top level entity. Special
   * treatments are: - The entity may not be null. - The entity is not checked for existence in the
   * visited object set; entities cannot be referenced by another entity.
   */
  static void writeEntity(
      Format format, Catalog catalog, Object entity, DatabaseEntry data, boolean rawAccess)
      throws RefreshException {

    RecordOutput output = new RecordOutput(catalog, rawAccess);
    output.registerEntity(entity);
    output.writePackedInt(format.getId());
    format.writeObject(entity, output, rawAccess);
    TupleBase.outputToEntry(output, data);
  }