org.openrdf.model.ValueFactory Java Examples

The following examples show how to use org.openrdf.model.ValueFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestGPO.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks for reverse linkset referential integrity when property replaced
 */
public void testLinkSetConsistency2() {
	doLoadData();
	
	final ValueFactory vf = om.getValueFactory();

    final URI workeruri = vf.createURI("gpo:#123");
    IGPO workergpo = om.getGPO(workeruri);
    final URI worksFor = vf.createURI("attr:/employee#worksFor");
    final ILinkSet ls = workergpo.getLinksOut(worksFor);
    
    assertTrue(ls.size() > 0);
    
    final IGPO employer = ls.iterator().next();
    
    final ILinkSet employees = employer.getLinksIn(worksFor);
    assertTrue(employees.contains(workergpo));
    
    // set property to new URI
    final URI newuri = vf.createURI("gpo:#999");
    workergpo.setValue(worksFor, newuri);
    
    assertFalse(employees.contains(workergpo));
    assertTrue(om.getGPO(newuri).getLinksIn(worksFor).contains(workergpo));
}
 
Example #2
Source File: SmokeTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public void testCreateDocument() throws Exception {
	// create a Document
	Document doc = new Document();
	doc.setTitle("Getting Started");

	// add a Document to the repository
	ValueFactory vf = con.getValueFactory();
	URI id = vf
			.createURI("http://meta.leighnet.ca/data/2009/getting-started");
	con.addObject(id, doc);

	// retrieve a Document by id
	doc = con.getObject(Document.class, id);
	assertEquals("Getting Started", doc.getTitle());

}
 
Example #3
Source File: FieldPredicateTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public void testReadAccess() throws Exception {
	ValueFactory vf = con.getValueFactory();
	URI graph = vf.createURI("urn:test:graph");
	con.setAddContexts(graph);
	Company c = new Company();
	c = (Company) con.getObject(con.addObject(c));
	c.setName("My Company");
	assertEquals("My Company", c.getName());
	TupleQuery query = con.prepareTupleQuery("SELECT ?g WHERE {GRAPH ?g {?o <urn:test:name> ?name}}");
	query.setBinding("name", vf.createLiteral("My Company"));
	TupleQueryResult results = query.evaluate();
	Value g = results.next().getValue("g");
	results.close();
	assertEquals(graph, g);
	con.setAddContexts();
	assertEquals("My Company", c.getName());
	query = con.prepareTupleQuery("SELECT ?g WHERE {GRAPH ?g {?o <urn:test:name> ?name}}");
	query.setBinding("name", vf.createLiteral("My Company"));
	results = query.evaluate();
	g = results.next().getValue("g");
	results.close();
	assertEquals(graph, g);
}
 
Example #4
Source File: SesameTransformationInjectPosLength.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void activate(final Collection<SesamePosLengthInjectMatch> matches) throws RepositoryException {
	final RepositoryConnection con = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI typeURI = vf.createURI(BASE_PREFIX + ModelConstants.LENGTH);
	final Literal zeroLiteral = vf.createLiteral(0);

	for (final SesamePosLengthInjectMatch match : matches) {
		final URI segment = match.getSegment();

		final RepositoryResult<Statement> statementsToRemove = con.getStatements(segment, typeURI, null, true);
		con.remove(statementsToRemove);

		con.add(segment, typeURI, zeroLiteral);
	}
}
 
Example #5
Source File: TestTicket4249.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private void executeQuery(final RepositoryConnection conn, final Literal string, final int start, final int length, final Literal expected)
		throws RepositoryException, MalformedQueryException, QueryEvaluationException {
	final ValueFactory vf = conn.getValueFactory();
	final String query = "select ?substring WHERE { BIND ( SUBSTR(?string, ?start, ?length) as ?substring ) . }";
	final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
	q.setBinding("string", string);
	q.setBinding("start", vf.createLiteral(start));
	q.setBinding("length", vf.createLiteral(length));
	final TupleQueryResult tqr = q.evaluate();
	try {
		while (tqr.hasNext()) {
			final BindingSet bindings = tqr.next();
			// assert expected value
			assertEquals(expected, bindings.getBinding("substring").getValue());
		}
	} finally {
		tqr.close();
	}
}
 
