Class CreateIfNecessaryTemplate<T,​D extends OnmsDao<T,​?>>


  • 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
    • Constructor Summary

      Constructors 
      Constructor Description
      CreateIfNecessaryTemplate​(org.springframework.transaction.PlatformTransactionManager transactionManager, D dao)
      Create a CreateIfNecessaryTemplate using the given transactionManager to create transactions.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      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 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,​?>>