Example usage for java.lang.reflect Modifier isTransient

List of usage examples for java.lang.reflect Modifier isTransient

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isTransient.

Prototype

public static boolean isTransient(int mod) 

Source Link

Document

Return true if the integer argument includes the transient modifier, false otherwise.

Usage

From source file:org.vulpe.model.dao.impl.jpa.AbstractVulpeBaseDAOJPA.java

private VulpeHashMap<String, Object> getUpdateSomeAttributesMap(final ENTITY entity) {
    final List<Field> fields = VulpeReflectUtil.getFields(entity.getClass());
    final VulpeHashMap<String, Object> map = new VulpeHashMap<String, Object>();
    for (final Field field : fields) {
        if (field.getName().equals("id") || Modifier.isTransient(field.getModifiers())) {
            continue;
        }//  w  w  w. j  av a2 s .com
        final Object value = VulpeReflectUtil.getFieldValue(entity, field.getName());
        if (VulpeValidationUtil.isNotEmpty(value)) {
            String columnName = field.getName();
            if (entity.fieldColumnMap().containsKey(field.getName())) {
                columnName = entity.fieldColumnMap().get(field.getName());
            } else {
                final Column column = field.getAnnotation(Column.class);
                final JoinColumn joinColumn = field.getAnnotation(JoinColumn.class);
                if (column != null) {
                    columnName = column.name();
                } else if (joinColumn != null) {
                    columnName = (StringUtils.isNotBlank(joinColumn.referencedColumnName())
                            ? joinColumn.referencedColumnName()
                            : joinColumn.name());
                }
            }
            map.put(columnName, value);
        }
    }
    return map;
}

From source file:org.dasein.persist.PersistentCache.java

protected String toDataStoreJSONFromCurrentState(Map<String, Object> state) {
    HashMap<String, Object> friendlyState = new HashMap<String, Object>();
    Class<? extends Object> t = getTarget();

    while (!t.equals(Object.class)) {
        for (Field field : t.getDeclaredFields()) {
            int modifiers = field.getModifiers();

            if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) {
                continue;
            }/*  w w  w .  ja v  a2 s . co m*/
            Object value = state.get(field.getName());

            if (value != null) {
                friendlyState.put(field.getName(), toJSONValue(value));
            }
        }
        t = t.getSuperclass();
    }
    friendlyState.put("SCHEMA_VERSION", getSchemaVersion());
    return new JSONObject(friendlyState).toString();
}

From source file:org.dasein.persist.PersistentCache.java

private @Nonnull JSONObject autoJSON(@Nonnull Object ob) {
    HashMap<String, Object> json = new HashMap<String, Object>();
    Class<?> cls = ob.getClass();

    while (!(cls.getName().equals(Object.class.getName()))) {
        Field[] fields = cls.getDeclaredFields();

        for (Field field : fields) {
            int modifiers = field.getModifiers();

            if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) {
                continue;
            }//from w  w w  .  j av a2 s  .  c  o  m
            field.setAccessible(true);
            try {
                Object value = field.get(ob);

                value = toJSONValue(value);
                json.put(field.getName(), value);
            } catch (IllegalAccessException e) {
                // this should not happen, don't map
                logger.warn("Illegal access exception mapping " + cls.getName() + "." + field.getName() + ": "
                        + e.getMessage(), e);
            }
        }
        cls = cls.getSuperclass();
    }
    return new JSONObject(json);
}

From source file:org.dasein.persist.PersistentCache.java

private @Nonnull <T> T autoDeJSON(@Nonnull Class<T> targetClass, @Nonnull JSONObject ob)
        throws PersistenceException {
    Class<?> cls = targetClass;

    T item;//from  w w w .  j a  v  a  2  s  . c o m

    try {
        item = targetClass.newInstance();
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
    while (!(cls.getName().equals(Object.class.getName()))) {
        Field[] fields = cls.getDeclaredFields();

        for (Field field : fields) {
            int modifiers = field.getModifiers();

            if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) {
                continue;
            }
            field.setAccessible(true);
            Object value = null;

            if (ob.has(field.getName())) {
                try {
                    value = mapValue(field.getName(), ob.get(field.getName()), field.getType(), null);
                } catch (JSONException e) {
                    logger.warn("JSON error mapping " + targetClass.getName() + "." + field.getName() + ": "
                            + e.getMessage(), e);
                }
            }
            if (value != null || !field.getType().isPrimitive()) {
                try {
                    field.set(item, value);
                } catch (IllegalAccessException e) {
                    logger.warn("Could not set " + targetClass.getName() + "." + field.getName() + ": "
                            + e.getMessage(), e);
                }
            }
        }
        cls = cls.getSuperclass();
    }
    return item;
}

