com.ca.jcs.jdbc
Class JDBCAttributeStyleOpProcessor

java.lang.Object
  extended by com.ca.jcs.processor.AbstractBaseProcessor
      extended by com.ca.jcs.processor.AbstractAttributeStyleOpProcessor
          extended by com.ca.jcs.processor.AbstractAttributeStyleOpProcessorAssocDirect
              extended by com.ca.jcs.assoc.DefaultAssocDirectAttributeOpProcessor
                  extended by com.ca.jcs.assoc.DefaultAssocAttributeOpProcessor
                      extended by com.ca.jcs.jdbc.JDBCAttributeStyleOpProcessor
All Implemented Interfaces:
Activatable, AssocAttributeOpProcessor, AssocDirectAttributeOpProcessor, AssocIndirectAttributeOpProcessor, AttributeStyleOpProcessor, OpProcessor, PostQueryAttributesProcessor
Direct Known Subclasses:
ORAAttributeStyleOpProcessor

public class JDBCAttributeStyleOpProcessor
extends DefaultAssocAttributeOpProcessor

A dynamic JDBC connector driven by metadata which specifies all mapping information for Account, Group and Connection (Endpoint) classes.


Nested Class Summary
static class JDBCAttributeStyleOpProcessor.VendorTypeHandling
          Defines various JDBC type treatment options
 
Nested classes/interfaces inherited from class com.ca.jcs.assoc.DefaultAssocDirectAttributeOpProcessor
DefaultAssocDirectAttributeOpProcessor.AssocAttrValue, DefaultAssocDirectAttributeOpProcessor.AssociationStyle
 
Nested classes/interfaces inherited from interface com.ca.jcs.processor.OpProcessor
OpProcessor.MethodName
 
Field Summary
protected  JDBCMetaConnector connector
           
protected  DataSource dataSource
           
protected  MetaDataDefs.GeneratedOverrideStatus generatedOverrideStatus
           
protected  Logger log
           
protected  long searchTimeout
           
static SQLMultiValueFlattener SQL_FLATTENER
          Helps formatting SQL literals and "IN" lists.
protected  TransactionManager transactionManager
           
protected  long transactionTimeout
           
 
Fields inherited from class com.ca.jcs.assoc.DefaultAssocAttributeOpProcessor
proxiedAssocSelf
 
Fields inherited from class com.ca.jcs.assoc.DefaultAssocDirectAttributeOpProcessor
metaConnector
 
Fields inherited from class com.ca.jcs.processor.AbstractAttributeStyleOpProcessor
proxiedSelf
 
Fields inherited from class com.ca.jcs.processor.AbstractBaseProcessor
ldapExceptionPrefix
 
Constructor Summary
JDBCAttributeStyleOpProcessor(BaseConnector connector)
           
 
Method Summary
 void activate()
          Sets proxiedSelf to OpBindings-aware proxy if any OpBindings are configured, otherwise left assigned to "this".
 void addAttrAssocs(ObjectInfo objInfo, Association assoc, Attribute attr, Object context)
          Note delegates to super class if assoc is of direct flavour.
 void deactivate()
          We also define this for symmetry as activate() is defined.
 void deleteAssocs(ObjectInfo objInfo, boolean fromObj, Collection<Association> assocs, Object context)
          Don't need to worry about direct associations (and hence super class) here, as this method is part of the AssocIndirectAttributeOpProcessor interface only, and not used for direct associations.
 void doAdd(ObjectInfo objInfo, Attributes attrs)
          Handle adding new objects, both normal and compound.
