Search in sources :

Example 1 with SDBException

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

the class ModStore method processArgs.

@Override
public void processArgs(CmdArgModule cmdLine) {
    if (!cmdLine.contains(argDeclSDBdesc)) {
        System.err.println("No store description");
        throw new TerminationException(1);
    }
    String f = cmdLine.getArg(argDeclSDBdesc).getValue();
    try {
        storeDesc = StoreDesc.read(f);
        if (storeDesc.getLayout() == null) {
            System.err.println("No layout or unrecognized layout");
            throw new TerminationException(1);
        }
    } catch (SDBException ex) {
        System.err.println("Failed to read the store description");
        System.err.println(ex.getMessage());
        throw new TerminationException(1);
    } catch (NotFoundException ex) {
        System.err.println(f + " : Store description not found");
        throw new TerminationException(1);
    }
    // Overrides.
    if (cmdLine.contains(argDeclDbHost))
        storeDesc.connDesc.setHost(cmdLine.getArg(argDeclDbHost).getValue());
    if (cmdLine.contains(argDeclDbName))
        storeDesc.connDesc.setName(cmdLine.getArg(argDeclDbName).getValue());
    if (cmdLine.contains(argDeclDbType))
        storeDesc.connDesc.setType(cmdLine.getArg(argDeclDbType).getValue());
    if (cmdLine.contains(argDeclDbUser))
        storeDesc.connDesc.setUser(cmdLine.getArg(argDeclDbUser).getValue());
    if (cmdLine.contains(argDeclDbPassword))
        storeDesc.connDesc.setPassword(cmdLine.getArg(argDeclDbPassword).getValue());
    if (cmdLine.contains(argDeclMySQLEngine))
        storeDesc.engineType = MySQLEngineType.convert(cmdLine.getArg(argDeclMySQLEngine).getValue());
    if (cmdLine.contains(argDeclSAPStorage))
        storeDesc.storageType = SAPStorageType.convert(cmdLine.getArg(argDeclSAPStorage).getValue());
    if (cmdLine.contains(argDeclLayout)) {
        String layoutName = cmdLine.getArg(argDeclLayout).getValue();
        storeDesc.setLayout(LayoutType.fetch(layoutName));
        if (storeDesc.getLayout() == null) {
            System.err.println("Don't recognize layout name '" + layoutName + "'");
            throw new TerminationException(2);
        }
    }
    if (false) {
        //System.out.println("URL       = " + storeDesc.connDesc.URL);
        System.out.println("Type      = " + storeDesc.connDesc.getType());
        System.out.println("Host      = " + storeDesc.connDesc.getHost());
        System.out.println("Database  = " + storeDesc.connDesc.getName());
        System.out.println("User      = " + storeDesc.connDesc.getUser());
        System.out.println("Password  = " + storeDesc.connDesc.getPassword());
        //            if ( storeDesc.connDesc.getArgStr() != null )
        //                System.out.println("Args      = " + storeDesc.connDesc.getArgStr());
        System.out.println("Layout    = " + storeDesc.getLayout().getName());
        //System.out.println("Name      = " + argModelName);
        SDBConnection.logSQLExceptions = true;
        SDBConnection.logSQLStatements = true;
    }
    if (cmdLine.contains(argDeclJdbcDriver)) {
        String driverName = cmdLine.getArg(argDeclJdbcDriver).getValue();
        storeDesc.connDesc.setDriver(driverName);
    }
}
Also used : TerminationException(jena.cmd.TerminationException) SDBException(org.apache.jena.sdb.SDBException) NotFoundException(org.apache.jena.shared.NotFoundException)

Example 2 with SDBException

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

the class SDBConnectionDesc method worker.

