public static final byte[] toBytes(Object o, Field f) { PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(f); return accessor.toBytes(o); }
public static final Object getObject(Class<?> clazz) { PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(clazz); return accessor.getInstance(clazz); }
public static Object getObject(Class clazz, byte[] b) { return PropertyAccessorFactory.getPropertyAccessor(clazz).fromBytes(clazz, b); }
/** * Gets field value as byte-array. * * @param from * the from * @param field * the field * * @return the byte[] * * @throws PropertyAccessException * the property access exception */ public static byte[] get(Object from, Field field) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field); return accessor.toBytes(getObject(from, field)); }
/** * Sets a byte-array onto a field. * * @param target * the target * @param field * the field * @param fieldVal * the field value * * @throws PropertyAccessException * the property access exception */ public static void set(Object target, Field field, String fieldVal) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field); Object value = accessor.fromString(target.getClass(), fieldVal); set(target, field, value); }
/** * Sets a byte-array onto a field. * * @param target * the target * @param field * the field * @param bytes * the bytes * * @throws PropertyAccessException * the property access exception */ public static void set(Object target, Field field, byte[] bytes) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field); Object value = accessor.fromBytes(field.getType(), bytes); set(target, field, value); }
/** * Gets the string. * * @param from * the from * @param field * the field * * @return the string * * @throws PropertyAccessException * the property access exception */ public static String getString(Object from, Field field) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field); Object object = getObject(from, field); return object != null ? accessor.toString(object) : null; }
public static Object fromDate(Class<?> targetClass, Class<?> sourceClass, Object o) { if (!targetClass.equals(sourceClass)) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(sourceClass); byte[] b = accessor.toBytes(o); accessor = PropertyAccessorFactory.getPropertyAccessor(targetClass); return accessor.fromBytes(targetClass, b); } return o; }
public static Object fromSourceToTargetClass(Class<?> targetClass, Class<?> sourceClass, Object o) { if (!targetClass.equals(sourceClass)) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(sourceClass); String s = accessor.toString(o); accessor = PropertyAccessorFactory.getPropertyAccessor(targetClass); return accessor.fromString(targetClass, s); } return o; }
/** * Sets the field value. * * @param entity * the entity * @param member * the member * @param retVal * the ret val */ private static void setFieldValue(Object entity, Field member, Object retVal) { if (member != null && retVal != null && entity != null) { PropertyAccessorHelper.set(entity, member, retVal); } }
/** * Retutrns copy of object * * @param from * @param field * @return */ public static Object getObjectCopy(Object from, Field field) { if (!field.isAccessible()) { field.setAccessible(true); } try { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field); return accessor.getCopy(field.get(from)); } catch (IllegalArgumentException iarg) { throw new PropertyAccessException(iarg); } catch (IllegalAccessException iacc) { throw new PropertyAccessException(iacc); } }
public static String getString(Object o) { return o != null ? PropertyAccessorFactory.getPropertyAccessor(o.getClass()).toString(o) : null; }
@Override public Object getIdentifier(Object entity) { Class<?> entityClass = entity.getClass(); // EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass); // // if (entityMetadata == null) // { // throw new IllegalArgumentException(entityClass + " is not an entity"); // } return PropertyAccessorHelper.getId(entity, /*entityMetadata*/null); }
/** * Populates foreign key as column. * * @param rlName * relation name * @param rlValue * relation value * @param timestamp * the timestamp * @return the column * @throws PropertyAccessException * the property access exception */ protected Column populateFkey(String rlName, Object rlValue, long timestamp) throws PropertyAccessException { Column col = new Column(); col.setName(PropertyAccessorFactory.STRING.toBytes(rlName)); col.setValue(PropertyAccessorHelper.getBytes(rlValue)); col.setTimestamp(timestamp); return col; }
/** * Gets the property accessor. * * @param property * the property * * @return the property accessor */ public static PropertyAccessor<?> getPropertyAccessor(Field property) { return getPropertyAccessor(property.getType()); }
/** * Populate counter fkey. * * @param rlName * the rl name * @param rlValue * the rl value * @return the counter column */ private CounterColumn populateCounterFkey(String rlName, Object rlValue) { CounterColumn counterCol = new CounterColumn(); counterCol.setName(PropertyAccessorFactory.STRING.toBytes(rlName)); counterCol.setValue((Long) rlValue); return counterCol; }
/** * Test method for {@link com.impetus.kundera.property.accessor.BigIntegerAccessor#getInstance(java.lang.Class)}. */ @Test public void testGetInstance() { Assert.assertEquals(BigInteger.TEN, accessor.getInstance(BigInteger.class)); }
public static final byte[] toBytes(Object o, Class c) { PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(c); return accessor.toBytes(o); }
/** * Test method for * {@link com.impetus.kundera.property.accessor.BooleanAccessor#getInstance(java.lang.Class)} * . */ @Test public void testGetInstance() { Assert.assertTrue((Boolean) accessor.getInstance(Boolean.class)); }
public static byte[] getBytes(Object o) { return PropertyAccessorFactory.getPropertyAccessor(o.getClass()).toBytes(o); }