nl.gx.webmanager.services.seo.dao.impl
Class FriendlyURLEntityDAOImpl

java.lang.Object
  extended by nl.gx.webmanager.services.seo.dao.impl.FriendlyURLEntityDAOImpl
All Implemented Interfaces:
FriendlyURLEntityDAO
Direct Known Subclasses:
DBPageFriendlyURLEntityDAOImpl, MediaItemFriendlyURLEntityDAOImpl, PageFriendlyURLEntityDAOImpl

public abstract class FriendlyURLEntityDAOImpl
extends java.lang.Object
implements FriendlyURLEntityDAO

Data access methods for friendly URLs.

Author:
Sander Dahlberg

Constructor Summary
protected FriendlyURLEntityDAOImpl(SEODatabaseUtil seoDatabaseUtil)
          Constructor.
 
Method Summary
 void activate(FriendlyURLEntity entity)
          Activates the given entity.
 void create(FriendlyURLEntity entity)
          Inserts a new record for the given entity.
 void delete(FriendlyURLEntity entity)
          Deletes the given entity and its history.
 void deleteAll(FriendlyURLEntity entity)
          Deletes the given entity and all other related entities.
 void deleteById(FriendlyURLEntity entity)
          Deletes the given entity using its id.
protected  void determineSequenceNumber(java.sql.Connection connection, FriendlyURLEntity entity, java.util.List<FriendlyURLEntity> entities)
          Determines the sequence number for the given entity for ensuring URL uniqueness.
protected  boolean genericIdentifierConflicts(FriendlyURLEntity sourceEntity, java.util.List<FriendlyURLEntity> targetEntities)
          Checks whether the source entity is in conflict with one of the target entities.
protected abstract  java.util.List<java.lang.Object> getAvailabilityArguments(FriendlyURLEntity entity)
          Returns the SQL arguments for checking the availability of a friendly URL.
protected abstract  java.lang.String getAvailabilityQuery()
          Returns SQL query that confirms a given friendly URL is unique.
protected static java.lang.String getCreateFields()
          Returns comma separated string of table fields needed to create a generic friendly URL.
protected abstract  java.lang.String getDeleteQuery()
          Returns SQL delete query used for deleting friendly URLs.
abstract  FriendlyURLEntity getEntity(int versionId)
          Returns a friendly URL entity given its version ID.
 FriendlyURLEntity getEntityById(int id)
          Returns a friendly URL entity given its ID.
protected  java.util.List<java.lang.Object> getGenericInsertArguments(FriendlyURLEntity entity)
          Returns the SQL arguments for the insertion of the given friendly URL entity.
protected abstract  java.util.List<java.lang.Object> getInsertArguments(FriendlyURLEntity entity)
          Returns the SQL arguments for the insertion of the given friendly URL entity.
protected abstract  java.lang.String getInsertQuery()
          Returns SQL insert query used for creating friendly URLs.
protected abstract  java.lang.String getMatchQuery()
          Returns SQL query that returns a matching friendly URL.
protected abstract  java.lang.String getMatchQueryNullSequence()
          Returns SQL query that returns a matching friendly URL.
protected  FriendlyURLEntity getReferencedEntity(int referenceId)
          Turns the database value for a entity reference into a friendly URL entity.
protected abstract  java.lang.String getReferringQuery()
          Returns SQL select query used for returning referring friendly URLs.
protected abstract  java.lang.String getSelectByIdQuery()
          Returns SQL select query for retrieving friendly URL by id.
protected static java.lang.String getSelectFields()
          Returns comma separated string of table fields needed to select a generic friendly URL.
protected  SEODatabaseUtil getSEODatabaseUtil()
          Returns reference to the SEO database utility class.
protected  java.lang.Integer getSequenceNumber(int sequenceField)
          Turns the database value for a sequence number into a real sequence number.
 java.lang.String getURLTitle(java.lang.String queryString)
          Returns the URL title of the friendly URL entity backed by the given querystring.
protected  boolean identifierConflicts(java.sql.Connection connection, FriendlyURLEntity entity, java.util.List<FriendlyURLEntity> entities)
          Determines the sequence number the given entity should get in order to make its URL identifier unique.
protected abstract  boolean identifierConflictsWithInMemEntities(FriendlyURLEntity sourceEntity, java.util.List<FriendlyURLEntity> targetEntities)
          Checks whether the source entity is in conflict with one of the target entities.