Example #6
Source File: TestTicket632.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private void executeQuery(final URI serviceUri, final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException {
    try {
        repo.initialize();
        final RepositoryConnection conn = repo.getConnection();
        final ValueFactory vf = conn.getValueFactory();
        conn.setAutoCommit(false);
        try {
            final String query = "SELECT ?x { SERVICE <" + serviceUri.stringValue() + "> { ?x <u:1> ?bool1 } }";
            final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
            q.setBinding("bool1", vf.createLiteral(true));
            final TupleQueryResult tqr = q.evaluate();
            try {
                tqr.hasNext();
            } finally {
                tqr.close();
            }
        } finally {
            conn.close();
        }
    } finally {
        repo.shutDown();
    }
}
 
Example #7
Source File: TestNoExceptions.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private void executeQuery(final SailRepository repo, final String query)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, IOException,
		RDFHandlerException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		conn.setAutoCommit(false);
		try {
			final ValueFactory vf = conn.getValueFactory();
			conn.commit();
			TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
			TupleQueryResult tqr = tq.evaluate();
			tqr.close();
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}
 
Example #8
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
public Iterable<Statement> serialize( final EntityDescriptor entityDescriptor )
{
    Graph graph = new GraphImpl();
    ValueFactory values = graph.getValueFactory();
    URI entityTypeUri = values.createURI( Classes.toURI( entityDescriptor.types().findFirst().orElse( null ) ) );

    graph.add( entityTypeUri, Rdfs.TYPE, Rdfs.CLASS );
    graph.add( entityTypeUri, Rdfs.TYPE, OWL.CLASS );

    graph.add( entityTypeUri,
               PolygeneEntityType.TYPE,
               values.createLiteral( entityDescriptor.types().findFirst().get().toString() )
    );
    graph.add( entityTypeUri, PolygeneEntityType.QUERYABLE, values.createLiteral( entityDescriptor.queryable() ) );

    serializeMixinTypes( entityDescriptor, graph, entityTypeUri );

    serializePropertyTypes( entityDescriptor, graph, entityTypeUri );
    serializeAssociationTypes( entityDescriptor, graph, entityTypeUri );
    serializeManyAssociationTypes( entityDescriptor, graph, entityTypeUri );

    return graph;
}
 
Example #9
Source File: DavidsTestBOps.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void testExplicitDefaultAndNamedGraphNoGraphKeyword ()
    throws Exception
{
    final BigdataSail sail = getTheSail () ;
    final ValueFactory vf = sail.getValueFactory();
    final RepositoryConnection cxn = getRepositoryConnection ( sail ) ;
    try {
    String ns = "http://xyz.com/test#" ;
    String kb = String.format ( "<%ss> <%sp> <%so> .", ns, ns, ns ) ;
    String qs = String.format ( "select ?s from <%sg1> from named <%sg2> where { ?s ?p ?o .}", ns, ns ) ;

    Resource graphs [] = new Resource [] { vf.createURI ( String.format ( "%sg1", ns ) ), vf.createURI ( String.format ( "%sg2", ns ) ) } ;

    Collection<BindingSet> expected = getExpected ( createBindingSet ( new BindingImpl ( "s", new URIImpl ( String.format ( "%ss", ns ) ) ) ) ) ;

    run ( sail, cxn, kb, graphs, qs, expected ) ;
    } finally {
        cxn.close();
    }
}
 
Example #10
Source File: GraphHandler.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * Delete data from the graph.
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param response the HttpServletResponse object
 * @return the EmptySuccessView if successes
 * @throws ClientHTTPException throws when there are errors in getting the name of the Graph
 * @throws ServerHTTPException throws when errors happens update the data
 */
private ModelAndView getDeleteDataResult(final Repository repository,
		final HttpServletRequest request, final HttpServletResponse response)
		throws ClientHTTPException, ServerHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	URI graph = getGraphName(request, vf);

	try {
		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			repositoryCon.clear(graph);
		}
		repositoryCon.close();
		return new ModelAndView(EmptySuccessView.getInstance());
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
	}
}
 
