Holger's Java API

## com.antelmann.sql
Class RelationshipStore<T extends DefaultEntryRelationship>

    java.lang.Object
      com.antelmann.sql.JDBCRowStore<T>
          com.antelmann.sql.RelationshipStore<T>

All Implemented Interfaces:
  DBClassStore<T>, TransactionRequired, MappingInfo, RelationshipManager, ProcessorHook<T,DatabaseException>

Direct Known Subclasses:
  GPersonRelationStore

    public class RelationshipStore<T extends DefaultEntryRelationship>

extends JDBCRowStore<T>
implements RelationshipManager

provides an SQL-based store for relationships.

The class T must have a constructor that corresponds to `DefaultEntryRelationship.DefaultEntryRelationship(Object, com.antelmann.db.EntryRelationship)`, so that the instantiation of the mapper works based on reflection. When using a `TopicMapFilter` on this store, make sure that you are using an object derivable from the EntryClassMapper in use; see `setEntryClassMapper(EntryClassMapper)`. By default, a `EntryClassMapper.STRING_MAPPER` is used.

To allow more efficient storage, an implementation may be restricted to only allow relations of already specified types, so that the from-/to-class may not be stored. If that is the case, do not put these topics into the configuration map used in the constructor, but use `setFromClass(Class)` and `setToClass(Class)` respectively. If, on the other hand, the classes are mapped, then these two methods should be left with a null value. The fastDelete option is generally set to true here.

Since:
  14.04.2009, 16:24:11
Author:
  Holger Antelmann
See Also:
  `JDBCRowStore.setFastDelete(boolean)`

Nested Class Summary
`static class` `RelationshipStore.Mapper<T extends DefaultEntryRelationship>`

Nested classes/interfaces inherited from interface com.antelmann.sql.RelationshipManager
`RelationshipManager.Column`

Nested classes/interfaces inherited from interface com.antelmann.db.DBClassStore
`DBClassStore.DBMethod`

Field Summary

Fields inherited from class com.antelmann.sql.JDBCRowStore
`database, ensureTransactionsOnFetch, helper, mapper`

Constructor Summary
`RelationshipStore(Database<Connection> db, RelationshipStore.Mapper<T> mapper, Class<T> type)`
`RelationshipStore(Database<Connection> db, String tableName, String idColumn, Class<T> type, boolean useNextIntAsID)`
`RelationshipStore(Database<Connection> db, String tableName, String idColumn, IDFactory factory, Class<T> type)`
`RelationshipStore(Database<Connection> db, String tableName, String idColumn, Map<RelationshipManager.Column,String> config, Class<T> type, boolean useNextIntAsID)`
`RelationshipStore(Database<Connection> db, String tableName, String idColumn, Map<RelationshipManager.Column,String> config, IDFactory factory, Class<T> type)`
`RelationshipStore(Database<Connection> db, String tableName, String idColumn, Map<RelationshipManager.Column,String> config, IDFactory factory, Class<T> type, String query)`

Method Summary
`int` `countRelations(Map<RelationshipManager.Column,Object> restrictions)` the mapped values for the class columns `RelationshipManager.Column.TO_CLASS` and `RelationshipManager.Column.FROM_CLASS` may be represented as Class

`static

`<T extends DefaultEntryRelationship> ArrayList<T>`

`

`findBrokenRelationships(DBClassStore<T> store, boolean breakOnFirstEncounter)`

`static

`<T extends DefaultEntryRelationship> void`

`

`findBrokenRelationships(DBClassStore<T> store, Collection<T> set, Monitor monitor, boolean breakOnFirstEncounter)`
looks for broken relationships in the database and puts them into the given collection.

`static

`<T extends DefaultEntryRelationship> ArrayList<T>`

`

`findBrokenRelationships(DBClassStore<T> store, Monitor monitor, boolean breakOnFirstEncounter)`

