private Element createRelatedChildElem(ContentEntity child) {
   Element childEl = new Element("content");
   childEl.setAttribute("key", child.getKey().toString());
   childEl.setAttribute("deleted", Boolean.toString(child.isDeleted()));
   childEl.addContent(new Element("repositorypath").setText(child.getPathAsString()));
   childEl.addContent(new Element("title").setText(child.getMainVersion().getTitle()));
   return childEl;
 }
Example #2
0
  @Override
  protected ContentEntity dataToEntity(Content content) {
    ContentEntity entity = new ContentEntity();

    entity.setId(Integer.parseInt(content.get("id")));
    entity.setContent(content);

    return entity;
  }
Example #3
0
  @Override
  protected Content entityToData(ContentEntity entity) {
    Content content = new Content();
    content.putAll(entity.getContent());

    return content;
  }
Example #4
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();
    }
  }
Example #5
0
  public MeemContent load(MeemPath meemPath) {

    if (DEBUG) {
      logger.info("Loading content for " + meemPath);
    }

    MeemContent meemContent = new MeemContent();

    // This classloader change is to allows classes loaded by eclipse to perform Class.forName()
    ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

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

        @SuppressWarnings("unchecked")
        List<ContentEntity> content =
            em.createNamedQuery("Content.selectForMeem")
                .setParameter(1, meemPath.getLocation())
                .getResultList();

        for (ContentEntity contentItem : content) {
          meemContent.addPersistentField(
              contentItem.getWedgeName(), contentItem.getName(), contentItem.getValue());
        }

        em.getTransaction().commit();
      } catch (Exception e) {
        logger.log(Level.INFO, "Exception while loading MeemContent " + meemPath.toString(), e);
      } finally {
        PersistenceContext.instance().release();
      }
    } finally {
      Thread.currentThread().setContextClassLoader(previousClassLoader);
    }

    return meemContent;
  }