com.gentics.api.portalnode.connector
Class PortalConnectorFactory

java.lang.Object
  extended by com.gentics.api.portalnode.connector.PortalConnectorFactory

public final class PortalConnectorFactory
extends java.lang.Object

PortalConnectorFactory can be used to create instances for datasources, RuleTrees and Resolvables.

Author:
herbert

Method Summary
static
<T extends Datasource>
T
createDatasource(java.lang.Class<T> clazz, java.lang.String id)
          Create a datasource instance of the given class with given id
static Datasource createDatasource(java.util.Map handleprops)
          Creates a new datasource handle with the specified properties as well as a new Datasource (with default properties).
static Datasource createDatasource(java.util.Map handleprops, java.util.Map dsprops)
          Creates a new Datasource connection with the specified properties which should point to a Content Repository of Gentics Content.Node.
static Datasource createDatasource(java.lang.String id)
          Create a datasource instance for the datasource with given id
static Expression createExpression(java.lang.String rule)
          Parse the given expression string into an Expression.
static MultichannellingDatasource createMultichannellingDatasource(java.util.Map<java.lang.String,java.lang.String> handleProps, java.util.Map<java.lang.String,java.lang.String> dsProps)
          Create a new instance of a multichannelling datasource
static RuleTree createRuleTree(java.lang.String rule)
          Deprecated. deprecated, replaced by createExpression(String)
static WritableMultichannellingDatasource createWritableMultichannellingDatasource(java.util.Map<java.lang.String,java.lang.String> handleProps, java.util.Map<java.lang.String,java.lang.String> dsProps)
          Create a new writeable multichannelling datasource instance
static WriteableDatasource createWriteableDatasource(java.util.Map handleProperties)
          Creates a new datasource handle with the specified properties as well as a new writeable datasource (with default properties).
static WriteableDatasource createWriteableDatasource(java.util.Map handleProperties, java.util.Map datasourceProperties)
          Creates a new datasource handle with the specified properties as well as a new writeable datasource with the specified properties.
static void destroy()
          Destroy the portal connector factory, close all database connections, remove the scheduler (created background threads).
protected static void destroyDatasourceFactories()
          Destroy all created datasource factories, close all handles (closing database connections)
static java.util.List<java.lang.String> getAvailableDatasources()
          Get the list of all available datasource ids
static java.util.List<java.lang.String> getAvailableDatasources(java.lang.Class<? extends Datasource> datasourceClass)
          Get the available datasources as list of ids
static Changeable getChangeableContentObject(java.lang.String contentId, WriteableDatasource datasource)
          Returns a changeable content object with the given content id.
static Resolvable getContentObject(java.lang.String contentId, Datasource datasource)
          Returns a content object with the given content id.
static boolean isAutoRepair()
          Check whether the auto-repair functionality is switched on or off by configuration.
static boolean isAutoRepair2()
          Check whether the auto-repair2 functionality is switched on or off by configuration.
static void prefillAttributes(Datasource ds, java.util.Collection<Resolvable> objects, java.util.List<java.lang.String> prefillAttributes)
          Prefill the given attributes for objects which were fetched from the given datasource
static void registerDatasource(java.lang.String id, DatasourceType type, java.util.Map<java.lang.String,java.lang.String> parameters, java.util.List<java.lang.String> handles)
          Register a datasource at the factory.
static void registerDatasource(java.lang.String id, DatasourceType type, java.util.Map<java.lang.String,java.lang.String> parameters, java.util.List<java.lang.String> handleIds, boolean allowOverwrite)
          Register a datasource at the factory.
static void registerHandle(java.lang.String id, HandleType type, java.util.Map<java.lang.String,java.lang.String> parameters)
          Register a datasource handle at the factory.
static void registerHandle(java.lang.String id, HandleType type, java.util.Map<java.lang.String,java.lang.String> parameters, boolean allowOverwrite)
          Register a datasource handle at the factory.
protected static void startScheduler()
          Start the scheduler
protected static void stopScheduler()
          Stop the scheduler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createDatasource

public static Datasource createDatasource(java.util.Map handleprops)
Creates a new datasource handle with the specified properties as well as a new Datasource (with default properties).

Parameters:
handleprops - Handle properties used when initializing SQL handle.
Returns:
a new initialized Datasource
See Also:
Datasource, createDatasource(Map, Map)

createDatasource

public static Datasource createDatasource(java.util.Map handleprops,
                                          java.util.Map dsprops)
