org.openstreetmap.osmosis.core.pgsql.v0_6.impl
Class EntityMapper<T extends Entity>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.pgsql.v0_6.impl.EntityMapper<T>
Type Parameters:
T - The entity type to be supported.
Direct Known Subclasses:
NodeMapper, RelationMapper, WayMapper

public abstract class EntityMapper<T extends Entity>
extends java.lang.Object

Provides functionality common to all database entity builder implementations.

Author:
Brett Henderson

Constructor Summary
EntityMapper()
           
 
Method Summary
protected  OsmUser buildUser(java.sql.ResultSet resultSet)
          Creates a new user record based upon the current result set row.
abstract  java.lang.Class<T> getEntityClass()
          Returns the class type for the entity.
abstract  java.lang.String getEntityName()
          Returns the name of the entity to substitute into SQL statements.
abstract  ActionDataType getEntityType()
          Returns the action data type of the entity.
 java.lang.String getSqlDelete(boolean filterByEntityId)
          The SQL UPDATE statement for logically deleting entities.
 java.lang.String getSqlInsert(int rowCount)
          The SQL INSERT statement for adding entities.
 java.lang.String getSqlSelect(boolean filterByEntityId, boolean orderByEntityId)
          The SQL SELECT statement for retrieving entity details.
 java.lang.String getSqlSelectCount(boolean filterByEntityId)
          The SQL SELECT statement for counting entities.
 java.lang.String getSqlUpdate(boolean filterByEntityId)
          The SQL UPDATE statement for updating entity details.
protected abstract  java.lang.String[] getTypeSpecificFieldNames()
          Produces an array of additional column names specific to this entity type to be returned by entity queries.
abstract  T parseRecord(java.sql.ResultSet resultSet)
          Creates a new entity based upon the current row in the result set.
protected  int populateCommonEntityParameters(java.sql.PreparedStatement statement, int initialIndex, Entity entity)
          Sets common entity values as bind variable parameters to an entity insert query.
abstract  int populateEntityParameters(java.sql.PreparedStatement statement, int initialIndex, T entity)
          Sets entity values as bind variable parameters to an entity insert query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EntityMapper

public EntityMapper()
Method Detail

getEntityName

public abstract java.lang.String getEntityName()
Returns the name of the entity to substitute into SQL statements. This is a low-tech way of making the queries type independent.

Returns:
The entity name as defined in the database schema.

getEntityType

public abstract ActionDataType getEntityType()
Returns the action data type of the entity.

Returns:
The action type.

getEntityClass

public abstract java.lang.Class<T> getEntityClass()
Returns the class type for the entity.

Returns:
The entity type class.

getSqlSelectCount

public java.lang.String getSqlSelectCount(boolean filterByEntityId)
The SQL SELECT statement for counting entities. It will return a count of matching records.

Parameters:
filterByEntityId - If true, a WHERE clause will be added filtering by the entity id column.
Returns:
The SQL string.

getTypeSpecificFieldNames

protected abstract java.lang.String[] getTypeSpecificFieldNames()
Produces an array of additional column names specific to this entity type to be returned by entity queries.

Returns:
The column names.

getSqlSelect

public java.lang.String getSqlSelect(boolean filterByEntityId,
                                     boolean orderByEntityId)
The SQL SELECT statement for retrieving entity details.

Parameters:
filterByEntityId - If true, a WHERE clause will be added filtering by the entity id column.
orderByEntityId - If true, an ORDER BY clause will be added ordering by the entity id column.
Returns:
The SQL string.

getSqlInsert

public java.lang.String getSqlInsert(int rowCount)
The SQL INSERT statement for adding entities.

Parameters:
rowCount - The number of rows to insert in a single statement.
Returns:
The SQL string.

getSqlUpdate

public java.lang.String getSqlUpdate(boolean filterByEntityId)
The SQL UPDATE statement for updating entity details.

Parameters:
filterByEntityId - If true, a WHERE clause will be added filtering by the entity id column.
Returns:
The SQL String.

getSqlDelete

public java.lang.String getSqlDelete(boolean filterByEntityId)
The SQL UPDATE statement for logically deleting entities.

Parameters:
filterByEntityId - If true, a WHERE clause will be added filtering by the entity id column.
Returns:
The SQL String.

parseRecord

public abstract T parseRecord(java.sql.ResultSet resultSet)
Creates a new entity based upon the current row in the result set.

Parameters:
resultSet - The result set to read from.
Returns:
The newly built entity object.

buildUser

protected OsmUser buildUser(java.sql.ResultSet resultSet)
Creates a new user record based upon the current result set row.

Parameters:
resultSet - The result set to read from.
Returns:
The newly build user object.

populateCommonEntityParameters

protected int populateCommonEntityParameters(java.sql.PreparedStatement statement,
                                             int initialIndex,
                                             Entity entity)
Sets common entity values as bind variable parameters to an entity insert query.

Parameters:
statement - The prepared statement to add the values to.
initialIndex - The offset index of the first variable to set.
entity - The entity containing the data to be inserted.
Returns:
The current parameter offset.

populateEntityParameters

public abstract int populateEntityParameters(java.sql.PreparedStatement statement,
                                             int initialIndex,
                                             T entity)
Sets entity values as bind variable parameters to an entity insert query.

Parameters:
statement - The prepared statement to add the values to.
initialIndex - The offset index of the first variable to set.
entity - The entity containing the data to be inserted.
Returns:
The current parameter offset.