com.isomorphic.datasource

## Class AuditDSGenerator

- java.lang.Object
- - com.isomorphic.datasource.AuditDSGenerator

-     public class AuditDSGenerator
      extends java.lang.Object

  This class implements a `DynamicDSGenerator` which generates an audit `DataSource` based on a `DataSource` which has auditing enabled.

  An audit `DataSource` is a `DataSource` which basically inherits from the original `DataSource` and adds some additional metadata which allows storing the timestamp, revision, user and operation type in addition to record field values on each add, update and remove operations.

  In order to enable audit for a `DataSource` you have to specify the audit=true property.

  There are additional properties which can be specified in order to control how the new fields are named:

  - auditUserFieldName - specify the field name used to store the user who performed the operation. If empty string is specified as value, then this field won't be created. Default value is user.
  - auditRevisionFieldName - specify the field name used to store the revision information. If empty string is specified as value, then this field won't be created. Default value is revision.
  - auditTimeStampFieldName - specify the field name used to store the timestamp of the operation. If empty string is specified as value, then this field won't be created. Default value is timestamp.
  - auditTypeFieldName - specify the field name used to store the operation type. If empty string is specified as value, then this field won't be created. Default value is type.
  - auditDataSourceID - the id of the generated `DataSource`. Default value is audit_[OriginalDSID].

  In addition to this, setting audit=false property on a field will disable tracking on that field. In effect, the field won't be stored in the audit `DataSource`

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addMapping(java.lang.String auditDSID, java.lang.String dsID)` Add a mapping between an audit `DataSource` and audited `DataSource`
    `static java.lang.Integer` | `getAuditChangedFieldsFieldLength(DataSource ds)` Get the "changed fields" field length configured for the given `DataSource`.
    `static java.lang.String` | `getAuditChangedFieldsFieldName(DataSource ds)` Get the "changed fields" field name configured for the given `DataSource`.
    `static java.lang.String` | `getAuditDSConstructor(DataSource ds)` Get the serverConstructor configured for the given `DataSource`
    `static java.lang.String` | `getAuditRevisionFieldName(DataSource ds)` Get the revision field name configured for the given `DataSource`.
    `static java.lang.String` | `getAuditSchemaName(DataSource ds)` Get the audit schema configured for the given `DataSource`
    `static java.lang.String` | `getAuditTimestampFieldName(DataSource ds)` Get the timestamp field name configured for the given `DataSource`.
    `static java.lang.String` | `getAuditTypeFieldName(DataSource ds)` Get the type field name configured for the given `DataSource`.
    `static java.lang.String` | `getAuditUserFieldName(DataSource ds)` Get the user field name configured for the given `DataSource`.
    `boolean` | `hasMappingFor(java.lang.String auditDSID)` Returns true if the specified audit `DataSource` is already mapped inside the `AuditDSGenerator`

- - ### Method Detail

    - #### getAuditRevisionFieldName

          public static java.lang.String getAuditRevisionFieldName(DataSource ds)

      Get the revision field name configured for the given `DataSource`.
      Parameters:
        `ds` - the audit `DataSource` for which we want to retrieve the revision field name.
      Returns:
        the field name representing the revision field configured for the audit `DataSource` passed as parameter.

    - #### getAuditChangedFieldsFieldName

          public static java.lang.String getAuditChangedFieldsFieldName(DataSource ds)

      Get the "changed fields" field name configured for the given `DataSource`.
      Parameters:
        `ds` - the audit `DataSource` for which we want to retrieve the "changed fields" field name.
      Returns:
        the field name representing the "changed fields" field configured for the audit `DataSource` passed as parameter.

    - #### getAuditChangedFieldsFieldLength

          public static java.lang.Integer getAuditChangedFieldsFieldLength(DataSource ds)

      Get the "changed fields" field length configured for the given `DataSource`.
      Parameters:
        `ds` - the audit `DataSource` for which we want to retrieve the "changed fields" field length.
      Returns:
        the configured or default length to use for the "changed fields" field for the audit `DataSource` passed as parameter.

    - #### getAuditTimestampFieldName

          public static java.lang.String getAuditTimestampFieldName(DataSource ds)

      Get the timestamp field name configured for the given `DataSource`.
      Parameters:
        `ds` - the audit `DataSource` for which we want to retrieve the timestamp field name.
      Returns:
        the field name representing the timestamp field configured for the audit `DataSource` passed as parameter.

    - #### getAuditTypeFieldName

          public static java.lang.String getAuditTypeFieldName(DataSource ds)

      Get the type field name configured for the given `DataSource`.
      Parameters:
        `ds` - the audit `DataSource` for which we want to retrieve the type field name.
      Returns:
        the field name representing the type field configured for the audit `DataSource` passed as parameter.

    - #### getAuditUserFieldName

          public static java.lang.String getAuditUserFieldName(DataSource ds)

      Get the user field name configured for the given `DataSource`.
      Parameters:
        `ds` - the audit `DataSource` for which we want to retrieve the user field name.
      Returns:
        the field name representing the user field configured for the audit `DataSource` passed as parameter.

    - #### getAuditSchemaName

          public static java.lang.String getAuditSchemaName(DataSource ds)

      Get the audit schema configured for the given `DataSource`
      Parameters:
        `ds` - the audit `DataSource` for which we want to retrieve schema name.
      Returns:
        the schema name configured for the audit `DataSource` passed as parameter.

    - #### getAuditDSConstructor

          public static java.lang.String getAuditDSConstructor(DataSource ds)

      Get the serverConstructor configured for the given `DataSource`
      Parameters:
        `ds` - the audit `DataSource` for which we want to retrieve the serverConstructor.
      Returns:
        the serverConstructor configured for the audit `DataSource` passed as parameter.

    - #### addMapping

          public void addMapping(java.lang.String auditDSID,
                                 java.lang.String dsID)

      Add a mapping between an audit `DataSource` and audited `DataSource`
      Parameters:
        `auditDSID` - the audit `DataSource` to be generated
        `dsID` - the audited `DataSource` for which we need to generate the audit DataSource

    - #### hasMappingFor

          public boolean hasMappingFor(java.lang.String auditDSID)

      Returns true if the specified audit `DataSource` is already mapped inside the `AuditDSGenerator`
      Parameters:
        `auditDSID` - auditDSID the audit `DataSource` to be generated
      Returns:
        true if the audit `DataSource` is already mapped by the `AuditDSGenerator`