Example #1
0
  /** @inheritDoc */
  @SuppressWarnings("unchecked")
  public <T> T merge(final T theT) {
    assertStateOk(theT);

    Graph aExistingData = null;

    if (theT instanceof EmpireGenerated) {
      aExistingData = ((EmpireGenerated) theT).getInstanceTriples();
    }

    if (aExistingData == null || aExistingData.isEmpty()) {
      try {
        aExistingData = assertContainsAndDescribe(theT);
      } catch (IllegalArgumentException e) {
        // it doesnt exist, so really, nothing to delete
        aExistingData = new GraphImpl();
      }
    }

    try {
      preUpdate(theT);

      Graph aData = RdfGenerator.asRdf(theT);

      boolean isTopOperation = (mOp == null);

      DataSourceOperation aOp = new DataSourceOperation();

      if (doesSupportNamedGraphs() && EmpireUtil.hasNamedGraphSpecified(theT)) {
        java.net.URI aGraphURI = EmpireUtil.getNamedGraph(theT);

        aOp.remove(aGraphURI, aExistingData);
        aOp.add(aGraphURI, aData);
      } else {
        aOp.remove(aExistingData);
        aOp.add(aData);
      }

      joinCurrentDataSourceOperation(aOp);

      // cascade the merge
      cascadeOperation(theT, new IsMergeCascade(), new MergeCascade());

      finishCurrentDataSourceOperation(isTopOperation);

      postUpdate(theT);

      return theT;
    } catch (DataSourceException ex) {
      throw new PersistenceException(ex);
    } catch (InvalidRdfException ex) {
      throw new IllegalStateException(ex);
    }
  }
Example #2
0
  /** @inheritDoc */
  public void remove(final Object theObj) {
    assertStateOk(theObj);

    Graph aData = assertContainsAndDescribe(theObj);

    try {
      preRemove(theObj);

      boolean isTopOperation = (mOp == null);

      DataSourceOperation aOp = new DataSourceOperation();

      // we were transforming the current object to RDF and deleting that, but i dont think that's
      // the intended
      // behavior.  you want to delete everything about the object in the database, not the
      // properties specifically
      // on the thing being deleted -- there's an obvious case where there could be a delta between
      // them and you
      // don't delete everything.  so we'll do a describe on the object and delete everything we
      // know about it
      // i.e. everything where its in the subject position.

      // Graph aData = RdfGenerator.asRdf(theObj);
      // Graph aData = DataSourceUtil.describe(getDataSource(), theObj);

      if (doesSupportNamedGraphs() && EmpireUtil.hasNamedGraphSpecified(theObj)) {
        aOp.remove(EmpireUtil.getNamedGraph(theObj), aData);
      } else {
        aOp.remove(aData);
      }

      joinCurrentDataSourceOperation(aOp);

      cascadeOperation(theObj, new IsRemoveCascade(), new RemoveCascade());

      finishCurrentDataSourceOperation(isTopOperation);

      postRemove(theObj);
    } catch (DataSourceException ex) {
      throw new PersistenceException(ex);
    }
  }
Example #3
0
  /** @inheritDoc */
  public void persist(final Object theObj) {
    assertStateOk(theObj);

    try {
      assertNotContains(theObj);
    } catch (Throwable e) {
      throw new EntityExistsException(e);
    }

    try {
      prePersist(theObj);

      boolean isTopOperation = (mOp == null);

      DataSourceOperation aOp = new DataSourceOperation();

      Graph aData = RdfGenerator.asRdf(theObj);

      if (doesSupportNamedGraphs() && EmpireUtil.hasNamedGraphSpecified(theObj)) {
        aOp.add(EmpireUtil.getNamedGraph(theObj), aData);
      } else {
        aOp.add(aData);
      }

      joinCurrentDataSourceOperation(aOp);

      cascadeOperation(theObj, new IsPersistCascade(), new MergeCascade());

      finishCurrentDataSourceOperation(isTopOperation);

      postPersist(theObj);
    } catch (InvalidRdfException ex) {
      throw new IllegalStateException(ex);
    } catch (DataSourceException ex) {
      throw new PersistenceException(ex);
    }
  }