Object delegate = support.getBehaviourDelegate(); if (delegate != entity) { addObject(resource, delegate); return; merged.add(resource); boolean autoCommit = isAutoCommit(); if (autoCommit) { setAutoCommit(false); Set<URI> list = getTypes(proxy, new HashSet<URI>(4)); for (URI type : list) { types.addTypeStatement(resource, type); setAutoCommit(true); if (autoCommit && !isAutoCommit()) { rollback(); setAutoCommit(true);
public SparqlBuilder(ObjectConnection con, SPARQLQuery query) { assert con != null; assert query != null; this.con = con; this.query = query; of = con.getObjectFactory(); }
private void replace(int index, Object o) throws RepositoryException { if (o == null) throw new NullPointerException(); URI pred = getMemberPredicate(index); ObjectConnection conn = getObjectConnection(); Value newValue = getObjectConnection().addObject(o); boolean autoCommit = conn.isAutoCommit(); if (autoCommit) conn.setAutoCommit(false); try { conn.remove(getResource(), pred, null); conn.add(getResource(), pred, newValue); if (autoCommit) conn.setAutoCommit(true); } finally { if (autoCommit && !conn.isAutoCommit()) { conn.rollback(); conn.setAutoCommit(true); } } Object[] block = getBlock(index / BSIZE); if (block != null) { block[index % BSIZE] = o; } }
/** * Assigns a URI to this connection to be used for new blob versions and the * default insert graph. * * @param bundle * a unique URI */ public void setVersionBundle(URI bundle) { versionBundle = bundle; if (null == getInsertContext()) { setInsertContext(bundle); } }
public <T> Result<T> getObjects(Class<T> concept, String... uris) throws RepositoryException, QueryEvaluationException { ValueFactory vf = getValueFactory(); Resource[] resources = new Resource[uris.length]; for (int i = 0; i < uris.length; i++) { resources[i] = vf.createURI(uris[i]); } return getObjects(concept, resources); }
/** * Imports the entity into the RDF store using the given URI. */ public void addObject(String uri, Object entity) throws RepositoryException { addObject(getValueFactory().createURI(uri), entity); }
/** * Explicitly adds the concept to the entity. * * @return the entity with new composed concept */ public <T> T addDesignation(Object entity, Class<T> concept) throws RepositoryException { if (entity instanceof RDFObjectBehaviour) { RDFObjectBehaviour support = (RDFObjectBehaviour) entity; Object delegate = support.getBehaviourDelegate(); if (delegate != entity) { return addDesignation(delegate, concept); } } Resource resource = findResource(entity); Set<URI> types = new HashSet<URI>(4); getTypes(entity.getClass(), types); addConcept(resource, concept, types); Object bean = of.createObject(resource, types); assert assertConceptRecorded(bean, concept); return (T) bean; }
private Object getAndSet(int index, Object o) throws RepositoryException { if (o == null) throw new NullPointerException(); URI pred = getMemberPredicate(index); Object old = get(index); ObjectConnection conn = getObjectConnection(); if (old != null) { conn.remove(getResource(), pred, null); } conn.add(getResource(), pred, conn.addObject(o)); Object[] block = getBlock(index / BSIZE); if (block != null) { block[index % BSIZE] = o; } return old; }
Object entity = support.getBehaviourDelegate(); if (entity != instance) return addObject(entity); if (RDFObject.class.isAssignableFrom(type) || isEntity(type)) { Resource resource = assignResource(instance); if (!isAlreadyMerged(resource)) { addObject(resource, instance);
protected Object createInstance(Value value) throws RepositoryException { if (value instanceof Resource) return getObjectConnection().getObject((Resource) value); return getObjectConnection().getObjectFactory().createObject( ((Literal) value)); }
private void assign(int index, Object o) throws RepositoryException { if (o == null) throw new NullPointerException(); URI pred = getMemberPredicate(index); Value newValue = getObjectConnection().addObject(o); ObjectConnection conn = getObjectConnection(); conn.add(getResource(), pred, newValue); clearBlock(index / BSIZE); }
@Override public <T> T createObject(Class<T> clazz, Resource id) throws RepositoryException, IllegalAccessException, InstantiationException { ObjectFactory objectFactory = connection.getObjectFactory(); Resource resource = (id != null) ? id : IDGenerator.BLANK_RESOURCE; T object = objectFactory.createObject(resource, clazz); return connection.addDesignation(object, clazz); }
/** * Checks whether there is any other resource than the given one which has an {@code rdfs:label} * which would possibly result in the same identifier name by {@link #toJavaName(String)}. * @param resource The resource that has the label. * @param label The label to check for. * @return Returns true iff there is no possibly conflicting label within the repository. * @throws RepositoryException Thrown if an error occurs while querying the repository. */ private boolean isRDFSLabelUnique(ResourceObject resource, String label) throws RepositoryException { // A conflicting label may be lead by some non-alphanumeric characters: StringBuilder regex = new StringBuilder("([^a-zA-Z0-9])*"); for(int i = 0; i < label.length(); i++) { char c = label.charAt(i); if(Character.isJavaIdentifierPart(c)) { regex.append(c); } // Between each char (and at the end) there may be non-alphanumeric chars (would be pruned out by name generation): regex.append("([^0-9a-zA-Z])*"); } try { return !connection.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK {" + " ?s rdfs:label ?l . " + " FILTER( ?s != <" + resource.getResourceAsString() + "> && REGEX(LCASE(str(?l)), \"" + regex + "\") )" + "}" ).evaluate(); } catch (MalformedQueryException | QueryEvaluationException | RepositoryException e) { throw new RepositoryException(e); } }
private CloseableIteration<Value, RepositoryException> getValues(Resource subj, URI pred, Value obj) { try { RepositoryResult<Statement> stmts; ObjectConnection conn = getObjectConnection(); stmts = conn.getStatements(subj, pred, obj); return new ConvertingIteration<Statement, Value, RepositoryException>(stmts) { @Override protected Value convert(Statement stmt) throws RepositoryException { return stmt.getObject(); } }; } catch (RepositoryException e) { throw new ObjectStoreException(e); } }
private Object getDefaultValue(String value, Type type, ObjectConnection con) { Class<?> ctype = asClass(type); if (Set.class.equals(ctype)) { Object v = getDefaultValue(value, getComponentType(ctype, type), con); if (v == null) return null; return Collections.singleton(v); } ValueFactory vf = con.getValueFactory(); ObjectFactory of = con.getObjectFactory(); if (of.isDatatype(ctype)) { URIImpl datatype = new URIImpl("java:" + ctype.getName()); return of.createValue(of.createObject(new LiteralImpl(value, datatype))); } return vf.createURI(value); }
/** * {@inheritDoc } */ @Override public void persist(ResourceObject resource) throws RepositoryException { connection.addObject(resource); }
URI rootType = connection.getObjectFactory().getNameOf(type); if (rootType == null) { throw new IllegalArgumentException("Can't query for: " + type + " not found in name map. Is @Iri annotation set?"); logger.debug("Query after join order optimization:\n " + q); ObjectQuery query = connection.prepareObjectQuery(q);
public void add(ObjectConnection conn, Resource subj, Value obj) throws RepositoryException { conn.add(subj, pred, obj); }
public String toString() { try { URI uri = getVersionBundle(); if (uri == null) return getDelegate().toString(); return uri.stringValue(); } catch (RepositoryException e) { return super.toString(); } }
public void recompileSchemaOnClose() { getRepository().compileAfter(this); }