Package org.sql2o.reflection

Examples of org.sql2o.reflection.Getter


            if(!method.getName().startsWith("get_")) continue;

            Field field = pojo.getClass()
                    .getDeclaredField(method.getName().substring(3));

            Getter getter = mgf.newGetter(method);
            assertSame(field.getType(),getter.getType());

            Object val1 = field.get(pojo);
            assertEquals(val1, getter.getProperty(pojo));
        }
    }
View Full Code Here


        pojo._obj = pojo;

        Field[] fields = pojo.getClass().getDeclaredFields();

        for (Field field : fields) {
            Getter getter = fgf.newGetter(field);
            assertSame(field.getType(),getter.getType());

            Object val1 = field.get(pojo);
            assertEquals(val1, getter.getProperty(pojo));
        }
    }
View Full Code Here

            final String propertyPath,
            final PojoMetadata metadata) {
        int index = propertyPath.indexOf('.');
        if (index <= 0) {
            // Simple path - fast way
            final Getter getter = metadata.getPropertyGetterIfExists(propertyPath);
            // behavior change: do not throw if POJO contains less properties
            if (getter == null) return null;
            final Converter converter = quirks.converterOf(getter.getType());
            // getter without converter
            if (converter == null) return getter;
            return new Getter() {
                public Object getProperty(Object obj) {
                    try {
                        return converter.convert(getter.getProperty(obj));
                    } catch (ConverterException e) {
                        throw new Sql2oException("Error trying to convert column " + propertyPath + " to type " + getter.getType(), e);
                    }
                }

                public Class getType() {
                    return getter.getType();
                }
            };
        }
        // dot path - long way
        // i'm too lazy now to rewrite this case so I just call old unoptimized code...
        // TODO: rewrite, get rid of POJO class
        return new Getter() {
            public Object getProperty(Object obj) {
                Pojo pojo = new Pojo(metadata, metadata.isCaseSensitive(), obj);
                return pojo.getProperty(propertyPath, quirks);
            }
View Full Code Here

TOP

Related Classes of org.sql2o.reflection.Getter

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.