app/src/main/java/db/juhaku/juhakudb/core/android/EntityConverter.java
/**
     * Converts entity to content values. {@link ContentValues} is used when entity is stored to
     * database. And in the content values is put column name and and value which will be stored.
     *
     * @param object The entity that is being stored to database.
     * @return instance of ContentValues that are used to store entity to database.
     * @throws ConversionException if any exception occurs during conversion.
     *
     * @since 1.0.2
     */
Converts entity to content values.  ContentValues is used when entity is stored to
database. And in the content values is put column name and and value which will be stored.

@param object The entity that is being stored to database.
@return instance of ContentValues that are used to store entity to database.
@throws ConversionException if any exception occurs during conversion.


Converts entity to content values . ContentValues is used when entity is stored to database . And in the content values is put column name and and value which will be stored . @param object The entity that is being stored to database . @return instance of ContentValues that are used to store entity to database . @throws ConversionException if any exception occurs during conversion .
public ContentValues entityToContentValues(Object object) throws ConversionException {
        if (!object.getClass().isAnnotationPresent(Entity.class)) {
            throw new ConversionException(Entity.class.getName() + " annotation is missing, are you sure you provided entity?");
        }
        ContentValues values = new ContentValues();
        for (Field field : object.getClass().getDeclaredFields()) {
            field.setAccessible(true);
            if (hasPrimaryKeyJoin(field)) {
                continue;
            }
            try {
                String columnName;
                /*
                 * If field has foreign key relation to another table and this field has a value add the foreign key
                 * value the the content values.
                 */
                if (field.isAnnotationPresent(ManyToOne.class)
                        || (field.isAnnotationPresent(OneToOne.class) && StringUtils.isBlank(field.getAnnotation(OneToOne.class).mappedBy()))) {
                    columnName = NameResolver.resolveName(field);
                    Object value = getIdFieldValue(object, field);
                    if (value != null) {
                        if (Long.class.isAssignableFrom(value.getClass()) || Long.TYPE.isAssignableFrom(value.getClass())) {
                            values.put(columnName, (Long) value);
                        } else {
                            values.put(columnName, (Integer) value);
                        }
                    }
                    continue;
                } else {
                    columnName = NameResolver.resolveName(field);
                }
                if (Integer.class.isAssignableFrom(field.getType()) || Integer.TYPE.isAssignableFrom(field.getType())) {
                    values.put(columnName, (Integer) field.get(object));
                } else if (Short.class.isAssignableFrom(field.getType()) || Short.TYPE.isAssignableFrom(field.getType())) {
                    values.put(columnName, (Short) field.get(object));
                } else if (Boolean.class.isAssignableFrom(field.getType()) || Boolean.TYPE.isAssignableFrom(field.getType())) {
                    values.put(columnName, (Boolean) field.get(object));
                } else if (Long.class.isAssignableFrom(field.getType()) || Long.TYPE.isAssignableFrom(field.getType())) {
                    values.put(columnName, (Long) field.get(object));
                } else if (Float.class.isAssignableFrom(field.getType()) || Float.TYPE.isAssignableFrom(field.getType())) {
                    values.put(columnName, (Float) field.get(object));
                } else if (Double.class.isAssignableFrom(field.getType()) || Double.TYPE.isAssignableFrom(field.getType())) {
                    values.put(columnName, (Double) field.get(object));
                } else if (Byte.class.isAssignableFrom(field.getType()) || Byte.TYPE.isAssignableFrom(field.getType())) {
                    values.put(columnName, (Byte) field.get(object));
                } else if (byte[].class.isAssignableFrom(field.getType())) {
                    values.put(columnName, (byte[]) field.get(object));
                } else if (String.class.isAssignableFrom(field.getType())) {
                    values.put(columnName, (String) field.get(object));
                } else if (Date.class.isAssignableFrom(field.getType())) {
                    Object value = field.get(object);
                    values.put(columnName, value != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(value) : null);
                } else if (Enum.class.isAssignableFrom(field.getType())) {
                    Object value = field.get(object);
                    values.put(columnName, value != null ? value.toString() : null);
                }
            } catch (RuntimeException e) {
                /*
                 * Catch runtime exceptions so that they are not left behind the scene and re-throw them.
                 */
                throw e;
            } catch (Exception e) {
                throw new ConversionException("Failed to convert entity to content values", e);
            }
        }
        return values;
    }
