org.opennms.netmgt.dao.support
Class CreateIfNecessaryTemplate<T,D extends OnmsDao<T,?>>

java.lang.Object
  extended by org.opennms.netmgt.dao.support.UpsertTemplate<T,D>
      extended by org.opennms.netmgt.dao.support.CreateIfNecessaryTemplate<T,D>

public abstract class CreateIfNecessaryTemplate<T,D extends OnmsDao<T,?>>
extends UpsertTemplate<T,D>

Template for creating a row if and only if one doesn't already exists. This suffers from some of the same concurrency issues as described in the UpsertTemplate. See the detailed javadoc there for a description.

Author:
brozow

Field Summary
 
Fields inherited from class org.opennms.netmgt.dao.support.UpsertTemplate
m_dao, m_transactionManager
 
Constructor Summary
CreateIfNecessaryTemplate(org.springframework.transaction.PlatformTransactionManager transactionManager, D dao)
          Create a CreateIfNecessaryTemplate using the given transactionManager to create transactions.
 
Method Summary
protected abstract  T doInsert()
          Override this method to insert a new object into the database.
protected  T doUpdate(T dbObj)
          There is no need to update the object for this case as we just return the object found.
protected abstract  T query()
          Override this method to execute the query that is used to determine if there is an existing object in the database
 
Methods inherited from class org.opennms.netmgt.dao.support.UpsertTemplate
execute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CreateIfNecessaryTemplate

public CreateIfNecessaryTemplate(org.springframework.transaction.PlatformTransactionManager transactionManager,
                                 D dao)
Create a CreateIfNecessaryTemplate using the given transactionManager to create transactions.

Method Detail

query

protected abstract T query()
Description copied from class: UpsertTemplate
Override this method to execute the query that is used to determine if there is an existing object in the database

Specified by:
query in class UpsertTemplate<T,D extends OnmsDao<T,?>>

doUpdate

protected T doUpdate(T dbObj)
There is no need to update the object for this case as we just return the object found.

Specified by:
doUpdate in class UpsertTemplate<T,D extends OnmsDao<T,?>>

doInsert

protected abstract T doInsert()
Description copied from class: UpsertTemplate
Override this method to insert a new object into the database. This method will be called when the query method returns null. A DataIntegrityViolationException should be thrown if the insert has already occurred. (This is the normal exception thrown when to objects with the same id are inserted).

Specified by:
doInsert in class UpsertTemplate<T,D extends OnmsDao<T,?>>


Copyright © 2011. All Rights Reserved.