示例#1
0
 /**
  * Explicitly adds the types to the entity.
  *
  * @return the entity with new composed types
  */
 public Object addDesignations(Object entity, URI... types) throws RepositoryException {
   if (entity instanceof RDFObjectBehaviour) {
     RDFObjectBehaviour support = (RDFObjectBehaviour) entity;
     Object delegate = support.getBehaviourDelegate();
     if (delegate != entity) {
       return addDesignations(delegate, types);
     }
   }
   assert types != null && types.length > 0;
   Resource resource = findResource(entity);
   Set<URI> list = new HashSet<URI>(4);
   getTypes(entity.getClass(), list);
   boolean autoCommit = isAutoCommit();
   if (autoCommit) {
     setAutoCommit(false);
   }
   try {
     for (URI type : types) {
       this.types.addTypeStatement(resource, type);
       list.add(type);
     }
     if (autoCommit) {
       setAutoCommit(true);
     }
   } finally {
     if (autoCommit && !isAutoCommit()) {
       rollback();
       setAutoCommit(true);
     }
   }
   return cache(of.createObject(resource, list));
 }
示例#2
0
 /** Explicitly removes the types from the entity. */
 public void removeDesignations(Object entity, URI... types) throws RepositoryException {
   assert types != null && types.length > 0;
   boolean autoCommit = isAutoCommit();
   if (autoCommit) {
     setAutoCommit(false);
   }
   try {
     Resource resource = findResource(entity);
     for (URI type : types) {
       this.types.removeTypeStatement(resource, type);
     }
     if (autoCommit) {
       setAutoCommit(true);
     }
     cachedObjects.remove(resource);
   } finally {
     if (autoCommit && !isAutoCommit()) {
       rollback();
       setAutoCommit(true);
     }
   }
 }
示例#3
0
 /** Imports the entity into the RDF store using the given handle. */
 public void addObject(Resource resource, Object entity) throws RepositoryException {
   if (entity instanceof RDFObjectBehaviour) {
     RDFObjectBehaviour support = (RDFObjectBehaviour) entity;
     Object delegate = support.getBehaviourDelegate();
     if (delegate != entity) {
       addObject(resource, delegate);
       return;
     }
   }
   synchronized (merged) {
     merged.add(resource);
   }
   boolean autoCommit = isAutoCommit();
   if (autoCommit) {
     setAutoCommit(false);
   }
   try {
     Class<?> proxy = entity.getClass();
     Set<URI> list = getTypes(proxy, new HashSet<URI>(4));
     for (URI type : list) {
       types.addTypeStatement(resource, type);
     }
     Object result = of.createObject(resource, list);
     if (result instanceof Mergeable) {
       ((Mergeable) result).merge(entity);
     }
     if (autoCommit) {
       setAutoCommit(true);
     }
     cachedObjects.remove(resource);
   } finally {
     if (autoCommit && !isAutoCommit()) {
       rollback();
       setAutoCommit(true);
     }
   }
 }