Search in sources :

Example 11 with StoreDesc

use of org.apache.jena.sdb.StoreDesc in project jena by apache.

the class SDBModelAssembler method open.

@Override
public Model open(Assembler a, Resource root, Mode mode) {
    // Make a model.
    // [] rdf:type sdb:Model ;
    //    sdb:dataset <dataset> ;
    //    sdb:graphName <someURI> .
    // A model (graph) is a (dataset, name) pair where the name can be absent
    // meaning the default graph of the dataset.
    Resource dataset = GraphUtils.getResourceValue(root, AssemblerVocab.pDataset);
    if (dataset == null)
        throw new MissingException(root, "No dataset for model or graph");
    StoreDesc storeDesc = datasetAssem.openStore(a, dataset, mode);
    // Attempt to find a graph name - may be absent.
    // Two names : "namedGraph" and "graphName"
    String x = GraphUtils.getAsStringValue(root, AssemblerVocab.pNamedGraph1);
    if (x == null)
        x = GraphUtils.getAsStringValue(root, AssemblerVocab.pNamedGraph2);
    // No name - default model.
    Graph g = null;
    if (x == null)
        return SDBFactory.connectDefaultModel(storeDesc);
    else
        return SDBFactory.connectNamedModel(storeDesc, x);
}
Also used : Graph(org.apache.jena.graph.Graph) StoreDesc(org.apache.jena.sdb.StoreDesc) Resource(org.apache.jena.rdf.model.Resource)

Example 12 with StoreDesc

use of org.apache.jena.sdb.StoreDesc in project jena by apache.

the class StoreDescAssembler method open.

@Override
public StoreDesc open(Assembler a, Resource root, Mode mode) {
    SDBConnectionDesc sdbConnDesc = null;
    Resource c = GraphUtils.getResourceValue(root, AssemblerVocab.pConnection);
    if (c != null)
        sdbConnDesc = (SDBConnectionDesc) a.open(c);
    String layoutName = GraphUtils.getStringValue(root, AssemblerVocab.pLayout);
    String dbType = chooseDBType(root, sdbConnDesc);
    // Features
    List<Resource> x = GraphUtils.multiValueResource(root, AssemblerVocab.featureProperty);
    FeatureSet fSet = new FeatureSet();
    for (Resource r : x) {
        String n = GraphUtils.getStringValue(r, AssemblerVocab.featureNameProperty);
        String v = GraphUtils.getStringValue(r, AssemblerVocab.featureValueProperty);
        Feature f = new Feature(new Feature.Name(n), v);
        fSet.addFeature(f);
    }
    StoreDesc storeDesc = new StoreDesc(layoutName, dbType, fSet);
    storeDesc.connDesc = sdbConnDesc;
    // MySQL specials
    String engineName = GraphUtils.getStringValue(root, AssemblerVocab.pMySQLEngine);
    storeDesc.engineType = null;
    if (engineName != null)
        try {
            storeDesc.engineType = MySQLEngineType.convert(engineName);
        } catch (SDBException ex) {
        }
    // SAP specials
    String storageType = GraphUtils.getStringValue(root, AssemblerVocab.pStorageType);
    if (storageType != null)
        try {
            storeDesc.storageType = SAPStorageType.convert(storageType);
        } catch (SDBException ex) {
        }
    return storeDesc;
}
Also used : StoreDesc(org.apache.jena.sdb.StoreDesc) SDBException(org.apache.jena.sdb.SDBException) SDBConnectionDesc(org.apache.jena.sdb.sql.SDBConnectionDesc) Resource(org.apache.jena.rdf.model.Resource) FeatureSet(org.apache.jena.sdb.store.FeatureSet) Feature(org.apache.jena.sdb.store.Feature)

Example 13 with StoreDesc

use of org.apache.jena.sdb.StoreDesc in project jena by apache.

the class Ex2 method main.