From source file:org.dasein.persist.riak.RiakCache.java

@Override
public String getSchema() throws PersistenceException {
    if (std.isTraceEnabled()) {
        std.trace("ENTER: " + RiakCache.class.getName() + ".getSchema()");
    }/*from   w ww .jav  a 2s . c o m*/
    try {
        StringBuilder url = new StringBuilder();
        StringBuilder indexes = new StringBuilder();

        String key = getPrimaryKeyField();

        url.append(getEndpoint());
        url.append("buckets/");
        url.append(getBucket());
        url.append("/keys/");
        url.append("$").append(getPrimaryKeyField());

        HashMap<String, Class<?>> fields = new HashMap<String, Class<?>>();
        Class<?> cls = getTarget();

        while (!cls.getName().equals(Object.class.getName())) {
            for (Field field : cls.getDeclaredFields()) {
                int modifiers = field.getModifiers();

                if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) {
                    continue;
                }
                Class<?> t = field.getType();

                fields.put(field.getName(), t);
            }
            cls = cls.getSuperclass();
        }
        for (Key secondaryKey : getSecondaryKeys()) {
            if (secondaryKey.getFields().length > 1) {
                int len = secondaryKey.getFields().length;

                StringBuilder n = new StringBuilder();

                for (int i = 0; i < len; i++) {
                    n.append(secondaryKey.getFields()[i].toLowerCase());
                    if (i < len - 1) {
                        n.append("-");
                    }
                }
                indexes.append(n.toString()).append("_bin: ");
                for (String field : secondaryKey.getFields()) {
                    indexes.append(field).append(",");
                }
                indexes.append("\n");
            } else {
                Class<?> c = fields.get(secondaryKey.getFields()[0]);

                if (c != null && ((c.isPrimitive()
                        && (c.equals(long.class) || c.equals(int.class) || c.equals(short.class)))
                        || (c.equals(Long.class) || c.equals(Integer.class) || c.equals(Short.class)))) {
                    indexes.append(secondaryKey.getFields()[0].toLowerCase()).append("_int: ")
                            .append(secondaryKey.getFields()[0]).append("\n");
                } else {
                    indexes.append(secondaryKey.getFields()[0].toLowerCase()).append("_bin: ")
                            .append(secondaryKey.getFields()[0]).append("\n");
                }
            }
        }

        HashMap<String, Object> schema = new HashMap<String, Object>();

        for (Map.Entry<String, Class<?>> entry : fields.entrySet()) {
            if (entry.getValue().isPrimitive()) {
                schema.put(entry.getKey(), entry.getValue().getName());
            } else {
                schema.put(entry.getKey(), entry.getValue().getSimpleName());
            }
            /*
            else if( Number.class.isAssignableFrom(entry.getValue()) ) {
            schema.put(entry.getKey(), entry.getValue().getSimpleName());
            }
            else if( entry.getValue().equals(String.class) || entry.getValue().equals(Boolean.class) || Enum.class.isAssignableFrom(entry.getValue()) ) {
            schema.put(entry.getKey(), entry.getValue().getSimpleName());
            }
            else if( Locale.class.isAssignableFrom(entry.getValue()) || Currency.class.isAssignableFrom(entry.getValue()) ) {
            schema.put(entry.getKey(), entry.getValue().getSimpleName());
            }
            */
        }
        try {
            return (url.toString() + "\nSchema: " + getSchemaVersion() + "\n\n" + indexes.toString() + "\n"
                    + ((new JSONObject(schema))).toString(4));
        } catch (JSONException e) {
            throw new PersistenceException(e);
        }
    } finally {
        if (std.isTraceEnabled()) {
            std.trace("EXIT: " + RiakCache.class.getName() + ".getSchema()");
        }
    }
}

From source file:org.dasein.persist.PersistentCache.java

