use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlTable method truncateTable.
protected void truncateTable(Session session) {
LOG.debug("Truncate table: {}", this.table());
String sql = this.buildTruncateTemplate();
try {
session.execute(sql);
} catch (SQLException e) {
throw new BackendException("Failed to truncate table with '%s'", e, sql);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlTable method dropTable.
protected void dropTable(Session session) {
LOG.debug("Drop table: {}", this.table());
String sql = this.buildDropTemplate();
try {
session.execute(sql);
} catch (SQLException e) {
throw new BackendException("Failed to drop table with '%s'", e, sql);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class MysqlTable method delete.
@Override
public void delete(Session session, MysqlBackendEntry.Row entry) {
List<HugeKeys> idNames = this.idColumnName();
String template = this.buildDeleteTemplate(idNames);
PreparedStatement deleteStmt;
try {
deleteStmt = session.prepareStatement(template);
if (entry.columns().isEmpty()) {
// Delete just by id
List<Long> idValues = this.idColumnValue(entry);
assert idNames.size() == idValues.size();
for (int i = 0, n = idNames.size(); i < n; i++) {
deleteStmt.setObject(i + 1, idValues.get(i));
}
} else {
// Delete just by column keys(must be id columns)
for (int i = 0, n = idNames.size(); i < n; i++) {
HugeKeys key = idNames.get(i);
Object value = entry.column(key);
deleteStmt.setObject(i + 1, value);
}
}
} catch (SQLException e) {
throw new BackendException("Failed to prepare statement '%s'" + "with entry columns %s", template, entry.columns().values());
}
session.add(deleteStmt);
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RocksDBSstSessions method doClose.
@Override
protected synchronized void doClose() {
final String NO_ENTRIES = "Can't create sst file with no entries";
for (SstFileWriter sst : this.tables.values()) {
E.checkState(sst.isOwningHandle(), "SstFileWriter closed");
try {
sst.finish();
} catch (RocksDBException e) {
if (e.getMessage().equals(NO_ENTRIES)) {
continue;
}
throw new BackendException("Failed to close SstFileWriter", e);
}
sst.close();
}
this.tables.clear();
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class PaloTable method createTable.
@Override
public void createTable(MysqlSessions.Session session, TableDefine tableDefine) {
StringBuilder sql = new StringBuilder();
sql.append("CREATE TABLE IF NOT EXISTS ");
sql.append(this.table()).append(" (");
// Add columns
int i = 0;
for (Map.Entry<HugeKeys, String> entry : tableDefine.columns().entrySet()) {
sql.append(formatKey(entry.getKey()));
sql.append(" ");
sql.append(entry.getValue());
if (++i != tableDefine.columns().size()) {
sql.append(", ");
}
}
sql.append(")");
// Unique keys
sql.append(" UNIQUE KEY(");
i = 0;
for (HugeKeys key : tableDefine.keys()) {
sql.append(formatKey(key));
if (++i != tableDefine.keys().size()) {
sql.append(", ");
}
}
sql.append(")");
// Hash keys
sql.append(" DISTRIBUTED BY HASH(");
i = 0;
for (HugeKeys key : tableDefine.keys()) {
sql.append(formatKey(key));
if (++i != tableDefine.keys().size()) {
sql.append(", ");
}
}
sql.append(");");
// TODO: 'replication_num(default=3)’ can be a configuration
LOG.debug("Create table: {}", sql);
try {
session.execute(sql.toString());
} catch (SQLException e) {
throw new BackendException("Failed to create table with '%s'", e, sql);
}
}
Aggregations