Example #1
0
 /** Construct a log entry for writing to the log. */
 public INLogEntry(T in) {
   setLogType(in.getLogType());
   this.in = in;
   this.dbId = in.getDatabase().getId();
   this.prevFullLsn = in.getLastFullVersion();
   this.prevDeltaLsn = in.getLastDeltaVersion();
 }
  @SuppressWarnings("unchecked")
  public static <T extends DatabaseObject> T fetch(T instance) {
    Database database = instance.getDatabase();
    Object[] ids;

    synchronized (STUBS) {
      ids = STUBS.get(instance);
    }

    if (database == null || ids == null) {
      return instance;
    }

    AnnotatedRecordMapper<? extends Object> mapper = create(instance.getClass());

    String whereClause = "";

    for (String fieldName : mapper.getIdColumnNames()) {
      if (!whereClause.isEmpty()) {
        whereClause += " AND ";
      }
      whereClause += fieldName + "=?";
    }

    try (Transaction transaction = database.beginReadOnlyTransaction()) {
      return (T) transaction.selectUnique(instance.getClass(), whereClause, ids);
    }
  }