QueryParameter.java :  » Google-tech » jrest4guice » org » jrest4guice » dao » jpa » Java Open Source

Java Open Source » Google tech » jrest4guice 
jrest4guice » org » jrest4guice » dao » jpa » QueryParameter.java
package org.jrest4guice.dao.jpa;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;

import org.jrest4guice.dao.annotations.Find.FirstResult;
import org.jrest4guice.dao.annotations.Find.MaxResults;

import com.google.inject.name.Named;

/**
 * 
 * @author <a href="mailto:gzyangfan@gmail.com">gzYangfan</a>
 */
public class QueryParameter {
  
  private Integer firstResult;
  private Integer maxResults;
  private Map<String, Object> namedParameters = new HashMap<String, Object>();
  private Map<Integer, Object> positionParameters = new HashMap<Integer, Object>();
  
  public QueryParameter(Object[] parameters, Annotation[][] annotations) {
    if (parameters == null)
      return;
    label1: for (int index = 0; index < parameters.length; index++) {
      final Object para = parameters[index];
      if (annotations == null) {
        // if (this.annotations == null) {
        getPositionParameters().put(index + 1, para);
        continue;
      }
      for (final Annotation annotation : annotations[index]) {
        final Class<? extends Annotation> clazz = annotation.annotationType();
        if (clazz.equals(Named.class)) {
          final Named named = (Named) annotation;
          getNamedParameters().put(named.value(), para);
          continue label1;
        } else if (clazz.equals(FirstResult.class)) {
          firstResult = (Integer) para;
          continue label1;
        } else if (clazz.equals(MaxResults.class)) {
          maxResults = (Integer) para;
          continue label1;
        }
      }
      getPositionParameters().put(index + 1, para);
    }
  }
  
  public Integer getFirstResult() {
    return firstResult;
  }
  
  public void setFirstResult(Integer firstResult) {
    this.firstResult = firstResult;
  }
  
  public Integer getMaxResults() {
    return maxResults;
  }
  
  public void setMaxResults(Integer maxResults) {
    this.maxResults = maxResults;
  }
  
  public Map<String, Object> getNamedParameters() {
    return namedParameters;
  }
  
  public void setNamedParameters(Map<String, Object> namedParameters) {
    this.namedParameters = namedParameters;
  }
  
  public boolean hasNamedParameters() {
    if (namedParameters.size() > 0)
      return true;
    return false;
  }
  
  public void setPositionParameters(Map<Integer, Object> positionParameters) {
    this.positionParameters = positionParameters;
  }
  
  public Map<Integer, Object> getPositionParameters() {
    return positionParameters;
  }
  
  public boolean hasPositionParameters() {
    if (positionParameters.size() > 0)
      return true;
    return false;
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.