use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlSessions method buildUri.
protected String buildUri(boolean withConnParams, boolean withDB, boolean autoReconnect, Integer timeout) {
String url = this.buildUrlPrefix(withDB);
boolean forcedAutoReconnect = this.config.get(MysqlOptions.JDBC_FORCED_AUTO_RECONNECT);
int maxTimes = this.config.get(MysqlOptions.JDBC_RECONNECT_MAX_TIMES);
int interval = this.config.get(MysqlOptions.JDBC_RECONNECT_INTERVAL);
String sslMode = this.config.get(MysqlOptions.JDBC_SSL_MODE);
E.checkArgument(url.startsWith(JDBC_PREFIX), "The url must start with '%s': '%s'", JDBC_PREFIX, url);
String urlWithoutJdbc = url.substring(JDBC_PREFIX.length());
URIBuilder builder;
try {
builder = this.newConnectionURIBuilder(urlWithoutJdbc);
} catch (URISyntaxException e) {
throw new BackendException("Invalid url '%s'", e, url);
}
if (forcedAutoReconnect) {
autoReconnect = true;
}
if (withConnParams || forcedAutoReconnect) {
builder.setParameter("characterEncoding", "utf-8").setParameter("rewriteBatchedStatements", "true").setParameter("useServerPrepStmts", "false").setParameter("autoReconnect", String.valueOf(autoReconnect)).setParameter("maxReconnects", String.valueOf(maxTimes)).setParameter("initialTimeout", String.valueOf(interval));
}
if (timeout != null) {
builder.setParameter("socketTimeout", String.valueOf(timeout));
}
builder.setParameter("useSSL", sslMode);
return JDBC_PREFIX + builder.toString();
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RocksDBStdSessions method cf.
private CFHandle cf(String cfName) {
CFHandle cfh = this.rocksdb.cf(cfName);
if (cfh == null) {
throw new BackendException("Table '%s' is not opened", cfName);
}
cfh.open();
return cfh;
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RocksDBStdSessions method resumeSnapshot.
@Override
public void resumeSnapshot(String snapshotPath) {
File originDataDir = new File(this.dataPath);
File snapshotDir = new File(snapshotPath);
try {
/*
* Close current instance first
* NOTE: must close rocksdb instance before deleting file directory,
* if close after copying the snapshot directory to origin position,
* it may produce dirty data.
*/
this.forceCloseRocksDB();
// Delete origin data directory
if (originDataDir.exists()) {
LOG.info("Delete origin data directory {}", originDataDir);
FileUtils.deleteDirectory(originDataDir);
}
// Move snapshot directory to origin data directory
FileUtils.moveDirectory(snapshotDir, originDataDir);
LOG.info("Move snapshot directory {} to {}", snapshotDir, originDataDir);
// Reload rocksdb instance
this.reloadRocksDB();
} catch (Exception e) {
throw new BackendException("Failed to resume snapshot '%s' to' %s'", e, snapshotDir, this.dataPath);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlTable method createTable.
protected void createTable(Session session, TableDefine tableDefine) {
StringBuilder sql = new StringBuilder();
sql.append("CREATE TABLE IF NOT EXISTS ");
sql.append(this.table()).append(" (");
// Add columns
for (Map.Entry<HugeKeys, String> entry : tableDefine.columns().entrySet()) {
sql.append(formatKey(entry.getKey()));
sql.append(" ");
sql.append(entry.getValue());
sql.append(", ");
}
// Specified primary keys
sql.append(" PRIMARY KEY (");
int i = 0;
int size = tableDefine.keys().size();
for (HugeKeys key : tableDefine.keys()) {
sql.append(formatKey(key));
if (++i != size) {
sql.append(", ");
}
}
sql.append("))");
sql.append(this.engine(session));
sql.append(";");
LOG.debug("Create table: {}", sql);
try {
session.execute(sql.toString());
} catch (SQLException e) {
throw new BackendException("Failed to create table with '%s'", e, sql);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlTable method insert.
/**
* Insert an entire row
*/
@Override
public void insert(Session session, MysqlBackendEntry.Row entry) {
String template = this.buildInsertTemplate(entry);
PreparedStatement insertStmt;
try {
// Create or get insert prepare statement
insertStmt = session.prepareStatement(template);
int i = 1;
for (Object object : this.buildInsertObjects(entry)) {
insertStmt.setObject(i++, object);
}
} catch (SQLException e) {
throw new BackendException("Failed to prepare statement '%s'" + "for entry: %s", template, entry);
}
session.add(insertStmt);
}
Aggregations