Package net.sf.autodao

Examples of net.sf.autodao.Finder


  private boolean offset;
  private int indexed;

  protected ParametersChecker(@NotNull final Method method,
                              @NotNull final Map<Class<?>, QueryArgumentTransformer<?, ?>> transformers) {
    final Finder f = AnnotationUtils.getAnnotation(method, Finder.class);
    if (f == null)
      throw new SpecificationViolationException("Method is neither a finder method nor is implemented in AutoDAO", method);

    final int sum
        = (hasText(f.query()) ? 1 : 0)
        + (hasText(f.queryName()) ? 1 : 0)
        + (hasText(f.sqlQuery()) ? 1 : 0)
        + (hasText(f.sqlQueryName()) ? 1 : 0);
    if (sum < 1)
      throw new SpecificationViolationException("You need to specify at least one of: query, queryName, sqlQuery, sqlQueryName", method);

    if (sum > 1)
      throw new SpecificationViolationException("You can specify only one of: query, queryName, sqlQuery, sqlQueryName", method);
View Full Code Here


   * @return <code>true</code> if method is single-find, <code>false</code> otherwise.
   * @throws SpecificationViolationException
   *
   */
  private static boolean validateReturnType(@NotNull final Method method) {
    final Finder f = AnnotationUtils.findAnnotation(method, Finder.class);
    final boolean singleFind = !Collection.class.isAssignableFrom(method.getReturnType());
    if (!singleFind) {
      final Class<?> returnType = method.getReturnType();
      if (!returnType.isAssignableFrom(f.returnAs())) {
        throw new SpecificationViolationException(
            "@Finder.returnAs value (" + f.returnAs().getName()
                + ") cannot be cast to method return type (" + returnType.getName() + ")", method
        );
      } else if (f.returnAs() != List.class) {
        if (f.returnAs().isInterface()) {
          throw new SpecificationViolationException(
              "@Finder.returnAs value (" + f.returnAs().getName() + ") cannot be an interface", method
          );
        } else {
          try {
            f.returnAs().getConstructor();
          } catch (NoSuchMethodException e) {
            throw new SpecificationViolationException(
                "@Finder.returnAs value (" + f.returnAs().getName() + ") doesn't have no-arg constructor.", method
            );
          }
        }
      }
    }
View Full Code Here

  interface ParameterCallback {
    void visit(final int index, @NotNull final Class<?> type, @NotNull final Annotation[] annotations);
  }

  public static <T> T visitQuery(@NotNull final Method method, @NotNull final QueryVisitor<T> visitor) {
    final Finder finder = AnnotationUtils.findAnnotation(method, Finder.class);
    if (StringUtils.hasText(finder.query())) {
      return visitor.visitQuery(finder.query());
    } else if (StringUtils.hasText(finder.sqlQuery())) {
      return visitor.visitSQLQuery(finder.sqlQuery());
    } else if (StringUtils.hasText(finder.sqlQueryName())) {
      return visitor.visitSQLNamedQuery(finder.sqlQueryName());
    } else {
      Assert.hasText(finder.queryName());
      return visitor.visitNamedQuery(finder.queryName());
    }
  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public Object invoke(@NotNull final MethodInvocation invocation) throws Throwable {
    final Method method = invocation.getMethod();
    final Finder finder = AnnotationUtils.getAnnotation(method, Finder.class);

    if (finder == null)
      return invocation.proceed();

    final Object[] arguments = invocation.getArguments();
View Full Code Here

TOP

Related Classes of net.sf.autodao.Finder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.