Holger's Java API

## com.antelmann.sql
Class MySqlQueryToViewMapper<T extends DBEntry>

    java.lang.Object
      com.antelmann.sql.BaseRowMapper<T>
          com.antelmann.sql.MySqlQueryToViewMapper<T>

All Implemented Interfaces:
  TransactionRequired, MappingInfo, ObjectRowMapper<T>, Converter<RowItem,T>

    public abstract class MySqlQueryToViewMapper<T extends DBEntry>

extends BaseRowMapper<T>

enables the automated use of views with MySQL for better performance

Since:
  01.09.2016, 15:54:27
Author:
  holger
See Also:
  `setTableQuery(String)`, `checkMySqlViewForQuery(BaseRowMapper, String)`

Nested Class Summary

Nested classes/interfaces inherited from interface com.antelmann.util.Converter
`Converter.Adapter<T1,T2>`

Field Summary
`static boolean` `enabled`

Fields inherited from class com.antelmann.sql.BaseRowMapper
`db, helper`

Constructor Summary
`MySqlQueryToViewMapper(Database<Connection> db, MappingInfo mi, IDFactory idFactory, Class<T> type, Object... topics)`
`MySqlQueryToViewMapper(Database<Connection> db, String tableName, String idColumn)`
`MySqlQueryToViewMapper(Database<Connection> db, String tableName, String idColumn, IDFactory idFactory, Class<T> type)`
`MySqlQueryToViewMapper(Database<Connection> db, String tableName, String idColumn, String displayColumn)`
`MySqlQueryToViewMapper(Database<Connection> db, String tableName, String idColumn, String displayColumn, IDFactory idFactory, Class<T> type)`
`MySqlQueryToViewMapper(Database<Connection> db, String tableName, String idColumn, String displayColumn, IDFactory idFactory, Class<T> type, String query)`

Method Summary
`static String` `checkMySqlViewForQuery(BaseRowMapper<?> mapper, String tableQuery)` checks whether an appropriate view already exists for the given mapper and creates one based on the given query if it doesn't exist.
`static int` `deleteAssociatedViews(Database<Connection> db)`
`static boolean` `isEnabled()`
`static void` `setEnabled(boolean enabled)` allows to globally disable the use/creation of views
`void` `setTableQuery(String tableQuery)` allows to set a query for mapping the data instead of just using the table name.
`static String` `trimIfApplicable(String columnName)`

Methods inherited from class com.antelmann.sql.BaseRowMapper

`addColumnsForTopic, applyFromMapping, checkExistence, convert, convertBack, convertTopicFilter, emptyStringsToNull, extractReference, extractStub, extractStub, generateNewID, generateRowProperties, getAll, getColumnDisplayMapping, getColumnNames, getColumnsForTopic, getColumnSize, getConnection, getConnectionHelper, getDisplayColumn, getDisplayNameForColumn, getEntryClass, getEntryClassMapper, getIDColumn, getIDFactory, getMappedValue, getMappingForTopic, getNextIntID, getNextIntIDFactory, getNextIntIDFactory, getPreStoreFilter, getReadOnlyColumns, getRestrictMappedColumns, getResultSet, getSQLTypeforColumn, getStubColumns, getStubQuery, getStubResultSet, getSupportedTopicColumns, getTableColumnNames, getTableName, getTableQuery, getTableQueryForComboFilter, getTransactionCounter, getUniqueRandomString, handleAfterStore, initMapping, isMappedTopic, isTranslate, javaToSql, javaToSql, lockTable, mapReference, mapReference, mapToRow, removeColumnTopic, setColumnsForTopic, setDisplayColumn, setEntryClass, setEntryClassMapper, setIDFactory, setMappedValue, setNextIntIdAsFactory, setPreStoreFilter, setReadOnlyColumns, setRestrictedMappedColumns, setStubQuery, setTableQuery, setTopic, setTranslate, sqlToJava, toSQLMap, verifyBeforeDelete, verifyBeforeStore`

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

Methods inherited from interface com.antelmann.sql.ObjectRowMapper
`instantiate`

Field Detail

### enabled

    public static boolean enabled

Constructor Detail

### MySqlQueryToViewMapper

    public MySqlQueryToViewMapper(Database<Connection> db,
                                  MappingInfo mi,
                                  IDFactory idFactory,
                                  Class<T> type,
                                  Object... topics)
                           throws DatabaseException

Throws:
  `DatabaseException`

### MySqlQueryToViewMapper

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

Throws:
  `DatabaseException`

### MySqlQueryToViewMapper

    public MySqlQueryToViewMapper(Database<Connection> db,
                                  String tableName,
                                  String idColumn,
                                  String displayColumn,
                                  IDFactory idFactory,
                                  Class<T> type,
                                  String query)
                           throws DatabaseException

Throws:
  `DatabaseException`

### MySqlQueryToViewMapper

    public MySqlQueryToViewMapper(Database<Connection> db,
                                  String tableName,
                                  String idColumn,
                                  String displayColumn,
                                  IDFactory idFactory,
                                  Class<T> type)
                           throws DatabaseException

Throws:
  `DatabaseException`

### MySqlQueryToViewMapper

    public MySqlQueryToViewMapper(Database<Connection> db,
                                  String tableName,
                                  String idColumn,
                                  String displayColumn)
                           throws DatabaseException

Throws:
  `DatabaseException`

### MySqlQueryToViewMapper

    public MySqlQueryToViewMapper(Database<Connection> db,
                                  String tableName,
                                  String idColumn)
                           throws DatabaseException

Throws:
  `DatabaseException`

Method Detail

### setTableQuery

    public void setTableQuery(String tableQuery)
                       throws DatabaseException

  Description copied from class: `BaseRowMapper`
  allows to set a query for mapping the data instead of just using the table name. This method calls `BaseRowMapper.initMapping()` after setting the data. Since a query of the form '(select ...) as t1' may not be query optimized in certain databases, this implementation also supports a plain select statement to act as a query.

  Overrides:
    `setTableQuery` in class `BaseRowMapper<T extends DBEntry>`
  Throws:
    `DatabaseException`
  See Also:
    `checkMySqlViewForQuery(BaseRowMapper, String)`

### checkMySqlViewForQuery

    public static String checkMySqlViewForQuery(BaseRowMapper<?> mapper,
                                                String tableQuery)
                                         throws DatabaseException

  checks whether an appropriate view already exists for the given mapper and creates one based on the given query if it doesn't exist. If a view with the derived name for this mapper already exists, it is assumed that this is the appropriate view that already holds the correct query for this purpose. You can always easily regenerate all views by deleting the view names in question. Note that the described mechanism can be circumvented by disabling this class.

  Parameters:
    `mapper` - denotes the mapper this operation applies to
    `tableQuery` - the query string that will be used to create the view if it doesn't already exist
  Returns:
    the name of the view to be used when setting the table query for the super class
  Throws:
    `DatabaseException`
  See Also:
    `setEnabled(boolean)`, `setTableQuery(String)`

### isEnabled

    public static boolean isEnabled()

### setEnabled

    public static void setEnabled(boolean enabled)

  allows to globally disable the use/creation of views

### trimIfApplicable

    public static String trimIfApplicable(String columnName)

### deleteAssociatedViews

    public static int deleteAssociatedViews(Database<Connection> db)
                                     throws SQLException

  Throws:
    `SQLException`

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