Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.skife.jdbi.v2.sqlobject;
  
  import  com.fasterxml.classmate.members.ResolvedMethod;
  
 import java.util.List;
 
 abstract class CustomizingStatementHandler implements Handler
 {
     private final List<Bindifier>                    binders                        = new ArrayList<Bindifier>();
     private final List<FactoryAnnotationPair>        typeBasedCustomizerFactories   = new ArrayList<FactoryAnnotationPair>();
     private final List<FactoryAnnotationPair>        methodBasedCustomizerFactories = new ArrayList<FactoryAnnotationPair>();
     private final Class<?> sqlObjectType;
     private final Method method;
 
     CustomizingStatementHandler(Class<?> sqlObjectType, ResolvedMethod method)
     {
         this. = sqlObjectType;
         this. = method.getRawMember();
 
         for (final Annotation annotation : sqlObjectType.getAnnotations()) {
             if (annotation.annotationType().isAnnotationPresent(SqlStatementCustomizingAnnotation.class)) {
                 final SqlStatementCustomizingAnnotation a = annotation.annotationType()
                                                                       .getAnnotation(SqlStatementCustomizingAnnotation.class);
                 final SqlStatementCustomizerFactory f;
                 try {
                     f = a.value().newInstance();
                 }
                 catch (Exception e) {
                     throw new IllegalStateException("unable to create sql statement customizer factory"e);
                 }
                 .add(new FactoryAnnotationPair(fannotation));
             }
         }
 
 
         final Annotation[] method_annotations = method.getRawMember().getAnnotations();
         for (final Annotation method_annotation : method_annotations) {
             final Class<? extends Annotationm_anno_class = method_annotation.annotationType();
             if (m_anno_class.isAnnotationPresent(SqlStatementCustomizingAnnotation.class)) {
                 final SqlStatementCustomizingAnnotation scf =
                     m_anno_class.getAnnotation(SqlStatementCustomizingAnnotation.class);
                 final SqlStatementCustomizerFactory f;
                 try {
                     f = scf.value().newInstance();
                 }
                 catch (Exception e) {
                     throw new IllegalStateException("unable to instantiate statement customizer factory"e);
                 }
                 .add(new FactoryAnnotationPair(fmethod_annotation));
             }
 
         }
 
         final Annotation[][] param_annotations = method.getRawMember().getParameterAnnotations();
         for (int param_idx = 0; param_idx < param_annotations.lengthparam_idx++) {
             final Annotation[] annotations = param_annotations[param_idx];
             for (final Annotation annotation : annotations) {
                 final Class<? extends Annotationanno_class = annotation.annotationType();
 
 
                 if (anno_class.isAnnotationPresent(BindingAnnotation.class)) {
                     // we have a binder
                     BindingAnnotation ba = annotation.annotationType().getAnnotation(BindingAnnotation.class);
                     try {
                         BinderFactory fact = ba.value().newInstance();
                         .add(new Bindifier(annotationparam_idxfact.build(annotation)));
 
                     }
                     catch (Exception e) {
                         throw new IllegalStateException("unable to instantiate cusotmizer"e);
                     }
                 }
 
                 if (anno_class.isAnnotationPresent(SqlStatementCustomizingAnnotation.class)) {
                     SqlStatementCustomizingAnnotation sca = annotation.annotationType()
                                                                       .getAnnotation(SqlStatementCustomizingAnnotation.class);
                     final SqlStatementCustomizerFactory f;
                     try {
                         f = sca.value().newInstance();
                     }
                     catch (Exception e) {
                         throw new IllegalStateException("unable to instantiate sql statement customizer factory"e);
                     }
                     .add(new FactoryAnnotationIndexTriple(fannotationparam_idx));
 
                 }
             }
         }
     }
 
     protected final void populateSqlObjectData(ConcreteStatementContext q)
    {
        q.setSqlObjectMethod();
    }
    protected void applyBinders(SQLStatement<?> qObject[] args)
    {
        for (Bindifier binder : ) {
            binder.bind(qargs);
        }
    }
    protected void applyCustomizers(SQLStatement<?> qObject[] args)
    {
        for (FactoryAnnotationPair pair : ) {
            try {
                pair.factory.createForType(pair.annotation).apply(q);
            }
            catch (SQLException e) {
                throw new UnableToCreateStatementException("unable to apply customizer"eq.getContext());
            }
        }
        for (FactoryAnnotationPair pair : ) {
            try {
                pair.factory.createForMethod(pair.annotation).apply(q);
            }
            catch (SQLException e) {
                throw new UnableToCreateStatementException("unable to apply customizer"eq.getContext());
            }
        }
        if (args != null) {
            for (FactoryAnnotationIndexTriple triple : ) {
                try {
                    triple.factory
                        .createForParameter(triple.annotationargs[triple.index])
                        .apply(q);
                }
                catch (SQLException e) {
                    throw new UnableToCreateStatementException("unable to apply customizer"eq.getContext());
                }
            }
        }
    }
    private static class FactoryAnnotationPair
    {
        private final SqlStatementCustomizerFactory factory;
        private final Annotation                    annotation;
        FactoryAnnotationPair(SqlStatementCustomizerFactory factoryAnnotation annotation)
        {
            this. = factory;
            this. = annotation;
        }
    }
    private static class FactoryAnnotationIndexTriple
    {
        private final SqlStatementCustomizerFactory factory;
        private final Annotation                    annotation;
        private final int                           index;
        FactoryAnnotationIndexTriple(SqlStatementCustomizerFactory factoryAnnotation annotationint index)
        {
            this. = factory;
            this. = annotation;
            this. = index;
        }
    }
New to GrepCode? Check out our FAQ X