public static void main(String... argv) {
    String queryString = "SELECT * { ?s ?p ?o }";
    Query query = QueryFactory.create(queryString);
    StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash, DatabaseType.Derby);
    // Multiple choices for Derby - load the embedded driver
    JDBC.loadDriverDerby();
    String jdbcURL = "jdbc:derby:DB/SDB2";
    // Passing null for user and password causes them to be extracted
    // from the environment variables SDB_USER and SDB_PASSWORD
    SDBConnection conn = new SDBConnection(jdbcURL, null, null);
    // Make store from connection and store description. 
    Store store = SDBFactory.connectStore(conn, storeDesc);
    Dataset ds = DatasetStore.create(store);
    QueryExecution qe = QueryExecutionFactory.create(query, ds);
    try {
        ResultSet rs = qe.execSelect();
        ResultSetFormatter.out(rs);
    } finally {
        qe.close();
    }
    store.close();
}
Also used : StoreDesc(org.apache.jena.sdb.StoreDesc) SDBConnection(org.apache.jena.sdb.sql.SDBConnection) Store(org.apache.jena.sdb.Store) DatasetStore(org.apache.jena.sdb.store.DatasetStore)

Example 14 with StoreDesc

use of org.apache.jena.sdb.StoreDesc in project jena by apache.

the class sdbprint method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    // Force the connection to be a null one.
    // Known to be called after arg module initialization.
    StoreDesc storeDesc = getModStore().getStoreDesc();
    storeDesc.connDesc.setJdbcURL(JDBC.jdbcNone);
    if (storeDesc.getLayout() == null)
        storeDesc.setLayout(layoutDefault);
    printSQL = contains(argDeclPrintSQL);
    List<String> strList = getValues(argDeclPrint);
    for (String arg : strList) {
        if (arg.equalsIgnoreCase("query")) {
            printQuery = true;
        } else if (arg.equalsIgnoreCase("Op")) {
            printOp = true;
        } else if (arg.equalsIgnoreCase("SqlNode")) {
            printSqlNode = true;
        } else if (arg.equalsIgnoreCase("sql")) {
            printSQL = true;
        } else if (arg.equalsIgnoreCase("plan")) {
            printPlan = true;
        } else
            throw new CmdException("Not a recognized print form: " + arg + " : Choices are: query, prefix, op, sqlNode, sql");
    }
}
Also used : CmdException(jena.cmd.CmdException) StoreDesc(org.apache.jena.sdb.StoreDesc)

Example 15 with StoreDesc

use of org.apache.jena.sdb.StoreDesc in project jena by apache.

the class QueryTestSDBFactory method make.

public static void make(TestSuite ts, String storeList, String manifestFile) {
    for (Pair<String, StoreDesc> p : StoreList.stores(storeList)) {
        String label = p.car();
        StoreDesc storeDesc = p.cdr();
        if (label != null && !label.equals(""))
            label = label + " - ";
        TestSuite ts2 = make(storeDesc, manifestFile, label);
        ts.addTest(ts2);
    }
}
Also used : TestSuite(junit.framework.TestSuite) StoreDesc(org.apache.jena.sdb.StoreDesc)

Aggregations

StoreDesc (org.apache.jena.sdb.StoreDesc)27 SDBConnection (org.apache.jena.sdb.sql.SDBConnection)19 Store (org.apache.jena.sdb.Store)4 Resource (org.apache.jena.rdf.model.Resource)3 Connection (java.sql.Connection)2 CmdException (jena.cmd.CmdException)1 TestSuite (junit.framework.TestSuite)1 Graph (org.apache.jena.graph.Graph)1 Dataset (org.apache.jena.query.Dataset)1 SDBException (org.apache.jena.sdb.SDBException)1 SDBConnectionDesc (org.apache.jena.sdb.sql.SDBConnectionDesc)1 DatasetStore (org.apache.jena.sdb.store.DatasetStore)1 Feature (org.apache.jena.sdb.store.Feature)1 FeatureSet (org.apache.jena.sdb.store.FeatureSet)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1