}
Transaction tx = graphDb.beginTx();
try
{
int hashCode = key.hashCode();
KeyEntry entry = bTree.addIfAbsent( hashCode, value );
if ( entry != null )
{
entry.setKeyValue( key );
}
else
{
entry = bTree.getAsKeyEntry( hashCode );
Object goOtherNode = entry.getKeyValue();
Node bucketNode = null;
if ( !goOtherNode.equals( GOTO_NODE ) )
{
Object prevValue = entry.getValue();
Object prevKey = entry.getKeyValue();
if ( prevKey.equals( key ) )
{
Object oldValue = entry.getValue();
entry.setValue( value );
tx.success();
return (V) oldValue;
}
entry.setKeyValue( GOTO_NODE );
bucketNode = graphDb.createNode();
entry.setValue( bucketNode.getId() );
Node prevEntry = graphDb.createNode();
bucketNode.createRelationshipTo( prevEntry,
RelTypes.MAP_ENTRY );
prevEntry.setProperty( MAP_KEY, prevKey );
prevEntry.setProperty( MAP_VALUE, prevValue );
Node newEntry = graphDb.createNode();
bucketNode.createRelationshipTo( newEntry,
RelTypes.MAP_ENTRY );
newEntry.setProperty( MAP_KEY, key );
newEntry.setProperty( MAP_VALUE, value );
}
else
{
bucketNode = graphDb.getNodeById( (Long) entry.getValue() );
for ( Relationship rel : bucketNode.getRelationships(
RelTypes.MAP_ENTRY, Direction.OUTGOING ) )
{
Node entryNode = rel.getEndNode();
if ( entryNode.getProperty( MAP_KEY ).equals( key ) )