Search in sources :

Example 16 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class T_TDBWriteTransaction method run.

public static void run(String location) {
    if (false) {
        Journal journal = Journal.create(Location.create(location));
        JournalControl.print(journal);
        journal.close();
    }
    //String location = args[0]; // + "/" + UUID.randomUUID().toString();
    //String baseGraphName = "com.ibm.test.graphNamePrefix.";   
    long totalExecTime = 0L;
    long size = 0;
    Dataset dataset = TDBFactory.createDataset(location);
    Dataset dataset1 = TDBFactory.createDataset(location);
    if (bracketWithReader)
        dataset1.begin(ReadWrite.READ);
    for (int i = 0; i < TOTAL; i++) {
        List<String> lastProcessedUris = new ArrayList<>();
        for (int j = 0; j < 10 * i; j++) {
            String lastProcessedUri = "http://test.net/xmlns/test/1.0/someUri" + j;
            lastProcessedUris.add(lastProcessedUri);
        }
        //Dataset dataset = TDBFactory.createDataset(location);
        //String graphName = baseGraphName + i;
        long t = System.currentTimeMillis();
        try {
            dataset.begin(ReadWrite.WRITE);
            Model m = dataset.getDefaultModel();
            m.removeAll();
            Resource subject = m.createResource(INDEX_INFO_SUBJECT);
            Property predicate = m.createProperty(TIMESTAMP_PREDICATE);
            m.addLiteral(subject, predicate, System.currentTimeMillis());
            predicate = m.createProperty(URI_PREDICATE);
            for (String uri : lastProcessedUris) {
                m.add(subject, predicate, m.createResource(uri));
            }
            predicate = m.createProperty(VERSION_PREDICATE);
            m.addLiteral(subject, predicate, 1.0);
            size += m.size() + 1;
            predicate = m.createProperty(INDEX_SIZE_PREDICATE);
            m.addLiteral(subject, predicate, size);
            dataset.commit();
        } catch (Throwable e) {
            dataset.abort();
            throw new RuntimeException(e);
        } finally {
            dataset.end();
            long writeOperationDuration = System.currentTimeMillis() - t;
            totalExecTime += writeOperationDuration;
            System.out.println("Write operation " + i + " took " + writeOperationDuration + "ms");
        }
    }
    if (bracketWithReader)
        dataset1.end();
    System.out.println("All " + TOTAL + " write operations wrote " + size + " triples and took " + totalExecTime + "ms");
}
Also used : Dataset(org.apache.jena.query.Dataset) ArrayList(java.util.ArrayList) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Journal(org.apache.jena.tdb.transaction.Journal) Property(org.apache.jena.rdf.model.Property)

Example 17 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class InMemDatasetAssembler method open.

@Override
public Dataset open(final Assembler assembler, final Resource root, final Mode mode) {
    checkType(root, DatasetAssemblerVocab.tDatasetTxnMem);
    final Dataset dataset = createTxnMem();
    setContext(root, dataset.getContext());
    dataset.begin(WRITE);
    // load data into the default graph
    if (root.hasProperty(data)) {
        multiValueResource(root, data).forEach(defaultGraphDocument -> read(dataset, defaultGraphDocument.getURI()));
    }
    // load data into named graphs
    multiValueResource(root, pNamedGraph).forEach(namedGraphResource -> {
        final String graphName = getAsStringValue(namedGraphResource, pGraphName);
        if (namedGraphResource.hasProperty(data)) {
            multiValueResource(namedGraphResource, data).forEach(namedGraphData -> read(dataset.getNamedModel(graphName), namedGraphData.getURI()));
        }
    });
    dataset.commit();
    dataset.end();
    return dataset;
}
Also used : Dataset(org.apache.jena.query.Dataset)

Example 18 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractTestTransactionLifecycle method testCommitCommit.

private void testCommitCommit(ReadWrite mode) {
    Dataset ds = create();
    ds.begin(mode);
    ds.commit();
    try {
        ds.commit();
        fail("Expected transaction exception - commit-commit(" + mode + ")");
    } catch (JenaTransactionException ex) {
        safeEnd(ds);
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 19 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractTestTransactionLifecycle method testAbortCommit.

private void testAbortCommit(ReadWrite mode) {
    assumeTrue(supportsAbort());
    Dataset ds = create();
    ds.begin(mode);
    ds.abort();
    try {
        ds.commit();
        fail("Expected transaction exception - abort-commit(" + mode + ")");
    } catch (JenaTransactionException ex) {
        safeEnd(ds);
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 20 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractWholeFileQuadInputFormatTests method writeGoodTuples.

private void writeGoodTuples(OutputStream output, int num) {
    Dataset ds = DatasetFactory.createGeneral();
    Model m = ModelFactory.createDefaultModel();
    Resource currSubj = m.createResource("http://example.org/subjects/0");
    Property predicate = m.createProperty("http://example.org/predicate");
    for (int i = 0; i < num; i++) {
        if (i % 100 == 0) {
            ds.addNamedModel("http://example.org/graphs/" + (i / 100), m);
            m = ModelFactory.createDefaultModel();
        }
        if (i % 10 == 0) {
            currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
        }
        m.add(currSubj, predicate, m.createTypedLiteral(i));
    }
    if (!m.isEmpty()) {
        ds.addNamedModel("http://example.org/graphs/extra", m);
    }
    this.writeTuples(ds, output);
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Aggregations

Dataset (org.apache.jena.query.Dataset)725 Test (org.junit.Test)401 Model (org.apache.jena.rdf.model.Model)173 Ignore (org.junit.Ignore)93 URI (java.net.URI)80 Resource (org.apache.jena.rdf.model.Resource)70 QueryExecution (org.apache.jena.query.QueryExecution)53 ArrayList (java.util.ArrayList)46 QuerySolution (org.apache.jena.query.QuerySolution)46 ResultSet (org.apache.jena.query.ResultSet)45 WonNodeInformationService (won.protocol.service.WonNodeInformationService)28 Statement (org.apache.jena.rdf.model.Statement)26 Node (org.apache.jena.graph.Node)23 InputStream (java.io.InputStream)22 RDFNode (org.apache.jena.rdf.model.RDFNode)21 RdfUtils (won.protocol.util.RdfUtils)19 WonMessage (won.protocol.message.WonMessage)17 Literal (org.apache.jena.rdf.model.Literal)16 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16