`static HashMap<RelationshipManager.Column,String>` `getDefaultColumns()`
`EntryClassMapper` `getEntryClassMapper()` returns the EntryClassMapper used by the store to map the class of the references
`RelationshipStore.Mapper<T>` `getMapper()`
`boolean` `hasRelationships(DBReference ref)` determines if there are any relationsips present for a given reference (both: active and passive)
`Set<DefaultEntryRelationship>` `listAllRelations(DBReference ref, Object relationType)` contains passive and active relationships for the given reference - restricted to the given type if non-null
`List<DefaultEntryRelationship>` `listRelations(Map<RelationshipManager.Column,Object> restrictions)` the mapped values for the class columns `RelationshipManager.Column.TO_CLASS` and `RelationshipManager.Column.FROM_CLASS` may be represented as Class
`void` `setDefaultRelationType(Object relationType)` must be set if the topic `RelationshipManager.Column.TYPE` is not set
`void` `setEntryClassMapper(EntryClassMapper ecm)` use this method to set the EntryClassMapper of the embedded mapper to something other than `EntryClassMapper.STRING_MAPPER`
`void` `setFromClass(Class<? extends DBEntry> c)` must be set if the topic `RelationshipManager.Column.FROM_CLASS` is not set
`void` `setPreventSameRelation(boolean flag)`
`void` `setTableQuery(String query)`
`void` `setToClass(Class<? extends DBEntry> c)` must be set if the topic `RelationshipManager.Column.TO_CLASS` is not set
`void` `setVerifyRelationsOnStore(boolean flag)`
`protected Object` `translateForColumn(Object value, RelationshipManager.Column column)`
`protected Object` `translateForColumn(Object value, String column)`
`protected Map<Object,Object>` `translateMap(Map<RelationshipManager.Column,Object> restrictions)` responsible for converting the restrictions map to a map that can be used as a `TopicMapFilter`
`protected Map<String,Object>` `translateQueryMap(Map<String,Object> restrictions)`

Methods inherited from class com.antelmann.sql.JDBCRowStore

`add, checkTransaction, containsID, deleteEntries, deleteEntry, fetch, fetchStubs, generateNewID, getColumnNames, getColumnsForTopic, getColumnSize, getDatabase, getDisplayColumn, getDisplayNameForColumn, getEntry, getEntryClass, getIDColumn, getMappingForTopic, getSQLTypeforColumn, getStub, getTableName, getTableQuery, insert, insertAsNew, isFastDelete, isIgnoreInvalidProperties, remove, setFastDelete, setIgnoreInvalidProperties, size, trimIdString, update`

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

Constructor Detail

### RelationshipStore

    public RelationshipStore(Database<Connection> db,
                             String tableName,
                             String idColumn,
                             Class<T> type,
                             boolean useNextIntAsID)
                      throws DatabaseException

Throws:
  `DatabaseException`

### RelationshipStore

    public RelationshipStore(Database<Connection> db,
                             String tableName,
                             String idColumn,
                             Map<RelationshipManager.Column,String> config,
                             Class<T> type,
                             boolean useNextIntAsID)
                      throws DatabaseException

Throws:
  `DatabaseException`

### RelationshipStore

    public RelationshipStore(Database<Connection> db,
                             String tableName,
                             String idColumn,
                             IDFactory factory,
                             Class<T> type)
                      throws DatabaseException

Throws:
  `DatabaseException`

### RelationshipStore

    public RelationshipStore(Database<Connection> db,
                             String tableName,
                             String idColumn,
                             Map<RelationshipManager.Column,String> config,
                             IDFactory factory,
                             Class<T> type)
                      throws DatabaseException

Throws:
  `DatabaseException`

### RelationshipStore

    public RelationshipStore(Database<Connection> db,
                             String tableName,
                             String idColumn,
                             Map<RelationshipManager.Column,String> config,
                             IDFactory factory,
                             Class<T> type,
                             String query)
                      throws DatabaseException

Throws:
  `DatabaseException`

### RelationshipStore

    public RelationshipStore(Database<Connection> db,
                             RelationshipStore.Mapper<T> mapper,
                             Class<T> type)

Method Detail

### getDefaultColumns

    public static HashMap<RelationshipManager.Column,String> getDefaultColumns()

### setTableQuery

    public void setTableQuery(String query)
                       throws DatabaseException

  Throws:
    `DatabaseException`

### getMapper

    public RelationshipStore.Mapper<T> getMapper()

  Overrides:
    `getMapper` in class `JDBCRowStore<T extends DefaultEntryRelationship>`

### setEntryClassMapper

    public void setEntryClassMapper(EntryClassMapper ecm)

  use this method to set the EntryClassMapper of the embedded mapper to something other than `EntryClassMapper.STRING_MAPPER`

### setFromClass

    public void setFromClass(Class<? extends DBEntry> c)

  must be set if the topic `RelationshipManager.Column.FROM_CLASS` is not set

### setToClass

    public void setToClass(Class<? extends DBEntry> c)

  must be set if the topic `RelationshipManager.Column.TO_CLASS` is not set

