@Test public void FindStatements() { ID subject = new BID(); Set<STMT> additions = new HashSet<STMT>(); additions.add(new STMT(subject, RDF.type, RDF.Property)); additions.add(new STMT(subject, RDFS.label, new LIT("type"))); additions.add(new STMT(subject, RDFS.label, new LIT("tyyppi", new Locale("fi")))); Set<STMT> removals = new HashSet<STMT>(); conn.update(removals, additions); assertEquals(3, conn.find(subject, null, null, null, false).size()); assertEquals(1, conn.find(subject, RDF.type, null, null, false).size()); assertEquals(2, conn.find(subject, RDFS.label, null, null, false).size()); assertEquals(1, conn.find(subject, RDFS.label, new LIT("type"), null, false).size()); }
@Override @SuppressWarnings("serial") public CloseableIterator<STMT> findStatements( @Nullable final ID subject, @Nullable final UID predicate, @Nullable final NODE object, @Nullable final UID model, boolean includeInferred) { SQLQuery query = this.context.createQuery(); query.from(statement); final List<Expression<?>> exprs = new ArrayList<Expression<?>>(); if (subject != null) { query.where(statement.subject.eq(getId(subject))); } else { query.innerJoin(statement.subjectFk, sub); exprs.add(sub.lexical); } if (predicate != null) { query.where(statement.predicate.eq(getId(predicate))); } else { exprs.add(statement.predicate); } if (object != null) { query.where(statement.object.eq(getId(object))); } else { query.innerJoin(statement.objectFk, obj); exprs.add(obj.resource); exprs.add(obj.lexical); exprs.add(obj.datatype); exprs.add(obj.lang); } if (model != null) { query.where(statement.model.eq(getId(model))); } else { exprs.add(statement.model); } if (subject == null && predicate == null && object == null && model == null) { query.orderBy(statement.model.asc()); query.orderBy(statement.subject.asc()); query.orderBy(statement.predicate.asc()); query.orderBy(statement.object.asc()); } if (exprs.isEmpty()) { exprs.add(NumberTemplate.ONE); } Expression<STMT> stmt = new FactoryExpression<STMT>() { @Override public STMT newInstance(Object... args) { ID s = subject; UID p = predicate; NODE o = object; UID m = model; int counter = 0; if (s == null) { s = getNode(true, (String) args[counter++], null, null).asResource(); } if (p == null) { p = getNode((Long) args[counter++]).asURI(); } if (o == null) { o = getNode((Boolean) args[counter++], (String) args[counter++], (Long) args[counter++], (Integer) args[counter++]); } if (m == null && args[counter] != null && !args[counter].equals(Long.valueOf(0l))) { m = getNode((Long) args[counter]).asURI(); if (m.equals(RDB.nullContext)) { m = null; } } return new STMT(s, p, o, m); } @Override public List<Expression<?>> getArgs() { return exprs; } @Override public <R, C> R accept(Visitor<R, C> v, C context) { return v.visit(this, context); } @Override public Class<? extends STMT> getType() { return STMT.class; } }; return query.iterate(stmt); }
RDBConnection implements RDFConnection { @Override @SuppressWarnings("serial") public CloseableIterator<STMT> findStatements( @Nullable final ID subject, @Nullable final UID predicate, @Nullable final NODE object, @Nullable final UID model, boolean includeInferred) { SQLQuery query = this.context.createQuery(); query.from(statement); final List<Expression<?>> exprs = new ArrayList<Expression<?>>(); if (subject != null) { query.where(statement.subject.eq(getId(subject))); } else { query.innerJoin(statement.subjectFk, sub); exprs.add(sub.lexical); } if (predicate != null) { query.where(statement.predicate.eq(getId(predicate))); } else { exprs.add(statement.predicate); } if (object != null) { query.where(statement.object.eq(getId(object))); } else { query.innerJoin(statement.objectFk, obj); exprs.add(obj.resource); exprs.add(obj.lexical); exprs.add(obj.datatype); exprs.add(obj.lang); } if (model != null) { query.where(statement.model.eq(getId(model))); } else { exprs.add(statement.model); } if (subject == null && predicate == null && object == null && model == null) { query.orderBy(statement.model.asc()); query.orderBy(statement.subject.asc()); query.orderBy(statement.predicate.asc()); query.orderBy(statement.object.asc()); } if (exprs.isEmpty()) { exprs.add(NumberTemplate.ONE); } Expression<STMT> stmt = new FactoryExpression<STMT>() { @Override public STMT newInstance(Object... args) { ID s = subject; UID p = predicate; NODE o = object; UID m = model; int counter = 0; if (s == null) { s = getNode(true, (String) args[counter++], null, null).asResource(); } if (p == null) { p = getNode((Long) args[counter++]).asURI(); } if (o == null) { o = getNode((Boolean) args[counter++], (String) args[counter++], (Long) args[counter++], (Integer) args[counter++]); } if (m == null && args[counter] != null && !args[counter].equals(Long.valueOf(0l))) { m = getNode((Long) args[counter]).asURI(); if (m.equals(RDB.nullContext)) { m = null; } } return new STMT(s, p, o, m); } @Override public List<Expression<?>> getArgs() { return exprs; } @Override public <R, C> R accept(Visitor<R, C> v, C context) { return v.visit(this, context); } @Override public Class<? extends STMT> getType() { return STMT.class; } }; return query.iterate(stmt); } }
RDBConnection implements RDFConnection { @Override @SuppressWarnings("serial") public CloseableIterator<STMT> findStatements( @Nullable final ID subject, @Nullable final UID predicate, @Nullable final NODE object, @Nullable final UID model, boolean includeInferred) { SQLQuery query = this.context.createQuery(); query.from(statement); final List<Expression<?>> exprs = new ArrayList<Expression<?>>(); if (subject != null) { query.where(statement.subject.eq(getId(subject))); } else { query.innerJoin(statement.subjectFk, sub); exprs.add(sub.lexical); } if (predicate != null) { query.where(statement.predicate.eq(getId(predicate))); } else { exprs.add(statement.predicate); } if (object != null) { query.where(statement.object.eq(getId(object))); } else { query.innerJoin(statement.objectFk, obj); exprs.add(obj.resource); exprs.add(obj.lexical); exprs.add(obj.datatype); exprs.add(obj.lang); } if (model != null) { query.where(statement.model.eq(getId(model))); } else { exprs.add(statement.model); } if (subject == null && predicate == null && object == null && model == null) { query.orderBy(statement.model.asc()); query.orderBy(statement.subject.asc()); query.orderBy(statement.predicate.asc()); query.orderBy(statement.object.asc()); } if (exprs.isEmpty()) { exprs.add(NumberTemplate.ONE); } Expression<STMT> stmt = new FactoryExpression<STMT>() { @Override public STMT newInstance(Object... args) { ID s = subject; UID p = predicate; NODE o = object; UID m = model; int counter = 0; if (s == null) { s = getNode(true, (String) args[counter++], null, null).asResource(); } if (p == null) { p = getNode((Long) args[counter++]).asURI(); } if (o == null) { o = getNode((Boolean) args[counter++], (String) args[counter++], (Long) args[counter++], (Integer) args[counter++]); } if (m == null && args[counter] != null && !args[counter].equals(Long.valueOf(0l))) { m = getNode((Long) args[counter]).asURI(); if (m.equals(RDB.nullContext)) { m = null; } } return new STMT(s, p, o, m); } @Override public List<Expression<?>> getArgs() { return exprs; } @Override public <R, C> R accept(Visitor<R, C> v, C context) { return v.visit(this, context); } @Override public Class<? extends STMT> getType() { return STMT.class; } }; return query.iterate(stmt); } RDBConnection(RDBContext context); }
RDBConnection implements RDFConnection { @Override @SuppressWarnings("serial") public CloseableIterator<STMT> findStatements( @Nullable final ID subject, @Nullable final UID predicate, @Nullable final NODE object, @Nullable final UID model, boolean includeInferred) { SQLQuery query = this.context.createQuery(); query.from(statement); final List<Expression<?>> exprs = new ArrayList<Expression<?>>(); if (subject != null) { query.where(statement.subject.eq(getId(subject))); } else { query.innerJoin(statement.subjectFk, sub); exprs.add(sub.lexical); } if (predicate != null) { query.where(statement.predicate.eq(getId(predicate))); } else { exprs.add(statement.predicate); } if (object != null) { query.where(statement.object.eq(getId(object))); } else { query.innerJoin(statement.objectFk, obj); exprs.add(obj.resource); exprs.add(obj.lexical); exprs.add(obj.datatype); exprs.add(obj.lang); } if (model != null) { query.where(statement.model.eq(getId(model))); } else { exprs.add(statement.model); } if (subject == null && predicate == null && object == null && model == null) { query.orderBy(statement.model.asc()); query.orderBy(statement.subject.asc()); query.orderBy(statement.predicate.asc()); query.orderBy(statement.object.asc()); } if (exprs.isEmpty()) { exprs.add(NumberTemplate.ONE); } Expression<STMT> stmt = new FactoryExpression<STMT>() { @Override public STMT newInstance(Object... args) { ID s = subject; UID p = predicate; NODE o = object; UID m = model; int counter = 0; if (s == null) { s = getNode(true, (String) args[counter++], null, null).asResource(); } if (p == null) { p = getNode((Long) args[counter++]).asURI(); } if (o == null) { o = getNode((Boolean) args[counter++], (String) args[counter++], (Long) args[counter++], (Integer) args[counter++]); } if (m == null && args[counter] != null && !args[counter].equals(Long.valueOf(0l))) { m = getNode((Long) args[counter]).asURI(); if (m.equals(RDB.nullContext)) { m = null; } } return new STMT(s, p, o, m); } @Override public List<Expression<?>> getArgs() { return exprs; } @Override public <R, C> R accept(Visitor<R, C> v, C context) { return v.visit(this, context); } @Override public Class<? extends STMT> getType() { return STMT.class; } }; return query.iterate(stmt); } RDBConnection(RDBContext context); void addLocales(Set<Locale> l, @Nullable BiMap<Locale, Integer> cache); void addNodes(Set<NODE> n, @Nullable BiMap<NODE, Long> cache); @Override RDFBeanTransaction beginTransaction(boolean readOnly, int txTimeout, int isolationLevel); @Override void clear(); @Override void close(); @Override BID createBNode(); @Override Q createUpdate(UpdateLanguage<D, Q> updateLanguage, D definition); @SuppressWarnings("unchecked") @Override Q createQuery(QueryLanguage<D, Q> queryLanguage, D definition); void deleteFromContext(UID model); List<STMT> find(
            @Nullable ID subject,
            @Nullable UID predicate,
            @Nullable NODE object,
            @Nullable UID model, boolean includeInferred); @Override @SuppressWarnings("serial") CloseableIterator<STMT> findStatements(
            @Nullable final ID subject,
            @Nullable final UID predicate,
            @Nullable final NODE object,
            @Nullable final UID model, boolean includeInferred); @Override boolean exists(ID subject, UID predicate, NODE object, UID context, boolean includeInferred); @Override long getNextLocalId(); @Override void remove(ID s, UID p, NODE o, UID c); @Override void update(Collection<STMT> removedStatements, Collection<STMT> addedStatements); @Override QueryOptions getQueryOptions(); @Override InferenceOptions getInferenceOptions(); }
