Пример #1
0
 @Override
 public <E extends T> Selection<? extends Scalar<Integer>> count(Class<E> type) {
   checkClosed();
   Objects.requireNotNull(type);
   return new QueryElement<>(SELECT, entityModel, countOperation)
       .select(Count.count(type))
       .from(type);
 }
Пример #2
0
 @Override
 public <E extends T> Insertion<? extends Result<Tuple>> insert(Class<E> type) {
   checkClosed();
   Type<E> entityType = context.getModel().typeOf(type);
   Set<Expression<?>> keySelection = new LinkedHashSet<>();
   for (Attribute<E, ?> attribute : entityType.getKeyAttributes()) {
     keySelection.add((Expression<?>) attribute);
   }
   InsertReturningOperation operation = new InsertReturningOperation(context, keySelection);
   return new QueryElement<>(INSERT, entityModel, operation).from(type);
 }
Пример #3
0
 @Override
 public <V> V runInTransaction(Callable<V> callable, @Nullable TransactionIsolation isolation) {
   Objects.requireNotNull(callable);
   checkClosed();
   Transaction transaction = transactionProvider.get();
   if (transaction == null) {
     throw new TransactionException("no transaction");
   }
   try {
     transaction.begin(isolation);
     V result = callable.call();
     transaction.commit();
     return result;
   } catch (Exception e) {
     throw new RollbackException(e);
   }
 }
Пример #4
0
 @Override
 public <E extends T> Selection<? extends Result<E>> select(
     Class<E> type, QueryAttribute<?, ?>... attributes) {
   checkClosed();
   EntityReader<E, T> reader = context.read(type);
   Set<Expression<?>> selection;
   ResultReader<E> resultReader;
   if (attributes.length == 0) {
     selection = reader.defaultSelection();
     resultReader = reader.newResultReader(reader.defaultSelectionAttributes());
   } else {
     selection = new LinkedHashSet<>(Arrays.<Expression<?>>asList(attributes));
     resultReader = reader.newResultReader(attributes);
   }
   SelectOperation<E> select = new SelectOperation<>(context, resultReader);
   QueryElement<? extends Result<E>> query = new QueryElement<>(SELECT, entityModel, select);
   return query.select(selection).from(type);
 }
Пример #5
0
 @Override
 public <E extends T> Result<E> raw(Class<E> type, String query, Object... parameters) {
   checkClosed();
   return new RawEntityQuery<>(context, type, query, parameters).get();
 }
Пример #6
0
 @Override
 public Result<Tuple> raw(final String query, final Object... parameters) {
   checkClosed();
   return new RawTupleQuery(context, query, parameters).get();
 }
Пример #7
0
 @Override
 public Selection<? extends Scalar<Integer>> count(QueryAttribute<?, ?>... attributes) {
   checkClosed();
   return new QueryElement<>(SELECT, entityModel, countOperation).select(Count.count(attributes));
 }
Пример #8
0
 @Override
 public <E extends T> Deletion<? extends Scalar<Integer>> delete(Class<E> type) {
   checkClosed();
   return new QueryElement<>(DELETE, entityModel, updateOperation).from(type);
 }
Пример #9
0
 @Override
 public Deletion<? extends Scalar<Integer>> delete() {
   checkClosed();
   return new QueryElement<>(DELETE, entityModel, updateOperation);
 }
Пример #10
0
 @Override
 public Update<? extends Scalar<Integer>> update() {
   checkClosed();
   return new QueryElement<>(UPDATE, entityModel, updateOperation);
 }
Пример #11
0
 @Override
 public Transaction transaction() {
   checkClosed();
   return transactionProvider.get();
 }