protected  int insertFriendlyURL(FriendlyURLEntity entity)
          Inserts the friendly URL into the database.
 void lastCurrent(FriendlyURLEntity entity, boolean isCurrent)
          Sets the live bit of the given entity.
 java.lang.Integer makeIdentifierUnique(FriendlyURLEntity entity, java.util.List<FriendlyURLEntity> entities)
          Resolves potential URL identifier conflict by setting a sequence number for the given friendly URL entity.
 void refer(FriendlyURLEntity entity)
          Refers referenced entity to this entity.
 void refer(FriendlyURLEntity sourceEntity, FriendlyURLEntity targetEntity)
          Refers one entity to the other.
protected abstract  java.util.List<FriendlyURLEntity> selectFriendlyURLs(java.lang.String query, java.util.List<java.lang.Object> arguments)
          Selects friendly URL entities.
 void updateIdentifiers(java.util.List<FriendlyURLEntity> entities)
          Updates the URL identifying columns for the given entities.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FriendlyURLEntityDAOImpl

protected FriendlyURLEntityDAOImpl(SEODatabaseUtil seoDatabaseUtil)
Constructor.

Parameters:
seoDatabaseUtil - Reference to the friendly URL database util class.
Method Detail

getEntity

public abstract FriendlyURLEntity getEntity(int versionId)
                                     throws FriendlyURLException
Returns a friendly URL entity given its version ID.

Specified by:
getEntity in interface FriendlyURLEntityDAO
Parameters:
versionId - The version identifier of the page or media item version for which its friendly URL entity is returned.
Returns:
Friendly URL entity object.
Throws:
FriendlyURLException - If any database access fails.

getEntityById

public final FriendlyURLEntity getEntityById(int id)
                                      throws FriendlyURLException
Returns a friendly URL entity given its ID.

Specified by:
getEntityById in interface FriendlyURLEntityDAO
Parameters:
id - The ID of the friendly URL entity.
Returns:
Friendly URL entity object.
Throws:
FriendlyURLException - If any database access fails.

delete

public final void delete(FriendlyURLEntity entity)
                  throws FriendlyURLException
Deletes the given entity and its history. In case of versions makes sure that other entities referring this entity will refer to the next current or planned entity.

Specified by:
delete in interface FriendlyURLEntityDAO
Parameters:
entity - Remove this friendly URL entity from the database.
Throws:
FriendlyURLException - If removing the friendly URL fails.

deleteAll

public final void deleteAll(FriendlyURLEntity entity)
                     throws FriendlyURLException
Deletes the given entity and all other related entities. Technically, related entities are all entities with the same query string as the given entity.

Specified by:
deleteAll in interface FriendlyURLEntityDAO
Parameters:
entity - Remove this friendly URL entity and other entities with the same query string from the database.
Throws:
FriendlyURLException - If removing the friendly URL fails.

deleteById

public final void deleteById(FriendlyURLEntity entity)
                      throws FriendlyURLException
Deletes the given entity using its id.

Specified by:
deleteById in interface FriendlyURLEntityDAO
Parameters:
entity - Remove this friendly URL entity from the database.
Throws:
FriendlyURLException - If any database access fails.

getURLTitle

public final java.lang.String getURLTitle(java.lang.String queryString)
                                   throws FriendlyURLException
Returns the URL title of the friendly URL entity backed by the given querystring. If no friendly URL entity exists for the given querystring, the querystring itself is returned. Used for translating internal URLs to friendly URLs.

Specified by:
getURLTitle in interface FriendlyURLEntityDAO
Parameters:
queryString - Returns the URL title identified by this querystring.
Returns:
The URL title of the friendly URL entity identified by its querystring.
Throws:
FriendlyURLException - If any database access fails.

create

public final void create(FriendlyURLEntity entity)
                  throws FriendlyURLException
Inserts a new record for the given entity. Resolves potential URL clashes by generating a sequence number before inserting. The newly generated id is set on the entity bean.

Specified by:
create in interface FriendlyURLEntityDAO
Parameters:
entity - Write this friendly URL entity to the database.
Throws:
FriendlyURLException - If storing the friendly URL fails.

refer

public final void refer(FriendlyURLEntity entity)
                 throws FriendlyURLException
Refers referenced entity to this entity. References to the reference entity are also updated to refer to this entity. At last, if this entity itself is referring to another entity, clears that reference. After this call this entity is considered the current entity.

Specified by:
refer in interface FriendlyURLEntityDAO
Parameters:
entity - Updates this entity's referential structure.
Throws:
FriendlyURLException - If any database access fails.

refer

public final void refer(FriendlyURLEntity sourceEntity,
                        FriendlyURLEntity targetEntity)
                 throws FriendlyURLException
Refers one entity to the other. If a website visitor requests an URL specifying the source friendly URL entity, the visitor is redirected to an URL including the target friendly URL entity.

