/** * 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); } }
PropertyAccessorHelper.set(columnFamilyObj, columnField, columnValue);
/** * Builds the entity from cursor. * * @param entity * the entity * @param obj * the obj * @param entityType * the entity type * @return the object */ private void buildEntityFromCursor(Object entity, HashMap obj, EntityType entityType) { Iterator<Attribute> iter = entityType.getAttributes().iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); Field field = (Field) attribute.getJavaMember(); if (field.isAnnotationPresent(Id.class)) { PropertyAccessorHelper.set(entity, field, obj.get(ID)); } else { PropertyAccessorHelper.set(entity, field, obj.get(((AbstractAttribute) attribute).getJPAColumnName())); } } }
private static void setFieldValue(Object entity, Object value, Attribute column) { value = PropertyAccessorHelper.fromSourceToTargetClass(column.getJavaType(), value.getClass(), value); PropertyAccessorHelper.set(entity, (Field) column.getJavaMember(), 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); }
/** * 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); }
private void setInvalidClient(PersistenceDelegator pd) throws NoSuchFieldException, SecurityException { Map<String, Client> clientMap = new HashMap<String, Client>(); clientMap.put(persistenceUnit, new CoreTestClientNoGenerator(null, persistenceUnit, kunderaMetadata)); PropertyAccessorHelper.set(pd, pd.getClass().getDeclaredField("clientMap"), clientMap); }
/** * Sets the field value. * * @param entity * the entity * @param column * the column * @param value * the value */ private static void setFieldValue(Object entity, Attribute column, JsonElement value) { if (column.getJavaType().isAssignableFrom(byte[].class)) { PropertyAccessorHelper.set(entity, (Field) column.getJavaMember(), PropertyAccessorFactory.STRING.toBytes(value.getAsString())); } else { PropertyAccessorHelper.set( entity, (Field) column.getJavaMember(), PropertyAccessorHelper.fromSourceToTargetClass(column.getJavaType(), String.class, value.getAsString())); } }
PropertyAccessorHelper.set(embeddedObject, superColumnFieldMap.get(thriftColumnName), thriftColumnValue);
/** * Iterate and populate entity. * * @param entity * the entity * @param obj * the obj * @param iterator * the iterator */ private void iterateAndPopulateEntity(Object entity, JsonObject obj, Iterator<Attribute> iterator) { while (iterator.hasNext()) { Attribute attribute = iterator.next(); Field field = (Field) attribute.getJavaMember(); String colName = ((AbstractAttribute) attribute).getJPAColumnName(); if (!colName.equalsIgnoreCase(CouchbaseConstants.KUNDERA_ENTITY) && obj.get(colName) != null) { Object value = ConvertUtils.convert(obj.get(colName), field.getType()); PropertyAccessorHelper.set(entity, field, value); } } }
protected boolean add(final Object object) { eagerlyLoadDataCollection(); boolean result = false; if (dataCollection == null) { createEmptyDataCollection(); } if (dataCollection != null && !(dataCollection instanceof ProxyCollection) && ! ((Collection) dataCollection).contains(object) && object != null) { // getPersistenceDelegator().persist(object); ((Collection) dataCollection).add(object); PropertyAccessorHelper.set(getOwner(), getRelation().getProperty(), dataCollection); result = true; } return result; }
/** * Sets the field. * * @param result * the result * @param key * the key * @param attribute * the attribute * @param fieldValue * the field value */ private void setField(Object result, Object key, Attribute attribute, Object fieldValue) { if (fieldValue != null) { if (((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Date.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(java.sql.Date.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Timestamp.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Calendar.class)) { PropertyAccessorFactory.STRING.fromString(((AbstractAttribute) attribute).getBindableJavaType(), fieldValue.toString()); } else if (key == null || !key.equals(fieldValue)) { PropertyAccessorHelper.set(result, (Field) attribute.getJavaMember(), fieldValue); } } }
private void populateEntityFromDocument(Object entity, Object rowKey, MetamodelImpl metaModel, AbstractAttribute attrib) throws InstantiationException, IllegalAccessException { EmbeddableType embeddable = metaModel.embeddable(attrib.getBindableJavaType()); Iterator<Attribute> iter = embeddable.getAttributes().iterator(); Object compoundKey = attrib.getBindableJavaType().newInstance(); while (iter.hasNext()) { AbstractAttribute compositeAttrib = (AbstractAttribute) iter.next(); Object value = ((BasicDBObject) rowKey).get(compositeAttrib.getJPAColumnName()); if (metaModel.isEmbeddable(compositeAttrib.getBindableJavaType())) { populateEntityFromDocument(compoundKey, value, metaModel, compositeAttrib); } else { PropertyAccessorHelper.set(compoundKey, (Field) compositeAttrib.getJavaMember(), value); } } PropertyAccessorHelper.set(entity, (Field) attrib.getJavaMember(), compoundKey); }
/** * Sets Primary Key (Row key) into entity field that was annotated with @Id. * * @param entity * the entity * @param metadata * the metadata * @param rowKey * the row key * @throws PropertyAccessException * the property access exception */ public static void setId(Object entity, EntityMetadata metadata, Object rowKey) { try { Field idField = (Field) metadata.getIdAttribute().getJavaMember(); set(entity, idField, rowKey); } catch (IllegalArgumentException iarg) { throw new PropertyAccessException(iarg); } }
/** * Sets Primary Key (Row key) into entity field that was annotated with @Id. * * @param entity * the entity * @param metadata * the metadata * @param rowKey * the row key * @throws PropertyAccessException * the property access exception */ public static void setId(Object entity, EntityMetadata metadata, byte[] rowKey) { try { Field idField = (Field) metadata.getIdAttribute().getJavaMember(); set(entity, idField, rowKey); } catch (IllegalArgumentException iarg) { throw new PropertyAccessException(iarg); } }
/** * Test method for {@link com.impetus.kundera.property.PropertyAccessorHelper#set(java.lang.Object, java.lang.reflect.Field, java.lang.Object)}. */ @Test public void testSetObjectFieldObject() { PersonnelDTO person = new PersonnelDTO(); try { Object id = "1"; Object fn = "Amresh"; Object ln = "Singh"; PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("personId"), id); PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("firstName"), fn); PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("lastName"), ln); Assert.assertEquals("1", person.getPersonId()); Assert.assertEquals("Amresh", person.getFirstName()); Assert.assertEquals("Singh", person.getLastName()); } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchFieldException e) { Assert.fail(e.getMessage()); } }
/** * Test method for {@link com.impetus.kundera.property.PropertyAccessorHelper#set(java.lang.Object, java.lang.reflect.Field, byte[])}. */ @Test public void testSetObjectFieldByteArray() { PersonnelDTO person = new PersonnelDTO(); try { PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("personId"), "1".getBytes()); PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("firstName"), "Amresh".getBytes()); PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("lastName"), "Singh".getBytes()); Assert.assertEquals("1", person.getPersonId()); Assert.assertEquals("Amresh", person.getFirstName()); Assert.assertEquals("Singh", person.getLastName()); } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchFieldException e) { Assert.fail(e.getMessage()); } }
/** * Test method for {@link com.impetus.kundera.property.PropertyAccessorHelper#set(java.lang.Object, java.lang.reflect.Field, java.lang.String)}. */ @Test public void testSetObjectFieldString() { PersonnelDTO person = new PersonnelDTO(); try { PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("personId"), "1"); PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("firstName"), "Amresh"); PropertyAccessorHelper.set(person, person.getClass().getDeclaredField("lastName"), "Singh"); Assert.assertEquals("1", person.getPersonId()); Assert.assertEquals("Amresh", person.getFirstName()); Assert.assertEquals("Singh", person.getLastName()); } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchFieldException e) { Assert.fail(e.getMessage()); } }
/** * On via embeddable. * * @param entityType * the entity type * @param column * the column * @param m * the m * @param entity * the entity * @param embeddable * the embeddable * @param jsonObj * the json obj */ private static void onViaEmbeddable(EntityType entityType, Attribute column, EntityMetadata m, Object entity, EmbeddableType embeddable, JsonObject jsonObj) { Field embeddedField = (Field) column.getJavaMember(); JsonElement embeddedDocumentObject = jsonObj.get(((AbstractAttribute) column).getJPAColumnName()); if (!column.isCollection()) { PropertyAccessorHelper.set( entity, embeddedField, getObjectFromJson(embeddedDocumentObject.getAsJsonObject(), ((AbstractAttribute) column).getBindableJavaType(), embeddable.getAttributes())); } }
/** * After successfully parsing set relational entity object within entity * object. * * @param entity * @param relationEntity * @param relation */ private void setRelationToEntity(Object entity, Object relationEntity, Relation relation) { if (relation.getTargetEntity().isAssignableFrom(getEntity(relationEntity).getClass())) { if (relation.isUnary()) { PropertyAccessorHelper.set(entity, relation.getProperty(), getEntity(relationEntity)); } else { Object associationObject = PropertyAccessorHelper.getObject(entity, relation.getProperty()); if (associationObject == null || ProxyHelper.isProxyOrCollection(associationObject)) { associationObject = PropertyAccessorHelper.getCollectionInstance(relation.getProperty()); PropertyAccessorHelper.set(entity, relation.getProperty(), associationObject); } ((Collection) associationObject).add(getEntity(relationEntity)); } } }