RDBConnection implements RDFConnection { @Override @SuppressWarnings("serial") public CloseableIterator<STMT> findStatements( @Nullable final ID subject, @Nullable final UID predicate, @Nullable final NODE object, @Nullable final UID model, boolean includeInferred) { SQLQuery query = this.context.createQuery(); query.from(statement); final List<Expression<?>> exprs = new ArrayList<Expression<?>>(); if (subject != null) { query.where(statement.subject.eq(getId(subject))); } else { query.innerJoin(statement.subjectFk, sub); exprs.add(sub.lexical); } if (predicate != null) { query.where(statement.predicate.eq(getId(predicate))); } else { exprs.add(statement.predicate); } if (object != null) { query.where(statement.object.eq(getId(object))); } else { query.innerJoin(statement.objectFk, obj); exprs.add(obj.resource); exprs.add(obj.lexical); exprs.add(obj.datatype); exprs.add(obj.lang); } if (model != null) { query.where(statement.model.eq(getId(model))); } else { exprs.add(statement.model); } if (subject == null && predicate == null && object == null && model == null) { query.orderBy(statement.model.asc()); query.orderBy(statement.subject.asc()); query.orderBy(statement.predicate.asc()); query.orderBy(statement.object.asc()); } if (exprs.isEmpty()) { exprs.add(NumberTemplate.ONE); } Expression<STMT> stmt = new FactoryExpression<STMT>() { @Override public STMT newInstance(Object... args) { ID s = subject; UID p = predicate; NODE o = object; UID m = model; int counter = 0; if (s == null) { s = getNode(true, (String) args[counter++], null, null).asResource(); } if (p == null) { p = getNode((Long) args[counter++]).asURI(); } if (o == null) { o = getNode((Boolean) args[counter++], (String) args[counter++], (Long) args[counter++], (Integer) args[counter++]); } if (m == null && args[counter] != null && !args[counter].equals(Long.valueOf(0l))) { m = getNode((Long) args[counter]).asURI(); if (m.equals(RDB.nullContext)) { m = null; } } return new STMT(s, p, o, m); } @Override public List<Expression<?>> getArgs() { return exprs; } @Override public <R, C> R accept(Visitor<R, C> v, C context) { return v.visit(this, context); } @Override public Class<? extends STMT> getType() { return STMT.class; } }; return query.iterate(stmt); } RDBConnection(RDBContext context); void addLocales(Set<Locale> l, @Nullable BiMap<Locale, Integer> cache); void addNodes(Set<NODE> n, @Nullable BiMap<NODE, Long> cache); @Override RDFBeanTransaction beginTransaction(boolean readOnly, int txTimeout, int isolationLevel); @Override void clear(); @Override void close(); @Override BID createBNode(); @Override Q createUpdate(UpdateLanguage<D, Q> updateLanguage, D definition); @SuppressWarnings("unchecked") @Override Q createQuery(QueryLanguage<D, Q> queryLanguage, D definition); void deleteFromContext(UID model); List<STMT> find(
            @Nullable ID subject,
            @Nullable UID predicate,
            @Nullable NODE object,
            @Nullable UID model, boolean includeInferred); @Override @SuppressWarnings("serial") CloseableIterator<STMT> findStatements(
            @Nullable final ID subject,
            @Nullable final UID predicate,
            @Nullable final NODE object,
            @Nullable final UID model, boolean includeInferred); @Override boolean exists(ID subject, UID predicate, NODE object, UID context, boolean includeInferred); @Override long getNextLocalId(); @Override void remove(ID s, UID p, NODE o, UID c); @Override void update(Collection<STMT> removedStatements, Collection<STMT> addedStatements); @Override QueryOptions getQueryOptions(); @Override InferenceOptions getInferenceOptions(); static final QSymbol con; static final QSymbol obj; static final QSymbol pre; static final QSymbol sub; }