Package org.sql2o

Examples of org.sql2o.Sql2oException


            if (subValue == null){
                try {
                    subValue = getter.getType().newInstance();
                } catch (InstantiationException e) {
                    throw new Sql2oException("Could not instantiate a new instance of class "+ getter.getType().toString(), e);
                } catch (IllegalAccessException e) {
                    throw new Sql2oException("Could not instantiate a new instance of class "+ getter.getType().toString(), e);
                }

                return getter.getProperty(this.object);
            }

            PojoMetadata subMetadata = new PojoMetadata(getter.getType(), this.caseSensitive, this.metadata.isAutoDeriveColumnNames(), this.metadata.getColumnMappings());
            Pojo subPojo = new Pojo(subMetadata, this.caseSensitive, subValue);

            return subPojo.getProperty(newPath, quirks);
        }
        else{
            getter = metadata.getPropertyGetter(propertyPath);

            Converter converter;

            try {
                converter = throwIfNull(getter.getType(), quirks.converterOf(getter.getType()));
            } catch (ConverterException e) {
                throw new Sql2oException("Cannot convert column " + propertyPath + " to type " + getter.getType(), e);
            }

            try {
                return converter.convert(getter.getProperty(this.object));
            } catch (ConverterException e) {
                throw new Sql2oException("Error trying to convert column " + propertyPath + " to type " + getter.getType(), e);
            }
        }
    }
View Full Code Here


            Object subValue = this.metadata.getValueOfProperty(substring, this.object);
            if (subValue == null){
                try {
                    subValue = setter.getType().newInstance();
                } catch (InstantiationException e) {
                    throw new Sql2oException("Could not instantiate a new instance of class "+ setter.getType().toString(), e);
                } catch (IllegalAccessException e) {
                    throw new Sql2oException("Could not instantiate a new instance of class "+ setter.getType().toString(), e);
                }
                setter.setProperty(this.object, subValue);
            }
           
            PojoMetadata subMetadata = new PojoMetadata(setter.getType(), this.caseSensitive, this.metadata.isAutoDeriveColumnNames(), this.metadata.getColumnMappings());
            Pojo subPojo = new Pojo(subMetadata, this.caseSensitive, subValue);
            subPojo.setProperty(newPath, value, quirks);
        }
        else{
            setter = metadata.getPropertySetter(propertyPath);
            Converter converter;
            try {
                converter = throwIfNull(setter.getType(), quirks.converterOf(setter.getType()));
            } catch (ConverterException e) {
                throw new Sql2oException("Cannot convert column " + propertyPath + " to type " + setter.getType(), e);
            }

            try {
                setter.setProperty(this.object, converter.convert( value ));
            } catch (ConverterException e) {
                throw new Sql2oException("Error trying to convert column " + propertyPath + " to type " + setter.getType(), e);
            }
        }
       
       
    }
View Full Code Here

    public Object getProperty(Object obj) {
        try {
            return this.method.invoke(obj);
        } catch (IllegalAccessException e) {
            throw new Sql2oException("error while calling getter method with name " + method.getName() + " on class " + obj.getClass().toString(), e);
        } catch (InvocationTargetException e) {
            throw new Sql2oException("error while calling getter method with name " + method.getName() + " on class " + obj.getClass().toString(), e);
        }
    }
View Full Code Here

        return new ObjectConstructor() {
            public Object newInstance() {
                try {
                    return theUnsafe.allocateInstance(clazz);
                } catch (InstantiationException e) {
                    throw new Sql2oException("Could not create a new instance of class " + clazz, e);
                }
            }
        };
    }
View Full Code Here

        return new Getter() {
            public Object getProperty(Object obj) {
                try {
                    return methodAccessor.invoke(obj, null);
                } catch (InvocationTargetException e) {
                    throw new Sql2oException("error while calling getter method with name " + method.getName() + " on class " + obj.getClass().toString(), e);
                }
            }

            public Class getType() {
                return type;
View Full Code Here

            public void setProperty(Object obj, Object value) {
                if (value == null && type.isPrimitive()) return;
                try {
                    methodAccessor.invoke(obj, new Object[]{value});
                } catch (InvocationTargetException e) {
                    throw new Sql2oException("error while calling setter method with name " + method.getName() + " on class " + obj.getClass().toString(), e);
                }
            }

            public Class getType() {
                return type;
View Full Code Here

                    @Override
                    public Object newInstance() {
                        try {
                            return constructorAccessor.newInstance(null);
                        } catch (InstantiationException | InvocationTargetException e) {
                            throw new Sql2oException("Could not create a new instance of class " + cls, e);
                        }
                    }
                };
            } catch (NoSuchMethodException e) {
                // ignore
View Full Code Here

        }

        try {
            this.field.set(obj, value);
        } catch (IllegalAccessException e) {
            throw new Sql2oException("could not set field " + this.field.getName() + " on class " + obj.getClass().toString(), e);
        }
    }
View Full Code Here

TOP

Related Classes of org.sql2o.Sql2oException

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.