protected  void doAddCompound(ObjectInfo compChildObjInfo, Association assoc, Attribute attr, String parentKeyVal)
          Create compound object
 void doDelete(ObjectInfo objInfo)
          Delete the object referenced by objInfo from a managed system.
 void doDeleteAssocs(ObjectInfo objInfo, Object context)
          Delete all associations referencing target object referred to by objInfo.
 Attributes doLookUp(ObjectInfo objInfo, String[] attrIds)
          Look up the provided attribute names on the managed object referenced by objInfo, attribute ids not mapped to connector-speak will either be discarded or cause an error depending on the level of strictness configured for the parent connector.
 void doLookupAssocs(ObjectInfo objInfo, Association[] associations, Attributes attrs, Object context)
          Look provided associations for object referenced by objInfo, updating attrs with any information found.
 Attribute doLookupExpensiveStub(ObjectInfo objInfo, String connAttrId)
          If the named attribute has a value on the managed system then return an attribute with a dummy value (without needing to fully retrieve the value persisted on the managed system).
 void doModify(ObjectInfo objInfo, ModificationItem[] origModItems)
          Process the provided modifications, where attributes involved in 1:1 and 1:N associative relationships are split out for separate individual processing.
 void doModifyAssocs(ObjectInfo objInfo, AssocModificationItem[] items, Object context)
          Process modifications to any associative relationships mentioned in items (each requires one or more separate SQL operations).
 void doModifyRn(ObjectInfo objInfo, Rdn newRdn)
          Implement a change of Relative Distnguished Name (RDN) by: copying all of its data (except its name) to a new row which is given the new name.
 void doModifyRnAssocs(ObjectInfo objInfo, Rdn newRdn, Object context)
          Update association attributes after the target object denoted by objInfo (which still refers to the old name) is renamed.
 void doMove(ObjectInfo objInfo, Name newParentName, Rdn newRn)
          Move the managed object referenced by objInfo to a new parent whilst also changing its RDN (of form "attr=value").
 void doMoveAssocs(ObjectInfo objInfo, Name newName, Object context)
          Update association attributes after the target object denoted by objInfo (which still refers to the old name) is moved to newName.
 NamingEnumeration<SearchResult> doSearch(ObjectInfo baseObjInfo, FilterInfo filterInfo, Map<String,String> environment, SearchControls searchControls)
          Perform a search where all details in the filter and search controls have been mapped to connector speak, results are mapped back to LDAP by the base class.
 NamingEnumeration<SearchResult> doSearchAssocs(MetaObjectClassMappings classMapppings, Association[] associations, NamingEnumeration<SearchResult> searchResults, String filterExpr, Object context)
          Find all associative field values in assocAttrIds in the search results provided in queryResults.
protected  String formAssocSearchSql(Association assoc, String filterExpr, int offset)
          form the sql to be used to search for associations
 int getAccountCount()
           
 DataModel getMetaData()
          Needed to get around spelling error of geMetaData() in JCS 1.0 release, ideally would be left abstract here and should be overridden in the concrete processor, for instance SDKAttributeStyleOpProcessor.
protected static int getPropertySqlType(MetaObjectClassMapping classMap, Attribute connAttr)
          Determine SQL type for an attribute, falling back to Spring's SqlReturnType.TYPE_UNKNOWN when no special handling is required.
 long getTransactionTimeout()
           
 void incAccountCount()
           
 void initObjectCount(String objectClass, int count)
           
 boolean isAccountQueryStreaming()
           
 void removeAttrAssocs(ObjectInfo objInfo, Association assoc, Attribute attr, Object context)
          Note delegates to super class if assoc is of direct flavour.
 void setMetaData(DataModel dataModel)
          Called when datamodel metadata used to configure this connector is changed.
 void setTransactionTimeout(long transactionTimeout)
           
 
Methods inherited from class com.ca.jcs.assoc.DefaultAssocDirectAttributeOpProcessor
doAssocSearchForReferencesTo, doAssocUpdateReferencesTo, expandTemplateValues, getAssocClassMap, getAssocConnAttrId, getAssocConnAttrIds, getAssocConnectorAttrIds, getAssocDataModelProp, getAssocLdapAttr, getAssocObjectClass, getAttrProc, getMetaConnector, updateAttrAssocs
 
Methods inherited from class com.ca.jcs.processor.AbstractAttributeStyleOpProcessorAssocDirect
convertConnectorDNToKey, convertConnectorDNToKeys, convertKeyToConnectorDN
 
Methods inherited from class com.ca.jcs.processor.AbstractAttributeStyleOpProcessor
isPostQueryPocessingActive, processPostQueryAttributes, processPostQuerySearchResult, setPostQueryPocessingActive
 
Methods inherited from class com.ca.jcs.processor.AbstractBaseProcessor
getBaseConnector, makeNamingException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connector

protected final JDBCMetaConnector connector

log

protected final Logger log

transactionManager

protected final TransactionManager transactionManager

dataSource

protected final DataSource dataSource

generatedOverrideStatus

protected MetaDataDefs.GeneratedOverrideStatus generatedOverrideStatus

transactionTimeout

protected long transactionTimeout

searchTimeout

protected long searchTimeout

SQL_FLATTENER

public static final SQLMultiValueFlattener SQL_FLATTENER
Helps formatting SQL literals and "IN" lists.

