/** * This methods gives the requested child element for the given child name and attribute * * @param childName child element name * @param attribute attribute of the child element * @return * @throws org.wso2.carbon.automation.engine.configurations.exceptions.NonExistenceException */ public Configuration get(String childName, Attribute attribute) throws NonExistenceException { ArrayList<DynamicEntity> childEntity = rootEntity.get(childName); for (DynamicEntity dynamicEntity : childEntity) { if (((dynamicEntity.get(attribute.getName()))).equals(attribute.getValue())) { rootEntity = dynamicEntity; return this; } } throw new NonExistenceException("No Such element found"); }
@Override public String marshal(DynamicEntity v) throws Exception { if (null == jc || null == v) { return null; } String street = v.get("street"); street = street.replace(' ', '_'); String city = v.get("city"); String state = v.get("state"); String zip = v.get("zip"); return street + "|" + city + "|" + state + "|" + zip; }
@Test public void createAwithB() { DynamicType simpleTypeA = helper.getType("SimpleA"); assertNotNull(simpleTypeA); DynamicType simpleTypeB = helper.getType("SimpleB"); assertNotNull(simpleTypeB); EntityManager em = emf.createEntityManager(); assertNotNull(JpaHelper.getServerSession(emf).getDescriptorForAlias("SimpleB")); DynamicEntity simpleInstanceB = simpleTypeB.newDynamicEntity(); simpleInstanceB.set("id", 1); simpleInstanceB.set("value1", "B2"); DynamicEntity simpleInstanceA = simpleTypeA.newDynamicEntity(); simpleInstanceA.set("id", 1); simpleInstanceA.set("value1", "A2"); simpleInstanceA.<Collection<DynamicEntity>>get("b").add(simpleInstanceB); simpleInstanceB.set("a", simpleInstanceA); em.getTransaction().begin(); em.persist(simpleInstanceB); em.persist(simpleInstanceA); em.getTransaction().commit(); int simpleCountB = ((Number) em.createQuery("SELECT COUNT(s) FROM SimpleB s").getSingleResult()).intValue(); assertEquals(1, simpleCountB); int simpleCountA = ((Number) em.createQuery("SELECT COUNT(s) FROM SimpleA s").getSingleResult()).intValue(); assertEquals(1, simpleCountA); em.close(); }
@Test public void removeAwithB_PrivateOwned() { createAwithB(); DynamicType simpleAType = helper.getType("SimpleA"); ((OneToManyMapping) simpleAType.getDescriptor().getMappingForAttributeName("b")) .setIsPrivateOwned(true); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); DynamicEntity a = (DynamicEntity) em.find(simpleAType.getJavaClass(), 1); assertNotNull(a); assertEquals(1, a.<Collection>get("b").size()); em.remove(a); // em.remove(a.get("b", List.class).get(0)); em.getTransaction().commit(); }
/** * This method provides the property value of the given property name in generic type * * @param propertyName name of the property * @param <T> generic type * @return requested property value */ public <T> T getValue(String propertyName) { return rootEntity.get(propertyName); }
public Configuration get(String childName) { rootEntity = rootEntity.get(childName); return this; }
public String buildFieldValue(Object instance, String fieldName, Session session) { DynamicEntity person = (DynamicEntity) instance; return person.get("start-time"); }