Specified by:
refer in interface FriendlyURLEntityDAO
Parameters:
sourceEntity - Source entity that will refer to the target.
targetEntity - Target entity that will be referenced by the source entity.
Throws:
FriendlyURLException - If any database access fails.

activate

public final void activate(FriendlyURLEntity entity)
                    throws FriendlyURLException
Activates the given entity. This means that the friendly URL entity is considered live now. Any subsequent update on this entity actually duplicates the entity. The interpretation is that this entity after it is activated should never be deleted automatically, only manually. Remembering historic URLs enables redirecting requests to these old URLs to their current ones.

Specified by:
activate in interface FriendlyURLEntityDAO
Parameters:
entity - Activate this friendly URL entity.
Throws:
FriendlyURLException - If any database access fails.

lastCurrent

public final void lastCurrent(FriendlyURLEntity entity,
                              boolean isCurrent)
                       throws FriendlyURLException
Sets the live bit of the given entity. If set to true content backed by the entity is considered publicly available. Used to determine a current roll-over by comparing this field with the real current state.

Specified by:
lastCurrent in interface FriendlyURLEntityDAO
Parameters:
entity - Set live bit of this friendly URL entity.
isCurrent - Whether the content backed by this entity is publicly available.
Throws:
FriendlyURLException - If any database access fails.

makeIdentifierUnique

public final java.lang.Integer makeIdentifierUnique(FriendlyURLEntity entity,
                                                    java.util.List<FriendlyURLEntity> entities)
                                             throws FriendlyURLException
Resolves potential URL identifier conflict by setting a sequence number for the given friendly URL entity. Only makes sense for given friendly URL entity which is not persisted yet. If an URL identifier is already used by another friendly URL entity a sequence number is generated, which appended to the URL identifier makes to combination uniquely identify the internal resource backed by the friendly URL entity.

Note that a sequence number is not needed for two friendly URL entities with the same URL identifier if they both point to the same internal resource (that is, the same query string). This is the case for two page versions of the same page, which have the same URL identifier. There is always only one page version which is public within a language context.

Specified by:
makeIdentifierUnique in interface FriendlyURLEntityDAO
Parameters:
entity - Friendly URL entity to find sequence number for.
entities - List of uncommitted friendly URL entities. The friendly URL entity's URL identifier is first matched against the URL identifiers of these friendly URL entities. Cannot be null, but instead pass an empty list.
Returns:
Sequence number to make identifier unique, null if already unique.
Throws:
FriendlyURLException - If any database access fails.

updateIdentifiers

public final void updateIdentifiers(java.util.List<FriendlyURLEntity> entities)
                             throws FriendlyURLException
Updates the URL identifying columns for the given entities. Entities that are activated are duplicated and their references are handled.

Specified by:
updateIdentifiers in interface FriendlyURLEntityDAO
Parameters:
entities - Update these entities.
Throws:
FriendlyURLException - If any database access fails.

getSEODatabaseUtil

protected final SEODatabaseUtil getSEODatabaseUtil()
Returns reference to the SEO database utility class.

Returns:
Reference to the friendly URL database utility class.

selectFriendlyURLs

protected abstract java.util.List<FriendlyURLEntity> selectFriendlyURLs(java.lang.String query,
                                                                        java.util.List<java.lang.Object> arguments)
                                                                 throws java.sql.SQLException
Selects friendly URL entities. The type of entities in the returned list reflects the type of the implementing class.

Parameters:
query - Execute this select query, which must retrieve all friendly URL select fields.
arguments - The arguments for the given query.
Returns:
Array of friendly URL entities.
Throws:
java.sql.SQLException - If a database access error occurs.

identifierConflicts

protected final boolean identifierConflicts(java.sql.Connection connection,
                                            FriendlyURLEntity entity,
                                            java.util.List<FriendlyURLEntity> entities)
                                     throws FriendlyURLException
Determines the sequence number the given entity should get in order to make its URL identifier unique. In this generic case this means unique over all websites. URL identifiers can be the same if involving entities have the same querystring. This method is overridden by the class PageFriendlyURLEntityDAOImpl to allow page specific rules, and the class DBPageFriendlyURLEntityDAOImpl to allow resource instance specific rules.

Parameters:
connection - TODO
entity - Friendly URL entity to find sequence number for.
entities - Entity must also be unique against this in memory list of entities.
Returns:
Sequence number to make identifier unique, null if already unique.
Throws:
FriendlyURLException - If any database access fails.

identifierConflictsWithInMemEntities

protected abstract boolean identifierConflictsWithInMemEntities(FriendlyURLEntity sourceEntity,
                                                                java.util.List<FriendlyURLEntity> targetEntities)
Checks whether the source entity is in conflict with one of the target entities.