Constructor Detail

JDBCAttributeStyleOpProcessor

public JDBCAttributeStyleOpProcessor(BaseConnector connector)
Method Detail

getMetaData

public DataModel getMetaData()
Description copied from class: DefaultAssocDirectAttributeOpProcessor
Needed to get around spelling error of geMetaData() in JCS 1.0 release, ideally would be left abstract here and should be overridden in the concrete processor, for instance SDKAttributeStyleOpProcessor. Always throws a RuntimeException to ensure the fact it must be overridden is noticed if the method is ever called.

Specified by:
getMetaData in interface AttributeStyleOpProcessor
Overrides:
getMetaData in class DefaultAssocDirectAttributeOpProcessor
Returns:
Metadata used to configure this processor.

setMetaData

public void setMetaData(@NotNull
                        DataModel dataModel)
Description copied from interface: AttributeStyleOpProcessor
Called when datamodel metadata used to configure this connector is changed.

Parameters:
dataModel - New metadata to be internalised.

getAccountCount

public int getAccountCount()

activate

public void activate()
              throws NamingException
Description copied from class: AbstractAttributeStyleOpProcessor
Sets proxiedSelf to OpBindings-aware proxy if any OpBindings are configured, otherwise left assigned to "this".

Specified by:
activate in interface Activatable
Specified by:
activate in interface AttributeStyleOpProcessor
Overrides:
activate in class DefaultAssocAttributeOpProcessor
Throws:
NamingException

deactivate

public void deactivate()
Description copied from class: AbstractAttributeStyleOpProcessor
We also define this for symmetry as activate() is defined.

Specified by:
deactivate in interface Activatable
Specified by:
deactivate in interface AttributeStyleOpProcessor
Overrides:
deactivate in class AbstractAttributeStyleOpProcessor

initObjectCount

public void initObjectCount(String objectClass,
                            int count)

incAccountCount

public void incAccountCount()

isAccountQueryStreaming

public boolean isAccountQueryStreaming()

doDelete

public void doDelete(ObjectInfo objInfo)
              throws NamingException
Description copied from interface: OpProcessor
Delete the object referenced by objInfo from a managed system. Called by Partition.delete(org.apache.directory.shared.ldap.name.LdapDN) after mapping/validation/type conversion has been performed.

Parameters:
objInfo - References managed object to be deleted.
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

doDeleteAssocs

public void doDeleteAssocs(ObjectInfo objInfo,
                           Object context)
                    throws NamingException
Description copied from class: DefaultAssocDirectAttributeOpProcessor
Delete all associations referencing target object referred to by objInfo.

Specified by:
doDeleteAssocs in interface AssocAttributeOpProcessor
Overrides:
doDeleteAssocs in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Object to be deleted.
context - Optional field which can be provided additional context for the requested updates, eg transactional connectors may want the updates of the associative relationships to occur within a larger transaction.
Throws:
NamingException

deleteAssocs

public void deleteAssocs(ObjectInfo objInfo,
                         boolean fromObj,
                         Collection<Association> assocs,
                         Object context)
                  throws NamingException
Don't need to worry about direct associations (and hence super class) here, as this method is part of the AssocIndirectAttributeOpProcessor interface only, and not used for direct associations.

Throws:
NamingException

addAttrAssocs

public void addAttrAssocs(ObjectInfo objInfo,
                          Association assoc,
                          Attribute attr,
                          Object context)
                   throws NamingException
Note delegates to super class if assoc is of direct flavour.

Specified by:
addAttrAssocs in interface AssocAttributeOpProcessor
Overrides:
addAttrAssocs in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Object referenced.
assoc - Association through which object is referenced.
attr - Attribute containing new references to object which are to be stored.
context - Context if relevant to connector implementation (eg transaction, if supported).
Throws:
NamingException

removeAttrAssocs

public void removeAttrAssocs(ObjectInfo objInfo,
                             Association assoc,
                             Attribute attr,
                             Object context)
                      throws NamingException
Note delegates to super class if assoc is of direct flavour.

Specified by:
removeAttrAssocs in interface AssocAttributeOpProcessor
Overrides:
removeAttrAssocs in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Object referenced.
assoc - Association through which object is referenced.
attr - Attribute containing references to object, if null means "remove all references" (only supported by internal agreement within connector implementation, eg JDBC which uses indirect associations can remove all references without wasting time determining all currently existing links).
context - Context if relevant to connector implementation (eg transaction, if supported).
Throws:
NamingException

