@Override public void close() throws HibernateException { delegate.close(); }
@Test public void testHiLoAlgorithm() { sessionImpl = (SessionImpl) sessionFactory.openSession(); try { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // historically the hilo generators skipped the initial block of values; // so the first generated id value is maxlo + 1, here be 4 assertEquals(4L, generateValue()); // which should also perform the first read on the sequence which should set it to its "start with" value (1) assertEquals(1L, extractSequenceValue()); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assertEquals(5L, generateValue()); assertEquals(1L, extractSequenceValue()); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assertEquals(6L, generateValue()); assertEquals(1L, extractSequenceValue()); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assertEquals(7L, generateValue()); // unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation // after a clock over assertEquals(1L, extractSequenceValue()); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assertEquals(8L, generateValue()); // this should force an increment in the sequence value assertEquals(2L, extractSequenceValue()); } finally { sessionImpl.close(); } }
@Override public void close() throws HibernateException { delegate.close(); }
@Override public void run() { log.trace( "started" ); SessionImplementor session = (SessionImplementor) sessionFactory .withOptions() .tenantIdentifier( tenantId ) .openSession(); session.setHibernateFlushMode( FlushMode.MANUAL ); session.setCacheMode( cacheMode ); session.setDefaultReadOnly( true ); try { loadAllFromQueue( session ); } catch (Exception exception) { String logMessage = log.massIndexerExceptionWhileTransformingIds(); //TODO: use an errorHandler instance // errorHandler.handleException( logMessage, exception ); // temporary re-throw the exception as a Runtime throw new RuntimeException( logMessage, exception ); } finally { producerEndSignal.countDown(); session.close(); } log.trace( "finished" ); }
@Override public void run() { log.trace( "started" ); SessionImplementor session = (SessionImplementor) sessionFactory .withOptions() .tenantIdentifier( tenantId ) .openSession(); session.setHibernateFlushMode( FlushMode.MANUAL ); session.setCacheMode( cacheMode ); session.setDefaultReadOnly( true ); try { loadAllFromQueue( session ); } catch (Exception exception) { errorHandler.handleException( log.massIndexerExceptionWhileTransformingIds(), exception ); } finally { producerEndSignal.countDown(); session.close(); } log.trace( "finished" ); }