Parameters:
sourceEntity - Source friendly URL entity.
targetEntities - Target friendly URL entities.
Returns:
true if URL identifier is not unique, false otherwise.

genericIdentifierConflicts

protected final boolean genericIdentifierConflicts(FriendlyURLEntity sourceEntity,
                                                   java.util.List<FriendlyURLEntity> targetEntities)
Checks whether the source entity is in conflict with one of the target entities. Implements the generic way: URL identifiers are the same, both exist for the same website, both query strings differ.

Parameters:
sourceEntity - Source friendly URL entity.
targetEntities - Source friendly URL entity.
Returns:
true if URL identifier is not unique, false otherwise.

determineSequenceNumber

protected final void determineSequenceNumber(java.sql.Connection connection,
                                             FriendlyURLEntity entity,
                                             java.util.List<FriendlyURLEntity> entities)
                                      throws FriendlyURLException
Determines the sequence number for the given entity for ensuring URL uniqueness. The calculated sequence number is set on the entity.

Parameters:
connection - TODO
entity - Calculate sequence number for this entity.
entities - Entity must also be unique against this in memory list of entities.
Throws:
FriendlyURLException - If any data access fails.

getCreateFields

protected static final java.lang.String getCreateFields()
Returns comma separated string of table fields needed to create a generic friendly URL.

Returns:
Comma separated string of table fields.

getSelectFields

protected static final java.lang.String getSelectFields()
Returns comma separated string of table fields needed to select a generic friendly URL.

Returns:
Comma separated string of table fields.

getSelectByIdQuery

protected abstract java.lang.String getSelectByIdQuery()
Returns SQL select query for retrieving friendly URL by id.

Returns:
SQL select query.

getInsertQuery

protected abstract java.lang.String getInsertQuery()
Returns SQL insert query used for creating friendly URLs.

Returns:
SQL insert query.

getReferringQuery

protected abstract java.lang.String getReferringQuery()
Returns SQL select query used for returning referring friendly URLs.

Returns:
SQL select query.

getDeleteQuery

protected abstract java.lang.String getDeleteQuery()
Returns SQL delete query used for deleting friendly URLs.

Returns:
SQL delete query.

getMatchQuery

protected abstract java.lang.String getMatchQuery()
Returns SQL query that returns a matching friendly URL. Used by findMatchFromHistory(FriendlyURLEntity).

Returns:
SQL query for finding a matching friendly URL.

getMatchQueryNullSequence

protected abstract java.lang.String getMatchQueryNullSequence()
Returns SQL query that returns a matching friendly URL. Used by findMatchFromHistory(FriendlyURLEntity). Difference with getMatchQuery() is that the sequence is checked for being null.

Returns:
SQL query for finding a matching friendly URL.

getAvailabilityArguments

protected abstract java.util.List<java.lang.Object> getAvailabilityArguments(FriendlyURLEntity entity)
Returns the SQL arguments for checking the availability of a friendly URL.

Parameters:
entity - Friendly URL entity to return its arguments for.
Returns:
Array of arguments for the availability query.

getAvailabilityQuery

protected abstract java.lang.String getAvailabilityQuery()
Returns SQL query that confirms a given friendly URL is unique.

Returns:
SQL query for confirming uniqueness.

getGenericInsertArguments

protected final java.util.List<java.lang.Object> getGenericInsertArguments(FriendlyURLEntity entity)
Returns the SQL arguments for the insertion of the given friendly URL entity.

Parameters:
entity - Friendly URL entity to return its arguments for.
Returns:
Array of arguments for the insert query.

getInsertArguments

protected abstract java.util.List<java.lang.Object> getInsertArguments(FriendlyURLEntity entity)
Returns the SQL arguments for the insertion of the given friendly URL entity.

Parameters:
entity - Friendly URL entity to return its arguments for.
Returns:
Array of arguments for the insert query.

insertFriendlyURL

protected final int insertFriendlyURL(FriendlyURLEntity entity)
                               throws FriendlyURLException
Inserts the friendly URL into the database.

Parameters:
entity - The friendly URL to insert.
Returns:
Identifier of the newly inserted friendly URL.
Throws:
FriendlyURLException - If storing the friendly URL fails.

getReferencedEntity

protected final FriendlyURLEntity getReferencedEntity(int referenceId)
Turns the database value for a entity reference into a friendly URL entity.

Parameters:
referenceId - Referenced friendly URL entity ID.
Returns:
Friendly URL entity.

getSequenceNumber

protected final java.lang.Integer getSequenceNumber(int sequenceField)
Turns the database value for a sequence number into a real sequence number.

Parameters:
sequenceField - Sequence value.
Returns:
Sequence number.


Copyright © 2007-2011 GX Software BV. All Rights Reserved.