doAdd

public void doAdd(ObjectInfo objInfo,
                  Attributes attrs)
           throws NamingException
Handle adding new objects, both normal and compound. When adding compound values caller is responsible for having placed parent object's key in attrs before calling.

Parameters:
objInfo - Contains information for the managed object which is to be created, where its connector-speak distinguished Name (DN) is dictated by objInfo.getConnectorDn() and its objectClass= is dictated by objInfo.getobjectClassMapping().
attrs - Attributes to be stored on the managed object.
Throws:
LdapNameAlreadyBoundException - Should be thrown if an object with the specified name already exists, other NamingExceptions (preferably implementing LdapException) may also be thrown. Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

doAddCompound

protected void doAddCompound(ObjectInfo compChildObjInfo,
                             Association assoc,
                             Attribute attr,
                             String parentKeyVal)
                      throws NamingException
Create compound object

Throws:
NamingException

doModifyAssocs

public void doModifyAssocs(ObjectInfo objInfo,
                           AssocModificationItem[] items,
                           Object context)
                    throws NamingException
Process modifications to any associative relationships mentioned in items (each requires one or more separate SQL operations). Indirect associations are handled in this class and direct associations are delegated to super class.

Specified by:
doModifyAssocs in interface AssocAttributeOpProcessor
Overrides:
doModifyAssocs in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Information about target object whose associations are to be updated.
items - Modifications to associative relationships, which can be additions, deletions or replacements.
context - Optional field which can be provided additional context for the requested updates, eg transactional connectors may want the updates of the associative relationships to occur within a larger transaction.
Throws:
NamingException

doModify

public void doModify(ObjectInfo objInfo,
                     ModificationItem[] origModItems)
              throws NamingException
Process the provided modifications, where attributes involved in 1:1 and 1:N associative relationships are split out for separate individual processing.

Parameters:
objInfo - Details of object instance being modified.
origModItems -
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

getPropertySqlType

protected static int getPropertySqlType(MetaObjectClassMapping classMap,
                                        Attribute connAttr)
                                 throws NamingException
Determine SQL type for an attribute, falling back to Spring's SqlReturnType.TYPE_UNKNOWN when no special handling is required. Needs to allow for:
  1. special handling of time-related columns (TIMESTAMP/DATE/TIME) where some JDBC drivers require unexpected extra hints in order to behave properly.
  2. handle extremely weird case for DB2/MSSQL (but not ORA or other vendors) where null values can not be passed in as prepared statement args unless:
    1. ps.setNull(idx, Types.) is used (this code means Spring JDBC takes this path).
    2. a ps.setObject() is called on a previous arg

Throws:
NamingException

doSearch

public NamingEnumeration<SearchResult> doSearch(ObjectInfo baseObjInfo,
                                                FilterInfo filterInfo,
                                                Map<String,String> environment,
                                                SearchControls searchControls)
                                         throws NamingException
Perform a search where all details in the filter and search controls have been mapped to connector speak, results are mapped back to LDAP by the base class.

Parameters:
baseObjInfo -
filterInfo - Information about original LDAP filter including a version of it mapped to connector-speak.
environment -
searchControls - Return attributes have been mapped to connector-speak.
Returns:
Enumeration over search results with everything still in connector-speak (names/attribute names/attribute values).
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

formAssocSearchSql

protected String formAssocSearchSql(Association assoc,
                                    String filterExpr,
                                    int offset)
form the sql to be used to search for associations


doSearchAssocs

public NamingEnumeration<SearchResult> doSearchAssocs(MetaObjectClassMappings classMapppings,
                                                      Association[] associations,
                                                      NamingEnumeration<SearchResult> searchResults,
                                                      String filterExpr,
                                                      Object context)
                                               throws NamingException
Find all associative field values in assocAttrIds in the search results provided in queryResults.

Specified by:
doSearchAssocs in interface AssocAttributeOpProcessor
Overrides:
doSearchAssocs in class DefaultAssocDirectAttributeOpProcessor
Throws:
NamingException

doLookUp

public Attributes doLookUp(ObjectInfo objInfo,
                           String[] attrIds)
                    throws NamingException
Description copied from interface: OpProcessor
Look up the provided attribute names on the managed object referenced by objInfo, attribute ids not mapped to connector-speak will either be discarded or cause an error depending on the level of strictness configured for the parent connector. Extra attributes may also be returned. Called by Partition.lookup(org.apache.directory.shared.ldap.name.LdapDN) after mapping has been performed.

