@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); }
@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); }
@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); } }
@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); }
@Override public <E extends T> Result<E> raw(Class<E> type, String query, Object... parameters) { checkClosed(); return new RawEntityQuery<>(context, type, query, parameters).get(); }
@Override public Result<Tuple> raw(final String query, final Object... parameters) { checkClosed(); return new RawTupleQuery(context, query, parameters).get(); }
@Override public Selection<? extends Scalar<Integer>> count(QueryAttribute<?, ?>... attributes) { checkClosed(); return new QueryElement<>(SELECT, entityModel, countOperation).select(Count.count(attributes)); }
@Override public <E extends T> Deletion<? extends Scalar<Integer>> delete(Class<E> type) { checkClosed(); return new QueryElement<>(DELETE, entityModel, updateOperation).from(type); }
@Override public Deletion<? extends Scalar<Integer>> delete() { checkClosed(); return new QueryElement<>(DELETE, entityModel, updateOperation); }
@Override public Update<? extends Scalar<Integer>> update() { checkClosed(); return new QueryElement<>(UPDATE, entityModel, updateOperation); }
@Override public Transaction transaction() { checkClosed(); return transactionProvider.get(); }