### setDefaultRelationType

    public void setDefaultRelationType(Object relationType)

  must be set if the topic `RelationshipManager.Column.TYPE` is not set

### setPreventSameRelation

    public void setPreventSameRelation(boolean flag)

### setVerifyRelationsOnStore

    public void setVerifyRelationsOnStore(boolean flag)

### translateForColumn

    protected Object translateForColumn(Object value,
                                        String column)

### translateForColumn

    protected Object translateForColumn(Object value,
                                        RelationshipManager.Column column)

### translateMap

    protected Map<Object,Object> translateMap(Map<RelationshipManager.Column,Object> restrictions)

  responsible for converting the restrictions map to a map that can be used as a `TopicMapFilter`

### listRelations

    public List<DefaultEntryRelationship> listRelations(Map<RelationshipManager.Column,Object> restrictions)
                                                 throws DatabaseException

  Description copied from interface: `RelationshipManager`
  the mapped values for the class columns `RelationshipManager.Column.TO_CLASS` and `RelationshipManager.Column.FROM_CLASS` may be represented as Class<?> objects as an alternative to the class name base on `EntryClassMapper.STRING_MAPPER`.

  Specified by:
    `listRelations` in interface `RelationshipManager`
  Throws:
    `DatabaseException`

### countRelations

    public int countRelations(Map<RelationshipManager.Column,Object> restrictions)
                       throws DatabaseException

  Description copied from interface: `RelationshipManager`
  the mapped values for the class columns `RelationshipManager.Column.TO_CLASS` and `RelationshipManager.Column.FROM_CLASS` may be represented as Class<?> objects as an alternative to the class name base on `EntryClassMapper.STRING_MAPPER`.

  Specified by:
    `countRelations` in interface `RelationshipManager`
  Throws:
    `DatabaseException`

### hasRelationships

    public boolean hasRelationships(DBReference ref)
                             throws DatabaseException

  Description copied from interface: `RelationshipManager`
  determines if there are any relationsips present for a given reference (both: active and passive)

  Specified by:
    `hasRelationships` in interface `RelationshipManager`
  Throws:
    `DatabaseException`

### listAllRelations

    public Set<DefaultEntryRelationship> listAllRelations(DBReference ref,
                                                          Object relationType)
                                                   throws DatabaseException

  Description copied from interface: `RelationshipManager`
  contains passive and active relationships for the given reference - restricted to the given type if non-null

  Specified by:
    `listAllRelations` in interface `RelationshipManager`
  Throws:
    `DatabaseException`

### findBrokenRelationships

    public static <T extends DefaultEntryRelationship> ArrayList<T> findBrokenRelationships(DBClassStore<T> store,
                                                                                            boolean breakOnFirstEncounter)
                                                                                 throws DatabaseException

  Throws:
    `DatabaseException`

### findBrokenRelationships

    public static <T extends DefaultEntryRelationship> ArrayList<T> findBrokenRelationships(DBClassStore<T> store,
                                                                                            Monitor monitor,
                                                                                            boolean breakOnFirstEncounter)
                                                                                 throws DatabaseException

  Throws:
    `DatabaseException`

### findBrokenRelationships

    public static <T extends DefaultEntryRelationship> void findBrokenRelationships(DBClassStore<T> store,
                                                                                    Collection<T> set,
                                                                                    Monitor monitor,
                                                                                    boolean breakOnFirstEncounter)
                                        throws DatabaseException

  looks for broken relationships in the database and puts them into the given collection. This methods ensures transactions via `DBUtils.runInTransaction(Task, com.antelmann.db.DBTransaction, boolean)`

  Type Parameters:
    `T` - denotes the relationship class
  Parameters:
    `store` - the store that holds the relationships in question
    `set` - used to store the broken relations found
    `monitor` - allows to monitor the (potentially long-running) operation; the `Monitor.runTask()`-method is called whenever a broken relationship is found
    `breakOnFirstEncounter` - if true, the method will return when the first broken relationship is found
  Throws:
    `DatabaseException`
  See Also:
    `DefaultEntryRelationship.isBroken(Database)`

### getEntryClassMapper

    public EntryClassMapper getEntryClassMapper()

  Description copied from interface: `RelationshipManager`
  returns the EntryClassMapper used by the store to map the class of the references

  Specified by:
    `getEntryClassMapper` in interface `RelationshipManager`

### translateQueryMap

    protected Map<String,Object> translateQueryMap(Map<String,Object> restrictions)

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads