Created
March 9, 2012 16:53
-
-
Save mikeycmccarthy/2007476 to your computer and use it in GitHub Desktop.
Uniqueness Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NodeManager | |
public <T extends PropertyContainer> T indexPutIfAbsent( Index<T> index, T entity, String key, Object value ) | |
{ | |
T existing = index.get( key, value ).getSingle(); | |
if ( existing != null ) return existing; | |
// Grab lock | |
IndexLock lock = new IndexLock( index.getName(), key ); | |
LockType.WRITE.acquire( lock, lockManager ); // 1. | |
try | |
{ | |
// Check again | |
existing = index.get( key, value ).getSingle(); | |
if ( existing != null ) | |
{ | |
LockType.WRITE.release( lock, lockManager ); | |
return existing; | |
} | |
// Add | |
index.add( entity, key, value ); // 2 | |
return null; | |
} | |
finally | |
{ | |
if ( existing == null ) LockType.WRITE.unacquire( lock, lockManager, lockReleaser ); // 5 | |
} | |
// LuceneIndex | |
public void add( T entity, String key, Object value ) | |
{ | |
LuceneXaConnection connection = getConnection(); // 3 | |
assertValidKey( key ); | |
for ( Object oneValue : IoPrimitiveUtils.asArray( value ) ) | |
{ | |
connection.add( this, entity, key, oneValue ); // 4 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment