Search in sources :

Example 6 with BackendException

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);
    }
}
Also used : SQLException(java.sql.SQLException) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 7 with BackendException

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);
    }
}
Also used : SQLException(java.sql.SQLException) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 8 with BackendException

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);
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 9 with BackendException

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();
}
Also used : RocksDBException(org.rocksdb.RocksDBException) SstFileWriter(org.rocksdb.SstFileWriter) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 10 with BackendException

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);
    }
}
Also used : SQLException(java.sql.SQLException) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) Map(java.util.Map) BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

BackendException (com.baidu.hugegraph.backend.BackendException)79 SQLException (java.sql.SQLException)15 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)6 Status (com.alipay.sofa.jraft.Status)5 PeerId (com.alipay.sofa.jraft.entity.PeerId)5 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)5 BytesBuffer (com.baidu.hugegraph.backend.serializer.BytesBuffer)4 Path (java.nio.file.Path)4 Random (java.util.Random)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 RocksDBException (org.rocksdb.RocksDBException)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Id (com.baidu.hugegraph.backend.id.Id)3 Query (com.baidu.hugegraph.backend.query.Query)3 HugeConfig (com.baidu.hugegraph.config.HugeConfig)3 Map (java.util.Map)3 ReadIndexClosure (com.alipay.sofa.jraft.closure.ReadIndexClosure)2 Condition (com.baidu.hugegraph.backend.query.Condition)2 Relation (com.baidu.hugegraph.backend.query.Condition.Relation)2