예제 #1
0
 @Override
 public <E extends T> E refreshAll(E entity) {
   EntityProxy<E> proxy = context.proxyOf(entity, false);
   synchronized (proxy.syncObject()) {
     return context.read(proxy.type().getClassType()).refreshAll(entity, proxy);
   }
 }
예제 #2
0
 @SuppressWarnings("unchecked")
 @Override
 public <E extends T> E refresh(E entity, Attribute<?, ?>... attributes) {
   EntityProxy<E> proxy = context.proxyOf(entity, false);
   synchronized (proxy.syncObject()) {
     return context
         .read(proxy.type().getClassType())
         .refresh(entity, proxy, (Attribute<E, ?>[]) attributes);
   }
 }
예제 #3
0
 @Override
 public <E extends T> Void delete(E entity) {
   try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
     EntityProxy<E> proxy = context.proxyOf(entity, true);
     synchronized (proxy.syncObject()) {
       context.write(proxy.type().getClassType()).delete(entity, proxy);
       transaction.commit();
     }
   }
   return null;
 }
예제 #4
0
 @Override
 public <E extends T> E upsert(E entity) {
   try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
     EntityProxy<E> proxy = context.proxyOf(entity, true);
     synchronized (proxy.syncObject()) {
       EntityWriter<E, T> writer = context.write(proxy.type().getClassType());
       writer.upsert(entity, proxy);
       transaction.commit();
       return entity;
     }
   }
 }
예제 #5
0
 @SuppressWarnings("unchecked")
 @Override
 public <E extends T> E update(E entity, Attribute<?, ?>... attributes) {
   try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
     EntityProxy<E> proxy = context.proxyOf(entity, true);
     synchronized (proxy.syncObject()) {
       context
           .write(proxy.type().getClassType())
           .update(entity, proxy, (Attribute<E, ?>[]) attributes);
       transaction.commit();
       return entity;
     }
   }
 }
예제 #6
0
 @Override
 public <K, E extends T> K insert(E entity, @Nullable Class<K> keyClass) {
   try (TransactionScope transaction = new TransactionScope(transactionProvider)) {
     EntityProxy<E> proxy = context.proxyOf(entity, true);
     synchronized (proxy.syncObject()) {
       EntityWriter<E, T> writer = context.write(proxy.type().getClassType());
       GeneratedKeys<E> key = null;
       if (keyClass != null) {
         key = new GeneratedKeys<>(proxy.type().isImmutable() ? null : proxy);
       }
       writer.insert(entity, proxy, key);
       transaction.commit();
       if (key != null && key.size() > 0) {
         return keyClass.cast(key.get(0));
       }
     }
   }
   return null;
 }