Package de.zalando.typemapper.core

Examples of de.zalando.typemapper.core.DatabaseFieldDescriptor


                });
        }

        for (final Field f : fields) {
            final DatabaseFieldDescriptor databaseFieldDescriptor = getDatabaseFieldDescriptor(f);
            if (databaseFieldDescriptor != null) {
                if (!f.isAccessible()) {
                    f.setAccessible(true);
                }

                Object value;
                try {
                    value = getOptionalValue(f.get(obj));
                } catch (final IllegalArgumentException e) {
                    throw new IllegalArgumentException("Could not read value of field " + f.getName(), e);
                } catch (final IllegalAccessException e) {
                    throw new IllegalArgumentException("Could not read value of field " + f.getName(), e);
                }

                if (value != null) {

                    // here we need apply any value/type transformation before generating the
                    value = applyTransformer(f, databaseFieldDescriptor, value);
                }

                final int fieldPosition = databaseFieldDescriptor.getPosition();
                if (fieldPosition > 0) {
                    if (resultPositionMap == null) {
                        resultPositionMap = new TreeMap<Integer, Object>();
                    }

                    resultPositionMap.put(fieldPosition, value);

                } else {
                    DbTypeField dbField = null;
                    if (dbFields != null) {

                        // we have type information from database (field positions)
                        final String dbFieldName = Mapping.getDatabaseFieldName(f, databaseFieldDescriptor.getName());
                        dbField = dbFields.get(dbFieldName);

                        if (dbField == null) {
                            throw new IllegalArgumentException("Field " + f.getName() + " (" + dbFieldName
                                    + ") of class " + clazz.getSimpleName() + " could not be found in database type "
View Full Code Here


     *
     * @return  a {@link de.zalando.typemapper.core.DatabaseFieldDescriptor} based on a found {@link DatabaseField} or
     *          {@link javax.persistence.Column}
     */
    public static DatabaseFieldDescriptor getDatabaseFieldDescriptor(final Field field) {
        DatabaseFieldDescriptor databaseFieldDescriptor = fieldToDataBaseFieldDescriptorMap.get(field);
        if (databaseFieldDescriptor == null) {

            DatabaseField databaseField = field.getAnnotation(DatabaseField.class);
            if (databaseField != null) {
                databaseFieldDescriptor = new DatabaseFieldDescriptor(databaseField);
            } else {

                // do we have a column definition?
                final Column column = field.getAnnotation(Column.class);
                if (column != null) {
                    databaseFieldDescriptor = new DatabaseFieldDescriptor(column);
                }
            }

            fieldToDataBaseFieldDescriptorMap.put(field, databaseFieldDescriptor);
        }
View Full Code Here

TOP

Related Classes of de.zalando.typemapper.core.DatabaseFieldDescriptor

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.