Example #1
0
  public void store(MeemPath meemPath, MeemContent content) {
    if (content == null) {
      return;
    }

    if (DEBUG) {
      logger.log(Level.INFO, "Storing " + meemPath);
    }

    try {
      EntityManager em = PersistenceContext.instance().getEntityManager();
      em.getTransaction().begin();

      String meemId = meemPath.getLocation();
      //			MeemEntity meemEntity = em.find(MeemEntity.class, meemId);
      //			if (meemEntity == null) {
      //				//logger.info("could not locate Meem in storage, " + meemPath.getLocation());
      //				meemEntity = new MeemEntity();
      //				meemEntity.setId(meemPath.getLocation());
      //				em.persist(meemEntity);
      //			}

      Collection<String> wedgeIds = content.getWedgeIdentifiers();
      for (String wedgeName : wedgeIds) {
        Map<String, Serializable> fields = content.getPersistentFields(wedgeName);
        if (fields != null && fields.size() > 0) {
          for (Entry<String, Serializable> field : fields.entrySet()) {
            String name = field.getKey();
            Serializable value = field.getValue();

            ContentPK key = new ContentPK(meemId, wedgeName, name);
            ContentEntity contentEntity = em.find(ContentEntity.class, key);
            if (contentEntity == null) {
              contentEntity = new ContentEntity();
              contentEntity.setMeemId(meemId);
              contentEntity.setWedgeName(wedgeName);
              contentEntity.setName(name);
              contentEntity.setType(PropertyType.typeOf(value));
              contentEntity.setValue(value);

              em.persist(contentEntity);
            } else {
              contentEntity.setType(PropertyType.typeOf(value));
              contentEntity.setValue(value);
            }
          }
        }
      }
      em.getTransaction().commit();
    } catch (Exception e) {
      logger.log(Level.INFO, "Exception while storing MeemContent " + meemPath.toString(), e);
    } finally {
      PersistenceContext.instance().release();
    }
  }