Example #11
Source File: SparqlParameters.java    From anno4j with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #12
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
private void serializeAssociationTypes( final EntityDescriptor entityDescriptor,
                                        final Graph graph,
                                        final URI entityTypeUri
)
{
    ValueFactory values = graph.getValueFactory();
    // Associations
    entityDescriptor.state().associations().forEach( associationType -> {
        URI associationURI = values.createURI( associationType.qualifiedName().toURI() );
        graph.add( associationURI, Rdfs.DOMAIN, entityTypeUri );
        graph.add( associationURI, Rdfs.TYPE, Rdfs.PROPERTY );

        URI associatedURI = values.createURI( Classes.toURI( Classes.RAW_CLASS.apply( associationType.type() ) ) );
        graph.add( associationURI, Rdfs.RANGE, associatedURI );
        graph.add( associationURI, Rdfs.RANGE, XMLSchema.ANYURI );
    } );
}
 
Example #13
Source File: TestGPO.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void testLinkSetsIn() {
	doLoadData();
	
	final ValueFactory vf = om.getValueFactory();

    final URI clssuri = vf.createURI("gpo:#1");
    IGPO clssgpo = om.getGPO(clssuri);
	
    final URI linkURI = vf.createURI("attr:/type");
    ILinkSet ls = clssgpo.getLinksIn(linkURI);
    
    assertTrue(ls.getOwner() == clssgpo);
    assertTrue(ls.isLinkSetIn());
    assertTrue(ls.getLinkProperty().equals(linkURI));
    
    checkLinkSet(ls, 2);
}
 
Example #14
Source File: TestTicket4249.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private void executeQuery(final RepositoryConnection conn, final Literal string, final int start, final Literal expected)
		throws RepositoryException, MalformedQueryException, QueryEvaluationException {
	final ValueFactory vf = conn.getValueFactory();
	final String query = "select ?substring WHERE { BIND ( SUBSTR(?string, ?start) as ?substring ) . }";
	final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
	q.setBinding("string", string);
	q.setBinding("start", vf.createLiteral(start));
	final TupleQueryResult tqr = q.evaluate();
	try {
		while (tqr.hasNext()) {
			final BindingSet bindings = tqr.next();
			// assert expected value
			assertEquals(expected, bindings.getBinding("substring").getValue());
		}
	} finally {
		tqr.close();
	}
}
 
Example #15
Source File: BlazeValueFactory.java    From tinkerpop3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a datatyped literal from a blueprints property value.
 * <p>
 * Supports: Float, Double, Integer, Long, Boolean, Short, Byte, and String.
 */
default Literal toLiteral(final Object value) {

    final ValueFactory vf = Defaults.VF;
    
    if (value instanceof Float) {
        return vf.createLiteral((Float) value);
    } else if (value instanceof Double) {
        return vf.createLiteral((Double) value);
    } else if (value instanceof Integer) {
        return vf.createLiteral((Integer) value);
    } else if (value instanceof Long) {
        return vf.createLiteral((Long) value);
    } else if (value instanceof Boolean) {
        return vf.createLiteral((Boolean) value);
    } else if (value instanceof Short) {
        return vf.createLiteral((Short) value);
    } else if (value instanceof Byte) {
        return vf.createLiteral((Byte) value);
    } else if (value instanceof String) { 
        return vf.createLiteral((String) value);
    } else {
        throw new IllegalArgumentException(String.format("not supported: %s", value));
    }
    
}
 
Example #16
Source File: WriteStatementsKnowledgeStore.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static public org.openrdf.model.Statement castJenaOpenRdf(com.hp.hpl.jena.rdf.model.Statement jenaStatement, String modelName) {
    org.openrdf.model.Statement statement = null;
    try {
        ValueFactory valueFactory = ValueFactoryImpl.getInstance();
        URI modelURI = valueFactory.createURI(modelName);
        URI subject = valueFactory.createURI(jenaStatement.getSubject().getURI());
        URI sem = valueFactory.createURI(jenaStatement.getPredicate().getURI());
        if (jenaStatement.getObject().isLiteral()) {
            Literal objectLiteral = valueFactory.createLiteral(jenaStatement.getObject().toString());
             statement = valueFactory.createStatement(subject, sem, objectLiteral, modelURI);
        }

        else {
            URI objectUri = valueFactory.createURI(jenaStatement.getObject().asResource().getURI());
             statement = valueFactory.createStatement(subject, sem, objectUri, modelURI);
        }
    } catch (Exception e) {
        System.out.println("jenaStatement.toString() = " + jenaStatement.toString());
        e.printStackTrace();
    }
    return statement;
}
 
Example #17
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
private void serializePropertyTypes( final EntityDescriptor entityDescriptor,
                                     final Graph graph,
                                     final URI entityTypeUri
)
{
    ValueFactory values = graph.getValueFactory();

    // Properties
    entityDescriptor.state().properties().forEach( persistentProperty -> {
        URI propertyURI = values.createURI( persistentProperty.qualifiedName().toURI() );
        graph.add( propertyURI, Rdfs.DOMAIN, entityTypeUri );
        graph.add( propertyURI, Rdfs.TYPE, Rdfs.PROPERTY );

        // TODO Support more types
        URI type = dataTypes.get( persistentProperty.valueType().primaryType().getName() );
        if( type != null )
        {
            graph.add( propertyURI, Rdfs.RANGE, type );
        }
    } );
}
 
Example #18
Source File: TestGOM.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Simple test loads data from a file and navigates around
 */
public void testSimpleDirectData() throws IOException, RDFParseException, RepositoryException {

       final URL n3 = TestGOM.class.getResource("testgom.n3");

       // print(n3);
	((IGOMProxy) m_delegate).load(n3, RDFFormat.N3);

       final ValueFactory vf = om.getValueFactory();

       final URI s = vf.createURI("gpo:#root");

       final URI rootAttr = vf.createURI("attr:/root");
       om.getGPO(s).getValue(rootAttr);
       final URI rootId = (URI) om.getGPO(s).getValue(rootAttr);

       final IGPO rootGPO = om.getGPO(rootId);

       if (log.isInfoEnabled()) {
           log.info("--------\n" + rootGPO.pp() + "\n"
                   + rootGPO.getType().pp() + "\n"
                   + rootGPO.getType().getStatements());
       }

       final URI typeName = vf.createURI("attr:/type#name");

       assertTrue("Company".equals(rootGPO.getType().getValue(typeName)
               .stringValue()));

       // find set of workers for the Company
       final URI worksFor = vf.createURI("attr:/employee#worksFor");
       final ILinkSet linksIn = rootGPO.getLinksIn(worksFor);
       final Iterator<IGPO> workers = linksIn.iterator();
       while (workers.hasNext()) {
           final IGPO tmp = workers.next();
           if (log.isInfoEnabled())
               log.info("Returned: " + tmp.pp());
       }

   }
 
Example #19
Source File: AugurTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	config.addConcept(Bean.class);
	super.setUp();
	con.setNamespace("test", NS);
	ValueFactory vf = con.getValueFactory();
	con.setAutoCommit(false);
	URI urn_root = vf.createURI(NS, "root");
	Bean root = con.addDesignation(con.getObjectFactory().createObject(urn_root), Bean.class);
	for (int i = 0; i < 100; i++) {
		URI uri = vf.createURI(NS, String.valueOf(i));
		Bean bean = con.addDesignation(con.getObjectFactory().createObject(uri), Bean.class);
		bean.setName("name" + i);
		bean.getNicks().add("nicka" + i);
		bean.getNicks().add("nickb" + i);
		bean.getNicks().add("nickc" + i);
		URI p = vf.createURI(NS, String.valueOf(i + 1000));
		Bean parent = con.addDesignation(con.getObjectFactory().createObject(p), Bean.class);
		parent.setName("name" + String.valueOf(i + 1000));
		bean.setParent(parent);
		for (int j = i - 10; j < i; j++) {
			if (j > 0) {
				URI f = vf.createURI(NS, String.valueOf(j + 1000));
				Bean friend = con.addDesignation(con.getObjectFactory().createObject(f), Bean.class);
				friend.setName("name" + String.valueOf(j + 1000));
				bean.getFriends().add(friend);
			}
		}
		root.getFriends().add(bean);
	}
	con.setAutoCommit(true);
}
 
Example #20
Source File: TestTicket967.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void executeTest(final SailRepository repo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, RDFHandlerException,
		IOException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		try {
			conn.setAutoCommit(false);
			final ValueFactory vf = conn.getValueFactory();
	        final URI uri = vf.createURI("os:/elem/example");
	        // run a query which looks for a statement and then adds it if it is not found.
	        addDuringQueryExec(conn, uri, RDF.TYPE, vf.createURI("os:class/Clazz"));
	        // now try to export the statements.
        	final RepositoryResult<Statement> stats = conn.getStatements(null, null, null, false);
	        try {
	        	// materialize the newly added statement.
	        	stats.next();
	        } catch (RuntimeException e) {
	        	fail(e.getLocalizedMessage(), e); // With Bigdata this fails
	        } finally {
	        	stats.close();
	        }
	        conn.rollback(); // discard the result (or commit, but do something to avoid a logged warning from Sesame).
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}
 
Example #21
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private void serializeMixinTypes( final EntityDescriptor entityDescriptor,
                                  final Graph graph,
                                  final URI entityTypeUri
)
{
    ValueFactory values = graph.getValueFactory();

    entityDescriptor.mixinTypes().forEach( mixinType -> {
        graph.add( entityTypeUri, Rdfs.SUB_CLASS_OF, values.createURI( Classes.toURI( mixinType ) ) );
    } );
}
 
Example #22
Source File: ObjectRepositoryFactory.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private LiteralManager getLiteralManager(ClassLoader cl, ValueFactory vf,
		ObjectRepositoryConfig module) {
	LiteralManager literalManager = createLiteralManager(vf, vf);
	literalManager.setClassLoader(cl);
	for (Map.Entry<Class<?>, List<URI>> e : module.getDatatypes().entrySet()) {
		for (URI value : e.getValue()) {
			literalManager.addDatatype(e.getKey(), value);
		}
	}
	return literalManager;
}
 
Example #23
Source File: ObjectRepositoryFactory.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private ObjectRepository getRepository(ObjectRepositoryConfig config,
		ValueFactory vf) throws ObjectStoreConfigException {
	ObjectRepository repo = getObjectRepository(config, vf);

	repo.setIncludeInferred(config.isIncludeInferred());
	repo.setMaxQueryTime(config.getMaxQueryTime());
	repo.setQueryLanguage(config.getQueryLanguage());
	repo.setReadContexts(config.getReadContexts());
	repo.setAddContexts(config.getAddContexts());
	repo.setInsertContext(config.getInsertContext());
	repo.setRemoveContexts(config.getRemoveContexts());
	repo.setArchiveContexts(config.getArchiveContexts());
	// repo.setQueryResultLimit(config.getQueryResultLimit());
	return repo;
}
 
Example #24
Source File: OwlNormalizer.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private void hasValueFromList() {
	ValueFactory vf = getValueFactory();
	for (Statement st : ds.match(null, OWL.HASVALUE, null)) {
		Resource res = st.getSubject();
		Value obj = st.getObject();
		if (obj instanceof Resource) {
			BNode node = vf.createBNode();
			ds.add(res, OWL.ALLVALUESFROM, node);
			ds.add(node, RDF.TYPE, OWL.CLASS);
			BNode list = vf.createBNode();
			ds.add(node, OWL.ONEOF, list);
			ds.add(list, RDF.TYPE, RDF.LIST);
			ds.add(list, RDF.FIRST, obj);
			ds.add(list, RDF.REST, RDF.NIL);
			for (Value type : ds.match(obj, RDF.TYPE, null).objects()) {
				ds.add(node, RDFS.SUBCLASSOF, type);
			}
			for (Value prop : ds.match(res, OWL.ONPROPERTY, null).objects()) {
				for (Value range : ds.match(prop, RDFS.RANGE, null).objects()) {
					ds.add(node, RDFS.SUBCLASSOF, range);
				}
				for (Resource cls : ds.match(null, RDFS.SUBCLASSOF, res).subjects()) {
					for (Value sup : findSuperClasses(cls)) {
						if (!sup.equals(res) && !ds.match(sup, OWL.ONPROPERTY, prop).isEmpty()) {
							for (Value from : ds.match(sup, OWL.ALLVALUESFROM, null).objects()) {
								ds.add(node, RDFS.SUBCLASSOF, from);
							}
						}
					}
				}
			}
		}
	}
}
 
Example #25
Source File: InterceptTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testCatchIllegalArgument() throws Exception {
	IConcept concept = con.addDesignation(
			con.getObject("urn:test:concept"), IConcept.class);
	ValueFactory vf = con.getValueFactory();
	Resource subj = concept.getResource();
	URI pred = vf.createURI("urn:test:time");
	Literal lit = vf.createLiteral("noon", XMLSchema.DATETIME);
	con.add(subj, pred, lit);
	XMLGregorianCalendar zero = DatatypeFactory.newInstance().newXMLGregorianCalendar();
	assertEquals(zero, concept.getTime());
}
 
Example #26
Source File: BigdataSail.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
     * A {@link BigdataValueFactory}
     * <p>
     * {@inheritDoc}
     */
    @Override // FIXME BLZG-2041 LexiconRelation constructor no longer overrides the value factory implementation class on this code path!
    final public ValueFactory getValueFactory() {
        
        return valueFactory;
//        return database.getValueFactory();
        
    }
 
Example #27
Source File: EntityStateSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private void serializeProperty( PropertyDescriptor persistentProperty, Object property,
                                Resource subject, Graph graph,
                                boolean includeNonQueryable )
{
    if( !( includeNonQueryable || persistentProperty.queryable() ) )
    {
        return; // Skip non-queryable
    }

    ValueType valueType = persistentProperty.valueType();

    final ValueFactory valueFactory = graph.getValueFactory();

    String propertyURI = persistentProperty.qualifiedName().toURI();
    URI predicate = valueFactory.createURI( propertyURI );
    String baseURI = propertyURI.substring( 0, propertyURI.indexOf( '#' ) ) + "/";

    if( valueType instanceof ValueCompositeType )
    {
        serializeValueComposite( subject, predicate, (ValueComposite) property, valueType,
                                 graph, baseURI, includeNonQueryable );
    }
    else
    {
        String stringProperty = serializer.serialize( Serializer.Options.NO_TYPE_INFO, property );
        final Literal object = valueFactory.createLiteral( stringProperty );
        graph.add( subject, predicate, object );
    }
}
 
Example #28
Source File: EntityStateSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private void serializeAssociations( final EntityState entityState,
                                    final Graph graph, URI entityUri,
                                    final Stream<? extends AssociationDescriptor> associations,
                                    final boolean includeNonQueryable
)
{
    ValueFactory values = graph.getValueFactory();

    // Associations
    associations.filter( type -> includeNonQueryable || type.queryable() ).forEach(
        associationType ->
        {
            EntityReference associatedId
                = entityState
                .associationValueOf(
                    associationType
                        .qualifiedName() );
            if( associatedId != null )
            {
                URI assocURI = values
                    .createURI(
                        associationType
                            .qualifiedName()
                            .toURI() );
                URI assocEntityURI
                    = values.createURI(
                    associatedId
                        .toURI() );
                graph.add( entityUri,
                           assocURI,
                           assocEntityURI );
            }
        } );
}
 
Example #29
Source File: TestTicket348.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void executeTest(final SailRepository repo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException, RDFParseException, RDFHandlerException,
		IOException {
	try {
		repo.initialize();
		final RepositoryConnection conn = repo.getConnection();
		try {
			conn.setAutoCommit(false);
			final ValueFactory vf = conn.getValueFactory();
	        final URI uri = vf.createURI("os:/elem/example");
	        // run a query which looks for a statement and then adds it if it is not found.
	        addDuringQueryExec(conn, uri, RDF.TYPE, vf.createURI("os:class/Clazz"));
	        // now try to export the statements.
        	final RepositoryResult<Statement> stats = conn.getStatements(null, null, null, false);
	        try {
	        	// materialize the newly added statement.
	        	stats.next();
	        } catch (RuntimeException e) {
	        	fail(e.getLocalizedMessage(), e); // With Bigdata this fails
	        } finally {
	        	stats.close();
	        }
	        conn.rollback(); // discard the result (or commit, but do something to avoid a logged warning from Sesame).
		} finally {
			conn.close();
		}
	} finally {
		repo.shutDown();
	}
}
 
Example #30
Source File: NamedQueryTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testSetOfURI() throws Exception {
	Set<URI> set = me.findFriendURIs();
	assertEquals(3, set.size());
	ValueFactory vf = con.getValueFactory();
	assertTrue(set.contains(vf.createURI(NS + "me")));
	assertTrue(set.contains(vf.createURI(NS + "john")));
}