Creates a new Datasource connection with the specified properties which should point to a Content Repository of Gentics Content.Node. For every different datasource (different handleproperties) a datasource handle will be created and reused with the given pooling settings.
Note: the returned instance of Datasource is NOT thread-safe.
      Handle Property - Parameters:
      type - Type of the datasource. (jndi or jdbc)
      For JNDI:
      name - The name of the defined JNDI datasource.
      
      For JDBC:
      driverClass = The name of the JDBC class to be used (e.g. com.mysql.jdbc.Driver)
      url = The URL which describes the JDBC datasource. (e.g. jdbc:mysql://playground.office:3306/testdb?user=root)
      
      Optional JDBC Pool Parameters:
      maxActive = Controls the maximum number of objects that can be borrowed from the pool at one time.
      maxIdle = Controls the maximum number of objects that can sit idle in the pool at any time.
      
      for more options and more detailed documentation for JDBC Pool options
      take a look at the API documentation of
      GenericObjectPool
 

Parameters:
handleprops - Handle properties used when initializing SQL handle.
dsprops - Datasource properties, may be an empty map.
Returns:
a new and initialized Datasource or null if one of the parameters where null or the sanity check failed. Datasource may be unusable (DatasourceNotAvailableException) if invalid properties where given.

createMultichannellingDatasource

public static MultichannellingDatasource createMultichannellingDatasource(java.util.Map<java.lang.String,java.lang.String> handleProps,
                                                                          java.util.Map<java.lang.String,java.lang.String> dsProps)
Create a new instance of a multichannelling datasource

Parameters:
handleProps - handle properties
dsProps - datasource properties
Returns:
instance of the multichannelling datasource or null

getContentObject

public static Resolvable getContentObject(java.lang.String contentId,
                                          Datasource datasource)
                                   throws DatasourceNotAvailableException
Returns a content object with the given content id.

Parameters:
contentId - The content id of the object which should be returned. ([objecttype].[object id] e.g. 10002.123)
datasource - Datasource used to load the content object.
Returns:
the content object corresponding to the given content id. This method returns null if datasource is null or contentid is null or it doesn't exist or the syntax of the contentid is wrong.
Throws:
DatasourceNotAvailableException

createExpression

public static Expression createExpression(java.lang.String rule)
                                   throws ParserException
Parse the given expression string into an Expression. You should reuse parsed Expressions whereever possible as well as reuse DatasourceFilters which are created from those expressions.

Parameters:
rule - The Rule string to be parsed as Expression.
Returns:
the parsed Expression.
Throws:
ParserException
See Also:
Datasource.createDatasourceFilter(Expression)

createRuleTree

public static RuleTree createRuleTree(java.lang.String rule)
                               throws ParserException
Deprecated. deprecated, replaced by createExpression(String)

Creates a new RuleTree with the given rule string. Take care that you reuse parsed RuleTree's wherever possible by replacing the resolver. Parsing strings to RuleTrees is cpu expensive.

Parameters:
rule - The rule string which is used to initialize the RuleTree
Returns:
a new and initialized RuleTree to match the given rule string.
Throws:
ParserException - when rule has invalid syntax or is null.
See Also:
RuleTree

createWriteableDatasource

public static WriteableDatasource createWriteableDatasource(java.util.Map handleProperties)
Creates a new datasource handle with the specified properties as well as a new writeable datasource (with default properties).

Parameters:
handleProperties - Handle properties used when initializing SQL handle.
Returns:
The WriteableDatasource which might be used to read/write content objects.

createWriteableDatasource

public static WriteableDatasource createWriteableDatasource(java.util.Map handleProperties,
                                                            java.util.Map datasourceProperties)
Creates a new datasource handle with the specified properties as well as a new writeable datasource with the specified properties.

Parameters:
handleProperties - Handle properties used when initializing SQL handle.
datasourceProperties - Datasource properties, may be an empty map.
Returns:
The WriteableDatasource which might be used to read/write content objects or null if the sanity check failed

createWritableMultichannellingDatasource

public static WritableMultichannellingDatasource createWritableMultichannellingDatasource(java.util.Map<java.lang.String,java.lang.String> handleProps,
                                                                                          java.util.Map<java.lang.String,java.lang.String> dsProps)
Create a new writeable multichannelling datasource instance

Parameters:
handleProps - handle properties
dsProps - datasource properties
Returns:
instance of the datasource or null

getChangeableContentObject

public static Changeable getChangeableContentObject(java.lang.String contentId,
                                                    WriteableDatasource datasource)
                                             throws DatasourceNotAvailableException
Returns a changeable content object with the given content id.

Parameters:
contentId - The content id of the object which should be returned. ([objecttype].[object id] e.g. 10002.123)
datasource - Writeable Datasource used to load the content object.
Returns:
the content object corresponding to the given content id.
Throws:
DatasourceNotAvailableException

prefillAttributes

public static void prefillAttributes(Datasource ds,
                                     java.util.Collection<Resolvable> objects,
                                     java.util.List<java.lang.String> prefillAttributes)
                              throws NodeException
Prefill the given attributes for objects which were fetched from the given datasource

Parameters:
ds - datasource
objects - collection of objects fetched from the datasource
prefillAttributes - list of attributes to be prefilled
Throws:
NodeException

startScheduler

protected static void startScheduler()
Start the scheduler


stopScheduler

protected static void stopScheduler()
Stop the scheduler. This method should be called before the factory is taken out of service


destroyDatasourceFactories

protected static void destroyDatasourceFactories()
Destroy all created datasource factories, close all handles (closing database connections)


destroy

public static void destroy()
Destroy the portal connector factory, close all database connections, remove the scheduler (created background threads). This method must be called to take the PortalConnectorFactory out of service


registerHandle

public static void registerHandle(java.lang.String id,
                                  HandleType type,
                                  java.util.Map<java.lang.String,java.lang.String> parameters)
                           throws DuplicateIdException,
                                  NodeException
Register a datasource handle at the factory.

Parameters:
id - id of the datasource handle
type - handle type
parameters - handle parameters
Throws:
DuplicateIdException - if a handle with that id was already registered
NodeException - if the parameters are invalid

registerHandle

public static void registerHandle(java.lang.String id,
                                  HandleType type,
                                  java.util.Map<java.lang.String,java.lang.String> parameters,
                                  boolean allowOverwrite)
                           throws DuplicateIdException,
                                  NodeException
Register a datasource handle at the factory. With this method, it is possible to re-register an existing handle with different parameters

Parameters:
id - id of the datasource handle
type - handle type
parameters - handle parameters
allowOverwrite - true if overwriting existing handles should be allowed
Throws:
DuplicateIdException - if a handle with that id was already registered and allowOverwrite was false
NodeException - if the parameters are invalid

registerDatasource

public static void registerDatasource(java.lang.String id,
                                      DatasourceType type,
                                      java.util.Map<java.lang.String,java.lang.String> parameters,
                                      java.util.List<java.lang.String> handles)
                               throws DuplicateIdException,
                                      NodeException
Register a datasource at the factory.

Parameters:
id - datasource id
type - datasource type
parameters - datasource parameters
handles - list of datasource handle ids
Throws:
DuplicateIdException - if a datasource with that id was already registered
NodeException

registerDatasource

public static void registerDatasource(java.lang.String id,
                                      DatasourceType type,
                                      java.util.Map<java.lang.String,java.lang.String> parameters,
                                      java.util.List<java.lang.String> handleIds,
                                      boolean allowOverwrite)
                               throws DuplicateIdException,
                                      NodeException
Register a datasource at the factory.

Parameters:
id - datasource id
type - datasource type
parameters - datasource parameters
handleIds - list of datasource handle ids
allowOverwrite - true if overwriting existing datasources should be allowed, false if not
Throws:
DuplicateIdException - if a datasource with that id was already registered and allowOverwrite was false
NodeException

isAutoRepair

public static boolean isAutoRepair()
Check whether the auto-repair functionality is switched on or off by configuration. Default is on

Returns:
true when auto-repair is on, false if not

isAutoRepair2

public static boolean isAutoRepair2()
Check whether the auto-repair2 functionality is switched on or off by configuration. Default is off

Returns:
true when auto-repair2 is on, false if not

getAvailableDatasources

public static java.util.List<java.lang.String> getAvailableDatasources()
Get the list of all available datasource ids

Returns:
lsit of available datasource ids

getAvailableDatasources

public static java.util.List<java.lang.String> getAvailableDatasources(java.lang.Class<? extends Datasource> datasourceClass)
Get the available datasources as list of ids

Parameters:
datasourceClass - datasource class. If null, all available datasources will be returned
Returns:
list of available datasource ids

createDatasource

public static Datasource createDatasource(java.lang.String id)
                                   throws NodeException
Create a datasource instance for the datasource with given id

Parameters:
id - datasource id
Returns:
datasource instance (never null)
Throws:
NodeException - if no datasource with given id was registered

createDatasource

public static <T extends Datasource> T createDatasource(java.lang.Class<T> clazz,
                                                        java.lang.String id)
                                             throws NodeException
Create a datasource instance of the given class with given id

Parameters:
clazz - datasource class
id - datasource id
Returns:
datasource instance
Throws:
NodeException - if no datasource with given id was registered or if the datasource does not implement the given class


Copyright © 2013 Gentics Software GmbH. All Rights Reserved.