/** * Get the string to append to SELECT statements to acquire READ locks * for this dialect. Location of the of the returned string is treated * the same as getForUpdateString. * * @param timeout in milliseconds, -1 for indefinite wait and 0 for no wait. * @return The appropriate <tt>LOCK</tt> clause string. */ public String getReadLockString(int timeout) { return getForUpdateString(); }
/** * Get the string to append to SELECT statements to acquire WRITE locks * for this dialect. Location of the of the returned string is treated * the same as getForUpdateString. * * @param timeout in milliseconds, -1 for indefinite wait and 0 for no wait. * @return The appropriate <tt>LOCK</tt> clause string. */ public String getWriteLockString(int timeout) { return getForUpdateString(); }
/** * Get the <tt>FOR UPDATE OF column_list NOWAIT</tt> fragment appropriate * for this dialect given the aliases of the columns to be write locked. * * @param aliases The columns to be write locked. * @return The appropriate <tt>FOR UPDATE OF colunm_list NOWAIT</tt> clause string. */ public String getForUpdateNowaitString(String aliases) { return getForUpdateString( aliases ); }
/** * Retrieves the <tt>FOR UPDATE NOWAIT</tt> syntax specific to this dialect. * * @return The appropriate <tt>FOR UPDATE NOWAIT</tt> clause string. */ public String getForUpdateNowaitString() { // by default we report no support for NOWAIT lock semantics return getForUpdateString(); }
/** * Retrieves the <tt>FOR UPDATE SKIP LOCKED</tt> syntax specific to this dialect. * * @return The appropriate <tt>FOR UPDATE SKIP LOCKED</tt> clause string. */ public String getForUpdateSkipLockedString() { // by default we report no support for SKIP_LOCKED lock semantics return getForUpdateString(); }
/** * Given a lock mode, determine the appropriate for update fragment to use. * * @param lockMode The lock mode to apply. * @return The appropriate for update fragment. */ public String getForUpdateString(LockMode lockMode) { return getForUpdateString( lockMode, LockOptions.WAIT_FOREVER ); }
/** * Get the <tt>FOR UPDATE OF column_list</tt> fragment appropriate for this * dialect given the aliases of the columns to be write locked. * * @param aliases The columns to be write locked. * @return The appropriate <tt>FOR UPDATE OF column_list</tt> clause string. */ public String getForUpdateString(String aliases) { // by default we simply return the getForUpdateString() result since // the default is to say no support for "FOR UPDATE OF ..." return getForUpdateString(); }
/** * Get the <tt>FOR UPDATE OF column_list SKIP LOCKED</tt> fragment appropriate * for this dialect given the aliases of the columns to be write locked. * * @param aliases The columns to be write locked. * @return The appropriate <tt>FOR UPDATE colunm_list SKIP LOCKED</tt> clause string. */ public String getForUpdateSkipLockedString(String aliases) { return getForUpdateString( aliases ); }
public String toFragmentString() { if ( lockOptions!= null ) { if ( aliases.length() == 0) { return dialect.getForUpdateString( lockOptions ); } else { return dialect.getForUpdateString( aliases.toString(), lockOptions ); } } else if ( aliases.length() == 0) { if ( lockMode != null ) { return dialect.getForUpdateString( lockMode ); } return ""; } // TODO: pass lockmode if(isNowaitEnabled) { return dialect.getForUpdateNowaitString( aliases.toString() ); } else if (isSkipLockedEnabled) { return dialect.getForUpdateSkipLockedString( aliases.toString() ); } else { return dialect.getForUpdateString( aliases.toString() ); } }
/** * Given LockOptions (lockMode, timeout), determine the appropriate for update fragment to use. * * @param lockOptions contains the lock mode to apply. * @return The appropriate for update fragment. */ public String getForUpdateString(LockOptions lockOptions) { final LockMode lockMode = lockOptions.getLockMode(); return getForUpdateString( lockMode, lockOptions.getTimeOut() ); }
/** * Get the <tt>FOR UPDATE OF column_list</tt> fragment appropriate for this * dialect given the aliases of the columns to be write locked. * * @param aliases The columns to be write locked. * @param lockOptions the lock options to apply * @return The appropriate <tt>FOR UPDATE OF column_list</tt> clause string. */ @SuppressWarnings({"unchecked", "UnusedParameters"}) public String getForUpdateString(String aliases, LockOptions lockOptions) { LockMode lockMode = lockOptions.getLockMode(); final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator(); while ( itr.hasNext() ) { // seek the highest lock mode final Map.Entry<String, LockMode>entry = itr.next(); final LockMode lm = entry.getValue(); if ( lm.greaterThan( lockMode ) ) { lockMode = lm; } } lockOptions.setLockMode( lockMode ); return getForUpdateString( lockOptions ); }
buf.append(dialect.getForUpdateString(lockOptions));
@SuppressWarnings( {"deprecation"}) private String getForUpdateString(LockMode lockMode, int timeout){ switch ( lockMode ) { case UPGRADE: return getForUpdateString(); case PESSIMISTIC_READ: return getReadLockString( timeout ); case PESSIMISTIC_WRITE: return getWriteLockString( timeout ); case UPGRADE_NOWAIT: case FORCE: case PESSIMISTIC_FORCE_INCREMENT: return getForUpdateNowaitString(); case UPGRADE_SKIPLOCKED: return getForUpdateSkipLockedString(); default: return ""; } }
@Test public void testLockTimeoutNoAliasNoTimeout() { assertEquals( " for update", dialect.getForUpdateString( new LockOptions( LockMode.PESSIMISTIC_READ ) ) ); assertEquals( " for update", dialect.getForUpdateString( new LockOptions( LockMode.PESSIMISTIC_WRITE ) ) ); }
@Test public void testLockTimeoutNoAliasSkipLocked() { assertEquals( " for update skip locked", dialect.getForUpdateString( new LockOptions( LockMode.PESSIMISTIC_READ ) .setTimeOut( LockOptions.SKIP_LOCKED ) ) ); assertEquals( " for update skip locked", dialect.getForUpdateString( new LockOptions( LockMode.PESSIMISTIC_WRITE ) .setTimeOut( LockOptions.SKIP_LOCKED ) ) ); }
@Test public void testLockTimeoutNoAliasNoWait() { assertEquals( " for update nowait", dialect.getForUpdateString( new LockOptions( LockMode.PESSIMISTIC_READ ) .setTimeOut( LockOptions.NO_WAIT ) ) ); assertEquals( " for update nowait", dialect.getForUpdateString( new LockOptions( LockMode.PESSIMISTIC_WRITE ) .setTimeOut( LockOptions.NO_WAIT ) ) ); }
@Test public void testLockTimeoutAliasNoTimeout() { String alias = "a"; assertEquals( " for update", dialect.getForUpdateString( alias, new LockOptions( LockMode.PESSIMISTIC_READ ).setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_READ ) ) ); assertEquals( " for update", dialect.getForUpdateString( alias, new LockOptions( LockMode.PESSIMISTIC_WRITE ).setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_WRITE ) ) ); }
@Test public void testLockTimeoutAliasNoWait() { String alias = "a"; assertEquals( " for update nowait", dialect.getForUpdateString( alias, new LockOptions( LockMode.PESSIMISTIC_READ ).setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_READ ) .setTimeOut( LockOptions.NO_WAIT ) ) ); assertEquals( " for update nowait", dialect.getForUpdateString( alias, new LockOptions( LockMode.PESSIMISTIC_WRITE ).setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_WRITE ) .setTimeOut( LockOptions.NO_WAIT ) ) ); }
@Test public void testLockTimeoutAliasSkipLocked() { String alias = "a"; assertEquals( " for update skip locked", dialect.getForUpdateString( alias, new LockOptions( LockMode.PESSIMISTIC_READ ).setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_READ ) .setTimeOut( LockOptions.SKIP_LOCKED ) ) ); assertEquals( " for update skip locked", dialect.getForUpdateString( alias, new LockOptions( LockMode.PESSIMISTIC_WRITE ).setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_WRITE ) .setTimeOut( LockOptions.SKIP_LOCKED ) ) ); } }