com.jenkov.mrpersister.itf.mapping
Interface IDbNameDeterminer

All Known Implementing Classes:
DbNameDeterminer, DbNameDeterminerOld

public interface IDbNameDeterminer

This interface represents the database name determiner to be used with Mr. Persister. The responsibility of the database name determiner is to determine which column name of a given collection of names exists in the table in the database.

The database name determiner is used internally in the object mapper. The collection of possible column names is usually generated by the database name guesser, also used internally in the object mapper.

Author:
Jakob Jenkov, Jenkov Development

Method Summary
 java.lang.String determineColumnName(java.util.Collection names, java.lang.String tableName, java.sql.Connection connection)
          Determines which, if any, of the given possible column names in the given collection is matching a column name in the given table.
 java.lang.String determineTableName(java.util.Collection names, java.sql.Connection connection)
          Determines which, if any, of the given possible table names in the given collection is matching a table name in the database.
 java.lang.String determineTableName(java.util.Collection names, java.lang.String databaseName, java.sql.Connection connection)
          Determines which, if any, of the given possible table names in the given collection is matching a table name in the database.
 int getColumnType(java.lang.String columnName, java.lang.String tableName)
          Returns the type for a given column in a given table.
 

Method Detail

getColumnType

int getColumnType(java.lang.String columnName,
                  java.lang.String tableName)
Returns the type for a given column in a given table. Note, this method only works if the determineColumnName worked (returned a name != null)

Parameters:
columnName - The name of the column to get the data type for.
tableName - The name of the table where the column is defined.
Returns:
An int matching one of the java.sql.Types.XXX type constants.

determineColumnName

java.lang.String determineColumnName(java.util.Collection names,
                                     java.lang.String tableName,
                                     java.sql.Connection connection)
                                     throws PersistenceException
Determines which, if any, of the given possible column names in the given collection is matching a column name in the given table. If no column name is matching any of the names in the collection null is returned. If more than one of the possible column names matches a column in the table, a PersistenceException is thrown.

Parameters:
names - The collection of possible column names.
tableName - The name of the database table to check for column matches in.
connection - The connection to the database to determine column name in.
Returns:
The matching column name. Null if no matching column name was found.
Throws:
PersistenceException - If anything goes wrong during the name determining, or if more than one of the possible column names matches a column in the table.

determineTableName

java.lang.String determineTableName(java.util.Collection names,
                                    java.sql.Connection connection)
                                    throws PersistenceException
Determines which, if any, of the given possible table names in the given collection is matching a table name in the database. If no table name is matching any of the names in the collection a PersistenceException is thrown. If more than one of the possible table names matches a table in the database a PersistenceException is also thrown.

Parameters:
names - The collection of possible table names.
connection - The connection to the database to determine table name in.
Returns:
The matching table name.
Throws:
PersistenceException - If anything goes wrong during the name determining, or if none or more than one of the possible table names matches a table in the database.

determineTableName

java.lang.String determineTableName(java.util.Collection names,
                                    java.lang.String databaseName,
                                    java.sql.Connection connection)
                                    throws PersistenceException
Determines which, if any, of the given possible table names in the given collection is matching a table name in the database. If no table name is matching any of the names in the collection a PersistenceException is thrown. If more than one of the possible table names matches a table in the database a PersistenceException is also thrown.

Parameters:
names - The collection of possible table names.
databaseName - The name of the database. Set to null if not known. The database name is usually implicitly referenced in the database connection, so you most often won't need to set this parameter to anything but null.
connection - The connection to the database to determine table name in.
Returns:
The matching table name.
Throws:
PersistenceException - If anything goes wrong during the name determining, or if none or more than one of the possible table names matches a table in the database.