Class AnnotationIdMethod

java.lang.Object
net.sf.basedb.plugins.batchimport.AnnotationIdMethod
All Implemented Interfaces:
IdMethod

public class AnnotationIdMethod
extends Object
implements IdMethod
Identification method implementation that can use an annotation for identifying items.
Since:
3.15
Author:
nicklas
  • Field Details

  • Constructor Details

    • AnnotationIdMethod

      public AnnotationIdMethod​(AnnotationType annotationType)
      Create a new id method.
  • Method Details

    • getIdMethods

      public static List<IdMethod> getIdMethods​(DbControl dc, Item itemType)
      Get identification methods that are based on annotations. It will make a query for all annotation types that are suitable as identifiers: The value type must be one of STRING, INT or LONG It must not be an enumeration The 'identifier' flag must be set
      Parameters:
      itemType - Either a specified item or null to return all possible annotation id methods
    • getMethod

      public String getMethod()
      Description copied from interface: IdMethod
      The name of this method, which should be unique among the methods that can be used at a given time.
      Specified by:
      getMethod in interface IdMethod
      Returns:
      The method name
    • getTitle

      public String getTitle()
      Description copied from interface: IdMethod
      The display title of the method.
      Specified by:
      getTitle in interface IdMethod
    • getColumnMappingParameterName

      public String getColumnMappingParameterName()
      Specified by:
      getColumnMappingParameterName in interface IdMethod
    • isTrulyUnique

      public boolean isTrulyUnique()
      Description copied from interface: IdMethod
      If the identification method is truly unique or not. If this method returns true, the IdMethod.find(DbControl, ItemQuery, String) method will never ever return a list with more than one item.
      Specified by:
      isTrulyUnique in interface IdMethod
    • prepareQuery

      public <I extends BasicItem> ItemQuery<I> prepareQuery​(DbControl dc, ItemQuery<I> query)
      Adds a restriction to the query: property = :identifier
      Specified by:
      prepareQuery in interface IdMethod
      query - The query to prepare
      Returns:
      The query that is used for item lookup
    • find

      public <I extends BasicItem> List<I> find​(DbControl dc, ItemQuery<I> query, String identifier)
      Find all items with property = identifier.
      Specified by:
      find in interface IdMethod
      query - The query to use, which should have been prepared using IdMethod.prepareQuery(DbControl, ItemQuery)
      identifier - The identifier of the item
      Returns:
      A list with the found items, if IdMethod.isTrulyUnique() return true the list is guaranteed to have at most one item
    • setIdentifierOnNewItem

      public <I extends BasicItem> boolean setIdentifierOnNewItem​(DbControl dc, I item, String identifier)
      Set the annotation on a newly created item.
      Specified by:
      setIdentifierOnNewItem in interface IdMethod
      Returns:
      TRUE if the identifier was set, FALSE if not
    • toString

      public String toString()
      Overrides:
      toString in class Object