protected Map<String, Object> toMapFromJSON(String json) throws PersistenceException {
    try {/*from   w w  w . j a  v  a 2s. c  o  m*/
        HashMap<String, Object> values = new HashMap<String, Object>();
        JSONObject j = new JSONObject(json);
        Class<T> targetClass = getTarget();
        Class<? extends Object> t = targetClass;

        while (!t.getName().equals(Object.class.getName())) {
            for (Field field : t.getDeclaredFields()) {
                int modifiers = field.getModifiers();

                if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) {
                    String fieldName = field.getName();

                    set(values, fieldName, j.has(fieldName) ? j.get(fieldName) : null, field.getType());
                }
            }
            t = t.getSuperclass();
        }
        return values;
    } catch (JSONException e) {
        throw new PersistenceException(e);
    } catch (RuntimeException e) {
        logger.error(e.getMessage(), e);
        throw new PersistenceException(e);
    } catch (Error e) {
        logger.error(e.getMessage(), e);
        throw new PersistenceException(e.getMessage());
    }
}

From source file:org.dasein.persist.PersistentCache.java

protected @Nonnull T toTargetFromJSON(@Nonnull String sourceVersion, @Nonnull JSONObject j)
        throws PersistenceException {
    try {//from  w w  w. j a  v a2  s .c  om
        while (!sourceVersion.equals(schemaVersion)) {
            SchemaMapper mapper = getSchemaMapper(sourceVersion);

            if (mapper == null) {
                break;
            }
            j = mapper.map(sourceVersion, j);
            sourceVersion = mapper.getTargetVersion();
        }
        Class<T> targetClass = getTarget();
        Class<? extends Object> t = targetClass;
        T item = targetClass.newInstance();

        while (!t.getName().equals(Object.class.getName())) {
            for (Field field : t.getDeclaredFields()) {
                int modifiers = field.getModifiers();

                if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) {
                    Object value = (j.has(field.getName()) ? j.get(field.getName()) : null);

                    set(item, field, value);
                }
            }
            t = t.getSuperclass();
        }
        return item;
    } catch (JSONException e) {
        throw new PersistenceException(e);
    } catch (InstantiationException e) {
        throw new PersistenceException(e);
    } catch (IllegalAccessException e) {
        throw new PersistenceException(e);
    } catch (RuntimeException e) {
        logger.error(e.getMessage(), e);
        throw new PersistenceException(e);
    } catch (Error e) {
        logger.error(e.getMessage(), e);
        throw new PersistenceException(e.getMessage());
    }
}

From source file:org.dasein.persist.PersistentCache.java

protected @Nonnull T toTargetFromMap(@Nonnull String dataStoreVersion,
        @Nonnull Map<String, Object> dataStoreState) throws PersistenceException {
    try {/*from ww  w . ja v  a2s .c o m*/
        while (!dataStoreVersion.equals(schemaVersion)) {
            SchemaMapper mapper = getSchemaMapper(dataStoreVersion);

            if (mapper == null) {
                break;
            }
            dataStoreState = mapper.map(dataStoreVersion, dataStoreState);
            dataStoreVersion = mapper.getTargetVersion();
        }
        Class<T> targetClass = getTarget();
        Class<? extends Object> t = targetClass;
        T item = targetClass.newInstance();

        while (!t.getName().equals(Object.class.getName())) {
            for (Field field : t.getDeclaredFields()) {
                int modifiers = field.getModifiers();

                if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) {
                    Object value = dataStoreState.get(field.getName());

                    set(item, field, value);
                }
            }
            t = t.getSuperclass();
        }
        return item;
    } catch (InstantiationException e) {
        throw new PersistenceException(e);
    } catch (IllegalAccessException e) {
        throw new PersistenceException(e);
    } catch (RuntimeException e) {
        logger.error(e.getMessage(), e);
        throw new PersistenceException(e);
    } catch (Error e) {
        logger.error(e.getMessage(), e);
        throw new PersistenceException(e.getMessage());
    }
}

From source file:jp.co.acroquest.jsonic.JSON.java

/**
 * Ignore this property. A default behavior is to ignore transient or declaring method in java.lang.Object.
 * You can override this method if you have to change default behavior.
 * //from  ww  w.jav  a2s  . c  o m
 * @param context current context
 * @param target target class
 * @param member target member
 * @return true if this member must be ignored.
 */
protected boolean ignore(Context context, Class<?> target, Member member) {
    if (Modifier.isTransient(member.getModifiers()))
        return true;
    if (member.getDeclaringClass().equals(Object.class))
        return true;
    return false;
}

From source file:org.apache.flink.api.java.typeutils.TypeExtractor.java

private int countFieldsInClass(Class<?> clazz) {
    int fieldCount = 0;
    for (Field field : clazz.getFields()) { // get all fields
        if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) {
            fieldCount++;/* w  w w .  j  a v  a 2  s . co  m*/
        }
    }
    return fieldCount;
}