private static SDBConnectionDesc worker(Model m) {
    Resource r = GraphUtils.getResourceByType(m, AssemblerVocab.SDBConnectionAssemblerType);
    if (r == null)
        throw new SDBException("Can't find connection description");
    SDBConnectionDesc desc = (SDBConnectionDesc) AssemblerBase.general.open(r);
    desc.initJDBC();
    return desc;
}
Also used : SDBException(org.apache.jena.sdb.SDBException) Resource(org.apache.jena.rdf.model.Resource)

Example 3 with SDBException

use of org.apache.jena.sdb.SDBException 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 4 with SDBException

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

the class TupleLoaderBase method flush.

protected void flush() {
    if (tupleNum == 0)
        return;
    boolean handleTransaction = startTransaction(connection());
    try {
        if (amLoading) {
            insertNodeLoader.executeBatch();
            insertTupleLoader.executeBatch();
            connection().execUpdate(insertNodes);
            connection().execUpdate(insertTuples);
            if (!handleTransaction || !clearsOnCommit()) {
                clearNodeLoader.execute();
                clearTupleLoader.execute();
            }
        } else {
            deleteTuples.executeBatch();
        }
        endTransaction(connection(), handleTransaction);
    } catch (SQLException e) {
        if (handleTransaction)
            try {
                connection().getSqlConnection().rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
        throw new SDBException("Exception flushing", e);
    } finally {
        tupleNum = 0;
        seenNodes = new HashSet<Long>();
    }
}
Also used : SQLException(java.sql.SQLException) SDBException(org.apache.jena.sdb.SDBException)

Example 5 with SDBException

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

the class TupleLoaderBase method unload.

@Override
public void unload(Node... row) {
    if (amLoading) {
        flush();
        amLoading = false;
    }
    // TODO rethink overloading
    if (row.length != this.getTableWidth()) {
        if ((row.length == 0 && this.getTableWidth() == 3) || (row.length == 1)) {
            massDelete(row);
            return;
        } else {
            throw new IllegalArgumentException("Tuple size mismatch");
        }
    }
    try {
        for (int i = 0; i < row.length; i++) {
            //, false);
            PreparedNode pNode = new PreparedNode(row[i]);
            deleteTuples.setLong(i + 1, pNode.hash);
        }
        deleteTuples.addBatch();
    } catch (SQLException e) {
        throw new SDBException("Problem adding to prepared delete statements", e);
    }
    tupleNum++;
    if (tupleNum >= chunkSize)
        flush();
}
Also used : SQLException(java.sql.SQLException) SDBException(org.apache.jena.sdb.SDBException)

Aggregations

SDBException (org.apache.jena.sdb.SDBException)38 SQLException (java.sql.SQLException)30 Resource (org.apache.jena.rdf.model.Resource)2 ActionMatchString (org.apache.jena.sdb.exprmatch.ActionMatchString)2 ActionMatchVar (org.apache.jena.sdb.exprmatch.ActionMatchVar)2 MapResult (org.apache.jena.sdb.exprmatch.MapResult)2 Var (org.apache.jena.sparql.core.Var)2 ResultSet (java.sql.ResultSet)1 TerminationException (jena.cmd.TerminationException)1 StoreDesc (org.apache.jena.sdb.StoreDesc)1 SDBRequest (org.apache.jena.sdb.core.SDBRequest)1 ResultSetJDBC (org.apache.jena.sdb.sql.ResultSetJDBC)1 SDBConnectionDesc (org.apache.jena.sdb.sql.SDBConnectionDesc)1 SDBExceptionSQL (org.apache.jena.sdb.sql.SDBExceptionSQL)1 Feature (org.apache.jena.sdb.store.Feature)1 FeatureSet (org.apache.jena.sdb.store.FeatureSet)1 TupleLoader (org.apache.jena.sdb.store.TupleLoader)1 NotFoundException (org.apache.jena.shared.NotFoundException)1 Op (org.apache.jena.sparql.algebra.Op)1 TransformFilterEquality (org.apache.jena.sparql.algebra.optimize.TransformFilterEquality)1