List of usage examples for org.hibernate.jpa QueryHints HINT_READONLY
String HINT_READONLY
To view the source code for org.hibernate.jpa QueryHints HINT_READONLY.
Click Source Link
From source file:org.mascherl.example.service.ComposeMailService.java
License:Apache License
@Transactional public Mail openDraft(String uuid, User currentUser) { // FiniteDuration fiveSeconds = Duration.apply(5l, TimeUnit.SECONDS); // Configuration configuration = new Configuration( // "postgres", // "localhost", // 5432, // new Some<>("postgres"), // new Some<>("niotest"), // StandardCharsets.UTF_8, // 16777216, // PooledByteBufAllocator.DEFAULT, // fiveSeconds, // fiveSeconds); ///*ww w. ja va2 s. c o m*/ // PostgreSQLConnection postgreSQLConnection = new PostgreSQLConnection( // configuration, // PostgreSQLColumnEncoderRegistry.Instance(), // PostgreSQLColumnDecoderRegistry.Instance(), // NettyUtils.DefaultEventLoopGroup(), // ExecutorServiceUtils.CachedExecutionContext()); // // CompletableFuture<Connection> future = new CompletableFuture<>(); // postgreSQLConnection.connect().onComplete(func((tryConnection) -> { // if (tryConnection.isSuccess()) { // future.complete(tryConnection.get()); // } else { // future.completeExceptionally(tryConnection.failed().get()); // } // return future; // }), FutureConverters.globalExecutionContext()); // future.whenComplete((connection, throwable) -> { // System.out.println(throwable); // System.out.println(connection); // }); // // FutureConverters.toJava(postgreSQLConnection.connect() // .flatMap(func(connection -> connection.sendPreparedStatement("SELECT m.uuid from mail m where m.uuid = ?", JavaConversions.asScalaBuffer(Arrays.asList(uuid)))), FutureConverters.globalExecutionContext()) // .flatMap(func(result -> { // OptionConverters.toJava(result.rows()).ifPresent((ResultSet rs) -> System.out.println(rs.head().apply(0))); // return postgreSQLConnection.disconnect(); // }), FutureConverters.globalExecutionContext())) // .whenComplete((connection, throwable) -> { // System.out.println(throwable); // System.out.println(connection); // }); List<MailEntity> resultList = em .createQuery("select m " + "from MailEntity m " + "where m.uuid = :uuid " + "and m.user.uuid = :userUuid", MailEntity.class) .setParameter("uuid", uuid).setParameter("userUuid", currentUser.getUuid()) .setHint(QueryHints.HINT_READONLY, Boolean.TRUE).getResultList(); if (resultList.isEmpty()) { return null; } MailEntity entity = resultList.get(0); if (entity.getMailType() != MailType.DRAFT) { throw new IllegalStateException("Mail with uuid " + uuid + " + is not of type draft"); } return convertToDomain(entity); }
From source file:org.mascherl.example.service.ComposeMailService.java
License:Apache License
public List<MailAddressUsage> getLastReceivedFromAddresses(User currentUser, int limit) { return em/*from www.jav a2 s . c o m*/ .createQuery("select distinct new " + MailAddressUsage.class.getName() + "( " + "m.from, " + "m.dateTime" + ") " + "from MailEntity m " + "where m.user.uuid = :userUuid " + "and m.mailType = :mailTypeReceived " + "and not exists ( " + " select m2.uuid from MailEntity m2 " + " where m2.user.uuid = :userUuid " + " and m2.mailType = :mailTypeReceived " + " and m2.from.address = m.from.address " + " and m2.dateTime > m.dateTime " + ") " + "order by m.dateTime desc", MailAddressUsage.class) .setParameter("userUuid", currentUser.getUuid()).setParameter("mailTypeReceived", MailType.RECEIVED) .setMaxResults(limit).setHint(QueryHints.HINT_READONLY, Boolean.TRUE).getResultList(); }
From source file:org.mascherl.example.service.MailService.java
License:Apache License
@Transactional public List<Mail> getMailsForUser(User currentUser, MailType mailType, int offset, int pageSize) { List<MailEntity> resultList = em .createQuery("select m " + "from MailEntity m " + "where m.user.uuid = :userUuid " + "and m.mailType = :mailType " + "order by m.dateTime desc", MailEntity.class) .setParameter("userUuid", currentUser.getUuid()).setParameter("mailType", mailType) .setFirstResult(offset).setMaxResults(pageSize).setHint(QueryHints.HINT_READONLY, Boolean.TRUE) .setHint(QueryHints.HINT_FETCH_SIZE, pageSize).getResultList(); return resultList.stream().map(MailConverter::convertToDomain).collect(Collectors.toList()); }