Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.skife.jdbi.v2.sqlobject.customizers;
 
 
Used to register a result set mapper with either a sql object type or for a specific method.
public @interface RegisterMapper
{
    
The result set mapper class to register
    Class<? extends ResultSetMapper<?>>[] value();
    static class Factory implements SqlStatementCustomizerFactory
    {
        public SqlStatementCustomizer createForMethod(Annotation annotationClass sqlObjectTypeMethod method)
        {
            final RegisterMapper ma = (RegisterMapperannotation;
            final ResultSetMapper[] m = new ResultSetMapper[ma.value().length];
            try {
                Class<? extends ResultSetMapper<?>>[] mcs = ma.value();
                for (int i = 0; i < mcs.lengthi++) {
                    m[i] = mcs[i].newInstance();
                }
            }
            catch (Exception e) {
                throw new IllegalStateException("unable to create a specified result set mapper"e);
            }
            return new SqlStatementCustomizer()
            {
                public void apply(SQLStatement statement)
                {
                    if (statement instanceof Query) {
                        Query q = (Querystatement;
                        for (ResultSetMapper mapper : m) {
                            q.registerMapper(mapper);
                        }
                    }
                }
            };
        }
        public SqlStatementCustomizer createForType(Annotation annotationClass sqlObjectType)
        {
            final RegisterMapper ma = (RegisterMapperannotation;
            final ResultSetMapper[] m = new ResultSetMapper[ma.value().length];
            try {
                Class<? extends ResultSetMapper<?>>[] mcs = ma.value();
                for (int i = 0; i < mcs.lengthi++) {
                    m[i] = mcs[i].newInstance();
                }
            }
            catch (Exception e) {
                throw new IllegalStateException("unable to create a specified result set mapper"e);
            }
            return new SqlStatementCustomizer()
            {
                public void apply(SQLStatement statement)
                {
                    if (statement instanceof Query) {
                        Query q = (Querystatement;
                        for (ResultSetMapper mapper : m) {
                            q.registerMapper(mapper);
                        }
                    }
                }
            };
        }
        public SqlStatementCustomizer createForParameter(Annotation annotationClass sqlObjectTypeMethod methodObject arg)
        {
            throw new UnsupportedOperationException("Not defined for parameter");
        }
    }
New to GrepCode? Check out our FAQ X