All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mybatis.jpa.definition.AnnotationDefinitionRegistry Maven / Gradle / Ivy

There is a newer version: 2.5.1
Show newest version
package com.mybatis.jpa.definition;

import com.mybatis.jpa.annotation.InsertDefinition;
import com.mybatis.jpa.annotation.UpdateDefinition;
import com.mybatis.jpa.definition.adaptor.AnnotationAdaptable;
import com.mybatis.jpa.definition.adaptor.InsertDefinitionAdaptor;
import com.mybatis.jpa.definition.adaptor.UpdateDefinitionAdaptor;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author svili
 **/
public class AnnotationDefinitionRegistry {

  private final Map, AnnotationAdaptable> ANNOTATION_ADAPTORS = new HashMap<>();

  public AnnotationDefinitionRegistry() {
    registerAdaptor(InsertDefinition.class, new InsertDefinitionAdaptor());
    registerAdaptor(UpdateDefinition.class, new UpdateDefinitionAdaptor());
  }

  public AnnotationAdaptable resolveAdaptor(Class annotationType) {
    if (annotationType == null) {
      return null;
    }
    return ANNOTATION_ADAPTORS.get(annotationType);
  }

  public void registerAdaptor(Class annotationType,
      AnnotationAdaptable adaptor) {
    if (annotationType == null) {
      throw new RuntimeException("The parameter annotationType cannot be null");
    }
    if (adaptor == null) {
      throw new RuntimeException("The parameter register cannot be null");
    }
    ANNOTATION_ADAPTORS.put(annotationType, adaptor);
  }

  public Map, AnnotationAdaptable> getAnnotationAdaptors() {
    return Collections.unmodifiableMap(ANNOTATION_ADAPTORS);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy