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);
}
}
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;
}
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;
}
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>();
}
}
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();
}
Aggregations