UniqueFactory (Neo4j Community 1.8.RC1 API)
Date: 2012-09-07

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Neo4j Community
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.neo4j.graphdb.index
Class UniqueFactory<T extends PropertyContainer>

    java.lang.Object
      org.neo4j.graphdb.index.UniqueFactory<T>

Type Parameters:
  `T` - the type of entity created by this `UniqueFactory`.

Direct Known Subclasses:
  UniqueFactory.UniqueNodeFactory, UniqueFactory.UniqueRelationshipFactory

    public abstract class UniqueFactory<T extends PropertyContainer>

extends Object

A utility class for creating unique (with regard to a given index) entities. Uses the `putIfAbsent() method` of the referenced index.

Author:
  Tobias Lindaaker

Nested Class Summary
`static class` | `UniqueFactory.UniqueNodeFactory` Implementation of `UniqueFactory` for `Node`.
`static class` | `UniqueFactory.UniqueRelationshipFactory` Implementation of `UniqueFactory` for `Relationship`.

Method Summary
`protected abstract T` | `create(Map<String,Object> properties)` Implement this method to create the `Node` or `Relationship` to index.
`protected abstract void` | `delete(T created)` Invoked after a new entity has been `created`, but adding it to the index failed (due to being added by another transaction concurrently).
`T` | `getOrCreate(String key, Object value)` Get the indexed entity, creating it (exactly once) if no indexed entity exists.
`protected GraphDatabaseService` | `graphDatabase()` Get the `graph database` of the referenced index.
`protected Index<T>` | `index()` Get the referenced index.
`protected abstract void` | `initialize(T created, Map<String,Object> properties)` Implement this method to initialize the `Node` or `Relationship` created for being stored in the index.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### create

    protected abstract T create(Map<String,Object> properties)

  Implement this method to create the `Node` or `Relationship` to index. This method will be invoked exactly once per transaction that attempts to create an entry in the index. The created entity might be discarded if another thread creates an entity with the same mapping concurrently.

  Parameters:
    `properties` - the properties that this entity will is to be indexed uniquely with.
  Returns:
    the entity to add to the index.

### initialize

    protected abstract void initialize(T created,
                                       Map<String,Object> properties)

  Implement this method to initialize the `Node` or `Relationship` created for being stored in the index. This method will be invoked exactly once per created unique entity. The created entity might be discarded if another thread creates an entity concurrently. This method will however only be invoked in the transaction that succeeds in creating the node.

  Parameters:
    `created` - the created entity to initialize.
    `properties` - the properties that this entity was indexed uniquely with.

### delete

    protected abstract void delete(T created)

  Invoked after a new entity has been `created`, but adding it to the index failed (due to being added by another transaction concurrently). The purpose of this method is to undo the `creation of the entity`, the default implementations of this method remove the entity. Override this method to define a different behavior.

  Parameters:
    `created` - the entity that was created but was not added to the index.

### getOrCreate

    public final T getOrCreate(String key,
                               Object value)

  Get the indexed entity, creating it (exactly once) if no indexed entity exists.

  Parameters:
    `key` - the key to find the entity under in the index.
    `value` - the value the key is mapped to for the entity in the index.
  Returns:
    the unique entity in the index.

### graphDatabase

    protected final GraphDatabaseService graphDatabase()

  Get the `graph database` of the referenced index.

  Returns:
    the `graph database` of the referenced index.

### index

    protected final Index<T> index()

  Get the referenced index.

  Returns:
    the referenced index.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Neo4j Community
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.