session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { //connection, finally! } });
Session session = entityManager.unwrap(Session.class); session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { // do whatever you need to do with the connection } });
public class Main { public static void main(String[] args) { ExecutorServiceFactory.createScheduledExecutorService(new Work()); } }
'Session'.doWork(new Work() { @Override public void execute(Connection c) throws SQLException { } }
@Override public Work createEntityWork(Serializable id, IndexedTypeIdentifier entityType, WorkType workType) { return new Work(null, entityType, id, workType); } }
@Override public Work createEntityWork(Serializable id, IndexedTypeIdentifier entityType, WorkType workType) { return new Work(null, entityType, id, workType); } }
private boolean isReadOnly; public boolean isReadOnly() { this.getSessionFactory().getCurrentSession().doWork(new Work() { public void execute(Connection connection) throws SQLException { isReadOnly = connection.isReadOnly(); } }); return isReadOnly; }
@Override public Collection<Work> createPerEntityWorks(Object entity, Serializable id, WorkType workType) { Work work = new Work(entity, id, workType); return Collections.singleton(work); }
public void doWorkOnConnection(Session session) { session.doWork(new Work() { public void execute(Connection connection) throws SQLException { //use the connection here... } }); }
final boolean condition = ... Thread t = new Thread(new Runnable() { public void run() { Work work=new Work(); work.doWork(); if(condition) work.commit(); }}); t.start();
@Override public void accept(int id) { AbstractBookEntity book = dataset.create( id ); Work work = new Work( book, id, WorkType.ADD, false ); worker.performWork( work, tc ); needsFlush = true; ++count; if ( count % 1000 == 0 ) { //commit in batches of 1000: flush(); } }
private Work createDeleteWork(int id) { Work work = new Work( Quote.random( id ), id, DELETE ); deleteCounter.decrementAndGet(); return work; }
private Work createUpdateWork(int id) { Work work = new Work( Quote.random( id ), id, UPDATE ); updateCounter.decrementAndGet(); return work; }
private Work createAddWork() { Quote random = Quote.random(); Work work = new Work( random, random.getId(), ADD ); addCounter.decrementAndGet(); return work; }
@Override public Collection<Work> createPerEntityWorks(Object value, Serializable id, WorkType workType) { // Will generate extra entities based on the items List<Work> works = new LinkedList<>(super.createPerEntityWorks(value, id, workType)); Entity e = (Entity) value; for (String item : e.getItems()) { Entity newEntity = new Entity(item); works.add(new Work(newEntity, "item-" + item, workType)); } return works; }
protected void processWork(String tenantIdentifier, Object entity, Serializable id, WorkType workType, AbstractEvent event, boolean identifierRollbackEnabled) { Work work = new Work( tenantIdentifier, entity, id, workType, identifierRollbackEnabled ); final EventSourceTransactionContext transactionContext = new EventSourceTransactionContext( event.getSession() ); getExtendedSearchFactoryIntegrator().getWorker().performWork( work, transactionContext ); }
private static void deleteABook(Integer id, Worker worker) { Book book = new Book(); book.id = id; Work work = new Work( book, id, WorkType.DELETE, false ); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); tc.end(); }
private static void writeABook(Integer id, String bookTitle, Worker worker) { Book book = new Book(); book.id = id; book.title = bookTitle; Work work = new Work( book, book.id, WorkType.ADD, false ); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); tc.end(); }
private void storeObject(Object entity, Serializable id) { Work work = new Work( entity, id, WorkType.UPDATE, false ); TransactionContextForTest tc = new TransactionContextForTest(); searchIntegrator.getWorker().performWork( work, tc ); tc.end(); }
private void storeObject(Object entity, Serializable id) { Work work = new Work( entity, id, WorkType.UPDATE, false ); TransactionContextForTest tc = new TransactionContextForTest(); slaveNode.getSearchFactory().getWorker().performWork( work, tc ); tc.end(); }