/** * Test method for {@link com.impetus.kundera.property.PropertyAccessorHelper#getCollectionInstance(java.lang.reflect.Field)}. */ @Test public void testGetCollectionInstance() { try { Collection c = PropertyAccessorHelper.getCollectionInstance(PhotographerUni_1_M_1_M.class.getDeclaredField("albums")); Assert.assertNotNull(c); Assert.assertTrue(c instanceof ArrayList); c = PropertyAccessorHelper.getCollectionInstance(CacheBase.class.getDeclaredField("headNodes")); Assert.assertNotNull(c); Assert.assertTrue(c instanceof HashSet); } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchFieldException e) { Assert.fail(e.getMessage()); } }
/** * 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)); } } }
embeddedObject, columnNameToFieldMap); Collection collection = PropertyAccessorHelper.getCollectionInstance(embeddedCollectionField); collection.add(embeddedObject);
embeddedObject, columnNameToFieldMap); Collection collection = PropertyAccessorHelper.getCollectionInstance(embeddedCollectionField); collection.add(embeddedObject);