コード例 #1
0
 /**
  * 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");
 }
コード例 #2
0
  @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;
  }
コード例 #3
0
 @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();
 }
コード例 #4
0
 @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();
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
 public Configuration get(String childName) {
   rootEntity = rootEntity.get(childName);
   return this;
 }
コード例 #7
0
 public String buildFieldValue(Object instance, String fieldName, Session session) {
   DynamicEntity person = (DynamicEntity) instance;
   return person.get("start-time");
 }