Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.skife.jdbi.v2.sqlobject.customizers;
  
  
Use this to override the statement locator on a sql object, May be specified on either the interface or method level.
 
 public @interface OverrideStatementLocatorWith
 {
    
Specify the statement locator class to use
 
     Class<? extends org.skife.jdbi.v2.tweak.StatementLocatorvalue();
 
     static class Factory implements SqlStatementCustomizerFactory
     {
 
         public SqlStatementCustomizer createForMethod(Annotation annotationClass sqlObjectTypeMethod method)
         {
             OverrideStatementLocatorWith sl = (OverrideStatementLocatorWithannotation;
             final org.skife.jdbi.v2.tweak.StatementLocator f;
             try {
                 f = instantiate(sl.value(), sqlObjectTypemethod);
             }
             catch (Exception e) {
                 throw new IllegalStateException("unable to instantiate a statement locator"e);
             }
             return new SqlStatementCustomizer()
             {
                 public void apply(SQLStatement q)
                 {
                     q.setStatementLocator(f);
                 }
             };
         }
 
         public SqlStatementCustomizer createForType(Annotation annotationClass sqlObjectType)
         {
             OverrideStatementLocatorWith sl = (OverrideStatementLocatorWithannotation;
             final StatementLocator f;
             try {
                 f = instantiate(sl.value(), sqlObjectTypenull);
             }
             catch (Exception e) {
                 throw new IllegalStateException("unable to instantiate a statement locator"e);
             }
             return new SqlStatementCustomizer()
             {
                 public void apply(SQLStatement q)
                 {
                     q.setStatementLocator(f);
                 }
             };
         }
 
 
         private StatementLocator instantiate(Class<? extends StatementLocatorvalue,
                                              Class sqlObjectType,
                                              Method mthrows Exception
         {
             try {
                 Constructor<? extends StatementLocatorno_arg = value.getConstructor();
                 return no_arg.newInstance();
             }
             catch (NoSuchMethodException e) {
                 try {
                     Constructor<? extends StatementLocatorclass_arg = value.getConstructor(Class.class);
                     return class_arg.newInstance(sqlObjectType);
                 }
                 catch (NoSuchMethodException e1) {
                     if (m != null) {
                         Constructor<? extends StatementLocatorc_m_arg = value.getConstructor(Class.class,
                                                                                                Method.class);
                         return c_m_arg.newInstance(sqlObjectTypem);
                     }
                     throw new IllegalStateException("Unable to instantiate, no viable constructor " + value.getName());
                 }
             }
 
         }
 
         public SqlStatementCustomizer createForParameter(Annotation annotationClass sqlObjectTypeMethod methodObject arg)
         {
            throw new UnsupportedOperationException("Not applicable to parameter");
        }
    }
New to GrepCode? Check out our FAQ X