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 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,​?>>