public ContentValues entityToContentValues ( Object object ) throws ConversionException { if ( ! object . getClass ( ) . isAnnotationPresent ( Entity . class ) ) { throw new ConversionException ( Entity . class . getName ( ) + " annotation is missing, are you sure you provided entity?" ) ; } ContentValues values = new ContentValues ( ) ; for ( Field field : object . getClass ( ) . getDeclaredFields ( ) ) { field . setAccessible ( true ) ; if ( hasPrimaryKeyJoin ( field ) ) { continue ; } try { String columnName ; /*
                 * If field has foreign key relation to another table and this field has a value add the foreign key
                 * value the the content values.
                 */ if ( field . isAnnotationPresent ( ManyToOne . class ) || ( field . isAnnotationPresent ( OneToOne . class ) && StringUtils . isBlank ( field . getAnnotation ( OneToOne . class ) . mappedBy ( ) ) ) ) { columnName = NameResolver . resolveName ( field ) ; Object value = getIdFieldValue ( object , field ) ; if ( value != null ) { if ( Long . class . isAssignableFrom ( value . getClass ( ) ) || Long . TYPE . isAssignableFrom ( value . getClass ( ) ) ) { values . put ( columnName , ( Long ) value ) ; } else { values . put ( columnName , ( Integer ) value ) ; } } continue ; } else { columnName = NameResolver . resolveName ( field ) ; } if ( Integer . class . isAssignableFrom ( field . getType ( ) ) || Integer . TYPE . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( Integer ) field . get ( object ) ) ; } else if ( Short . class . isAssignableFrom ( field . getType ( ) ) || Short . TYPE . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( Short ) field . get ( object ) ) ; } else if ( Boolean . class . isAssignableFrom ( field . getType ( ) ) || Boolean . TYPE . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( Boolean ) field . get ( object ) ) ; } else if ( Long . class . isAssignableFrom ( field . getType ( ) ) || Long . TYPE . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( Long ) field . get ( object ) ) ; } else if ( Float . class . isAssignableFrom ( field . getType ( ) ) || Float . TYPE . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( Float ) field . get ( object ) ) ; } else if ( Double . class . isAssignableFrom ( field . getType ( ) ) || Double . TYPE . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( Double ) field . get ( object ) ) ; } else if ( Byte . class . isAssignableFrom ( field . getType ( ) ) || Byte . TYPE . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( Byte ) field . get ( object ) ) ; } else if ( byte [ ] . class . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( byte [ ] ) field . get ( object ) ) ; } else if ( String . class . isAssignableFrom ( field . getType ( ) ) ) { values . put ( columnName , ( String ) field . get ( object ) ) ; } else if ( Date . class . isAssignableFrom ( field . getType ( ) ) ) { Object value = field . get ( object ) ; values . put ( columnName , value != null ? new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss.SSS" ) . format ( value ) : null ) ; } else if ( Enum . class . isAssignableFrom ( field . getType ( ) ) ) { Object value = field . get ( object ) ; values . put ( columnName , value != null ? value . toString ( ) : null ) ; } } catch ( RuntimeException e ) { /*
                 * Catch runtime exceptions so that they are not left behind the scene and re-throw them.
                 */ throw e ; } catch ( Exception e ) { throw new ConversionException ( "Failed to convert entity to content values" , e ) ; } } return values ; }
Converts entity to content values.
Converts entity to content values .
// Ignore primary key joins as they do not have column in the current object's table. // Id is either long or integer. // Resolve regular column name of the current object.