return statelessSession.getNamedQuery(queryName);
StatelessSession session = sessionFactory.openStatelessSession(); Transaction tx = session.beginTransaction(); ScrollableResults customers = session.getNamedQuery("GetCustomers") .scroll(ScrollMode.FORWARD_ONLY); while ( customers.next() ) { Customer customer = (Customer) customers.get(0); customer.updateStuff(...); session.update(customer); } tx.commit(); session.close();
@Override public Query getNamedQuery(String queryName) { return this.raw.getNamedQuery(queryName); }
@Nonnull public Map<String, Date> getIdsToNextRunTimes() { return ((List<Object[]>) withStatelessSession(session -> session.getNamedQuery("findNextRuntimes").list())) .stream().collect(Collectors.toMap( row -> (String) row[0], row -> new Date((Long) row[1]) )); }
@Nonnull public Set<String> findAllJobRunnerKeys() { return (Set<String>) withStatelessSession(session -> session.getNamedQuery("findAllJobRunnerKeys").list()) .stream().collect(Collectors.toSet()); } }
@Nonnull public Collection<InternalClusterJob> findByJobRunnerKey(String jobRunnerKey) { return withStatelessSession(session -> session.getNamedQuery("findJobsByRunnerKey") .setString("runnerKey", jobRunnerKey) .list()); }
public Date getNextRunTime(String id) { Long result = (Long) withStatelessSession(session -> session.getNamedQuery("getNextRunTime") .setString("id", id) .uniqueResult()); return result == null ? null : new Date(result); }
public boolean delete(String id) { return withStatelessSession(session -> session.getNamedQuery("deleteById") .setString("id", id) .executeUpdate() == 1 ); }
public Long getVersion(String id) { return (Long) withStatelessSession(session -> session.getNamedQuery("getVersion") .setString("id", id) .uniqueResult()); }
public List<ClusterHeartbeatEntity> findHeartbeatsAfter(long timestamp) { return withStatelessSession(statelessSession -> (List<ClusterHeartbeatEntity>) statelessSession.getNamedQuery("findHeartbeatsAfter") .setParameter("timestamp", timestamp) .list()); }
public boolean claim(String id, @Nullable Long nextRunTimestamp, long expectedVersion, @Nullable String nodeId) { return withStatelessSession(session -> session.getNamedQuery("updateNextRunTime") .setLong("oldVersion", expectedVersion) .setLong("newVersion", expectedVersion + 1L) .setString("id", id) // using setLong will blow up on null value here, so we need setParameter .setParameter("nextRunTimestamp", nextRunTimestamp, org.hibernate.type.LongType.INSTANCE) .setString("claimNodeId", nodeId) .setLong("claimTimestamp", new Date().getTime()) .executeUpdate() == 1 ); }
return statelessSession.getNamedQuery(queryName);
StatelessSession session = sessionFactory.openStatelessSession(); Transaction tx = session.beginTransaction(); ScrollableResults customers = session.getNamedQuery("GetCustomers") .scroll(ScrollMode.FORWARD_ONLY); while ( customers.next() ) { Customer customer = (Customer) customers.get(0); customer.updateStuff(...); session.update(customer); } tx.commit(); session.close();
StatelessSession session = sessionFactory.openStatelessSession(); Transaction tx = session.beginTransaction(); ScrollableResults customers = session.getNamedQuery("GetCustomers") .scroll(ScrollMode.FORWARD_ONLY); while ( customers.next() ) { Customer customer = (Customer) customers.get(0); customer.updateStuff(...); session.update(customer); } tx.commit(); session.close();