Parameters:
objInfo - Managed object for which attributes are to be looked up.
attrIds - Connector-speak identifiers of attributes which are to be returned, null means return all attributes and a zero length array means return no attributes (just a way to check an object's existance).
Returns:
Attributes values on specified managed object, where connector-speak mappings exist for specified attrIds, can be null when the target object exists but has none of the requested
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

doLookupExpensiveStub

public Attribute doLookupExpensiveStub(ObjectInfo objInfo,
                                       String connAttrId)
                                throws NamingException
If the named attribute has a value on the managed system then return an attribute with a dummy value (without needing to fully retrieve the value persisted on the managed system). In the case of JDBC this means a SELECT COUNT(*). If the named attribute doesn't have a value on the managed system then null is returned.

Specified by:
doLookupExpensiveStub in interface AttributeStyleOpProcessor
Overrides:
doLookupExpensiveStub in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Object to be looked up.
connAttrId - Expensive attribute being queried.
Returns:
Attribute with dummy value, or null.
Throws:
NamingException
See Also:
ValidationLazyAttributesProxy

doLookupAssocs

public void doLookupAssocs(ObjectInfo objInfo,
                           Association[] associations,
                           Attributes attrs,
                           Object context)
                    throws NamingException
Look provided associations for object referenced by objInfo, updating attrs with any information found.

Specified by:
doLookupAssocs in interface AssocAttributeOpProcessor
Overrides:
doLookupAssocs in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Target object for which associations need to be worked out.
associations - Associations declared against target's objectclass, all of which need to be checked.
attrs - Attributes to be returned for target object, multi-valued associative attribute settings may be added to them by this method.
context - Unused.
Throws:
NamingException

doModifyRn

public void doModifyRn(ObjectInfo objInfo,
                       Rdn newRdn)
                throws NamingException
Implement a change of Relative Distnguished Name (RDN) by:
  1. copying all of its data (except its name) to a new row which is given the new name.
  2. changing the name recorded in all association mappings to and from the object being changed.
  3. deleting the existing object.
.

Parameters:
objInfo - References managed object.
newRdn - New terminal name (having form "attr=val") for managed object.
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

doModifyRnAssocs

public void doModifyRnAssocs(ObjectInfo objInfo,
                             Rdn newRdn,
                             Object context)
                      throws NamingException
Description copied from class: DefaultAssocDirectAttributeOpProcessor
Update association attributes after the target object denoted by objInfo (which still refers to the old name) is renamed.

Specified by:
doModifyRnAssocs in interface AssocAttributeOpProcessor
Overrides:
doModifyRnAssocs in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Object to be modified, contains "old" name.
newRdn - New relative name (RN) for object, eg "namingAttr=newName".
context - Optional field which can be provided additional context for the requested updates, eg transactional connectors
Throws:
NamingException

doMoveAssocs

public void doMoveAssocs(ObjectInfo objInfo,
                         Name newName,
                         Object context)
                  throws NamingException
Description copied from class: DefaultAssocDirectAttributeOpProcessor
Update association attributes after the target object denoted by objInfo (which still refers to the old name) is moved to newName.

Specified by:
doMoveAssocs in interface AssocAttributeOpProcessor
Overrides:
doMoveAssocs in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Object to be modified, contains "old" name.
newName - New DN (distinguished name) for object, where parent folder and RN may have changed.
context - Optional field which can be provided additional context for the requested updates, eg transactional connectors may want the updates of the associative relationships to occur within a larger transaction.
Throws:
NamingException

doMove

public void doMove(ObjectInfo objInfo,
                   Name newParentName,
                   Rdn newRn)
            throws NamingException
Description copied from interface: OpProcessor
Move the managed object referenced by objInfo to a new parent whilst also changing its RDN (of form "attr=value"). Called by Partition.move(org.apache.directory.shared.ldap.name.LdapDN, org.apache.directory.shared.ldap.name.LdapDN, String, boolean) after mapping has been performed.

Parameters:
objInfo - References managed object to be moved.
newParentName - New parent for managed object.
newRn - New relative distinguished name (RDN) for managed object, will be either be null (just a move) or different from the object's current RDN (move and rename).
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

getTransactionTimeout

public long getTransactionTimeout()

setTransactionTimeout

public void setTransactionTimeout(long transactionTimeout)


Created 2011-07-14 13:27 EST