コード例 #1
0
ファイル: InMem.java プロジェクト: victorbriz/rapidoid
 @SuppressWarnings("unchecked")
 private <T> T obj(Rec rec) {
   Class<T> destType = (Class<T>) rec.type;
   U.notNull(destType, "DB record type");
   T dest = data.constructor.create(destType);
   return (T) obj(rec, dest);
 }
コード例 #2
0
ファイル: InMem.java プロジェクト: victorbriz/rapidoid
  private long _insert(Object record, boolean failOnReadOnlyTx) {
    U.notNull(record, "record");
    secureInsert(record);

    sharedLock();
    try {
      if (failOnReadOnlyTx) {
        failIfReadonlyTx();
      }

      long id = data.ids.incrementAndGet();
      Beany.setId(record, id);

      // Optimistic concurrency control through the "version" property
      if (Beany.hasProperty(record, VERSION)) {
        // FIXME rollback version in TX fails
        Beany.setPropValue(record, VERSION, 1);
      }

      Date now = new Date();

      if (Beany.hasProperty(record, CREATED_BY)) {
        Beany.setPropValue(record, CREATED_BY, username());
      }

      if (Beany.hasProperty(record, CREATED_ON)) {
        Beany.setPropValue(record, CREATED_ON, now);
      }

      if (Beany.hasProperty(record, LAST_UPDATED_BY)) {
        Beany.setPropValue(record, LAST_UPDATED_BY, username());
      }

      if (Beany.hasProperty(record, LAST_UPDATED_ON)) {
        Beany.setPropValue(record, LAST_UPDATED_ON, now);
      }

      if (data.insideTx.get()) {
        if (data.txInsertions.putIfAbsent(id, INSERTION) != null) {
          throw new IllegalStateException("Cannot insert changelog record with existing ID: " + id);
        }
      }

      if (data.data.putIfAbsent(id, rec(record)) != null) {
        throw new IllegalStateException("Cannot insert record with existing ID: " + id);
      }

      updateChangesFromRels(record);

      data.lastChangedOn.set(System.currentTimeMillis());

      Log.audit("Inserted DB record", "id", id);
      return id;
    } finally {
      sharedUnlock();
    }
  }
コード例 #3
0
 @Override
 public long fromId() {
   Object holder = rel.getHolder();
   U.notNull(holder, "holder");
   return db.getIdOf(holder);
 }