org.pandora.knowledge.database
Class DatabaseNetwork

java.lang.Object
  extended by org.pandora.knowledge.AbstractNetwork
      extended by org.pandora.knowledge.database.DatabaseNetwork
All Implemented Interfaces:
java.lang.Cloneable, Network

public class DatabaseNetwork
extends AbstractNetwork

Network using JPA to access a Derby database.


Field Summary
 
Fields inherited from class org.pandora.knowledge.AbstractNetwork
MAX_SIZE, MAX_TEXT
 
Constructor Summary
DatabaseNetwork(javax.persistence.EntityManager entityManager, boolean isShortTerm)
           
 
Method Summary
 void addVertex(Vertex vertex)
          Add the existing vertex to the network.
 java.util.List<Vertex> allActive()
          Return all active vertices.
 void clear()
          Clear all vertices from the network.
 java.util.List<Vertex> findAll()
          Return all vertices.
 java.util.List<Vertex> findAllLike(java.lang.String filter)
          Return all vertices matching the filter.
 java.util.List<Vertex> findAllQuery(java.lang.String jpql)
          Return all vertices matching the JPQL query.
 java.util.List<Vertex> findAllQuery(java.lang.String jpql, int max)
          Return all vertices matching the JPQL query.
 java.util.List<Relationship> findAllRelationshipsTo(Vertex vertex)
          Find all relationships related to the vertex or of the vertex type.
 Vertex findByData(java.lang.Object data)
          Return the vertex with the given data.
 Vertex findById(java.lang.Number id)
          Return the vertex with the given name.
 Vertex findByName(java.lang.String name)
          Return the vertex with the given data.
 javax.persistence.EntityManager getEntityManager()
           
 Network getParent()
          Return the parent network.
 void merge(Network network)
          Merge the vertices and relations of the network into this network.
 void removeRelationship(Relationship relationship)
          Remove the relationship from the network.
 void removeVertex(Vertex vertex)
          Remove the vertex from the network.
 void removeVertexAndReferences(Vertex vertex)
          Remove the vertex and all references to it from the network.
 void resetSize()
           
 void resume()
          Resume the network after a save.
 void save()
          Commit memory to the database.
 void setEntityManager(javax.persistence.EntityManager entityManager)
           
 void setParent(Network parent)
          Set the parent network.
 int size()
          Return the total number of vertices stored.
 
Methods inherited from class org.pandora.knowledge.AbstractNetwork
associateCaseInsensitivity, clone, createInstance, createInstance, createNewObject, createObject, createSentence, createSpeaker, createTimestamp, createVertex, createVertex, createVertex, createWord, getPandora, importMerge, importVertex, isShortTerm, merge, setPandora, setShortTerm, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DatabaseNetwork

public DatabaseNetwork(javax.persistence.EntityManager entityManager,
                       boolean isShortTerm)
Method Detail

getEntityManager

public javax.persistence.EntityManager getEntityManager()

setEntityManager

public void setEntityManager(javax.persistence.EntityManager entityManager)

resume

public void resume()
Resume the network after a save. Keep the MAX_SIZE number of most conscious vertices in memory.


save

public void save()
Commit memory to the database.


resetSize

public void resetSize()

clear

public void clear()
Description copied from interface: Network
Clear all vertices from the network.


addVertex

public void addVertex(Vertex vertex)
Add the existing vertex to the network. Used to load an existing vertex, createVertex must be used to create a new one.


getParent

public Network getParent()
Description copied from interface: Network
Return the parent network. A network is essentially a nested-transactional sub-graph of the parent.


setParent

public void setParent(Network parent)
Description copied from interface: Network
Set the parent network. A network is essentially a nested-transactional sub-graph of the parent.


size

public int size()
Description copied from interface: Network
Return the total number of vertices stored.


removeVertex

public void removeVertex(Vertex vertex)
Remove the vertex from the network. Note that the vertex must be no longer referenced by any other vertex in the network.


removeVertexAndReferences

public void removeVertexAndReferences(Vertex vertex)
Remove the vertex and all references to it from the network.


removeRelationship

public void removeRelationship(Relationship relationship)
Remove the relationship from the network. Note that the relationship must be no longer referenced by any other vertex in the network.

Specified by:
removeRelationship in interface Network
Overrides:
removeRelationship in class AbstractNetwork

allActive

public java.util.List<Vertex> allActive()
Return all active vertices.


findAll

public java.util.List<Vertex> findAll()
Return all vertices.


findAllLike

public java.util.List<Vertex> findAllLike(java.lang.String filter)
Return all vertices matching the filter.


findAllQuery

public java.util.List<Vertex> findAllQuery(java.lang.String jpql)
Return all vertices matching the JPQL query.


findAllQuery

public java.util.List<Vertex> findAllQuery(java.lang.String jpql,
                                           int max)
Return all vertices matching the JPQL query.


findAllRelationshipsTo

public java.util.List<Relationship> findAllRelationshipsTo(Vertex vertex)
Find all relationships related to the vertex or of the vertex type.


findByData

public Vertex findByData(java.lang.Object data)
Return the vertex with the given data.


findByName

public Vertex findByName(java.lang.String name)
Return the vertex with the given data.


findById

public Vertex findById(java.lang.Number id)
Return the vertex with the given name.


merge

public void merge(Network network)
Merge the vertices and relations of the network into this network.

Specified by:
merge in interface Network
Overrides:
merge in class AbstractNetwork