Search in sources :

Example 26 with DataScannerException

use of herddb.model.DataScannerException in project herddb by diennea.

the class TableManager method validateForeignKeyConsistency.

private void validateForeignKeyConsistency(ForeignKeyDef fk, StatementEvaluationContext context, Transaction transaction) throws StatementExecutionException {
    if (!tableSpaceManager.getDbmanager().isFullSQLSupportEnabled()) {
        // we cannot perform this validation without Calcite
        return;
    }
    Table parentTable = tableSpaceManager.getTableManagerByUUID(fk.parentTableId).getTable();
    StringBuilder query = new StringBuilder("SELECT * " + "      FROM " + delimit(this.tableSpaceManager.getTableSpaceName()) + "." + delimit(this.table.name) + " childtable " + "      WHERE NOT EXISTS (SELECT * " + "                        FROM " + delimit(this.tableSpaceManager.getTableSpaceName()) + "." + delimit(parentTable.name) + " parenttable " + "                        WHERE ");
    for (int i = 0; i < fk.columns.length; i++) {
        if (i > 0) {
            query.append(" AND ");
        }
        query.append("childtable.").append(delimit(fk.columns[i])).append(" = parenttable.").append(delimit(fk.parentTableColumns[i]));
    }
    query.append(")");
    TransactionContext tx = transaction != null ? new TransactionContext(transaction.transactionId) : TransactionContext.NO_TRANSACTION;
    boolean fkOk;
    try (DataScanner scan = tableSpaceManager.getDbmanager().executeSimpleQuery(tableSpaceManager.getTableSpaceName(), query.toString(), Collections.emptyList(), // only one record
    1, // keep read locks in TransactionContext
    true, tx, context)) {
        List<DataAccessor> resultSet = scan.consume();
        fkOk = resultSet.isEmpty();
    } catch (DataScannerException err) {
        throw new StatementExecutionException(err);
    }
    if (!fkOk) {
        throw new ForeignKeyViolationException(fk.name, "foreignKey " + table.name + "." + fk.name + " violated");
    }
}
Also used : Table(herddb.model.Table) DataScanner(herddb.model.DataScanner) ForeignKeyViolationException(herddb.model.ForeignKeyViolationException) TransactionContext(herddb.model.TransactionContext) DataAccessor(herddb.utils.DataAccessor) StatementExecutionException(herddb.model.StatementExecutionException) DataScannerException(herddb.model.DataScannerException)

Example 27 with DataScannerException

use of herddb.model.DataScannerException in project herddb by diennea.

the class DBManager method createTableCheckSum.

public DataConsistencyStatementResult createTableCheckSum(TableConsistencyCheckStatement tableConsistencyCheckStatement, StatementEvaluationContext context) {
    TableSpaceManager manager = tablesSpaces.get(tableConsistencyCheckStatement.getTableSpace());
    String tableName = tableConsistencyCheckStatement.getTable();
    String tableSpaceName = tableConsistencyCheckStatement.getTableSpace();
    if (manager == null) {
        return new DataConsistencyStatementResult(false, "No such tablespace " + tableSpaceName);
    }
    try {
        manager.createAndWriteTableCheksum(manager, tableSpaceName, tableName, context);
    } catch (IOException | DataScannerException ex) {
        LOGGER.log(Level.SEVERE, "Error on check of tablespace " + tableSpaceName, ex);
        return new DataConsistencyStatementResult(false, "Error on check of tablespace " + tableSpaceName + ":" + ex);
    }
    return new DataConsistencyStatementResult(true, "Check table consistency for " + tableName + "completed");
}
Also used : DataConsistencyStatementResult(herddb.model.DataConsistencyStatementResult) IOException(java.io.IOException) DataScannerException(herddb.model.DataScannerException)

Example 28 with DataScannerException

use of herddb.model.DataScannerException in project herddb by diennea.

the class DBManager method createTableSpaceCheckSum.

public DataConsistencyStatementResult createTableSpaceCheckSum(TableSpaceConsistencyCheckStatement tableSpaceConsistencyCheckStatement) {
    TableSpaceManager manager = tablesSpaces.get(tableSpaceConsistencyCheckStatement.getTableSpace());
    String tableSpace = tableSpaceConsistencyCheckStatement.getTableSpace();
    List<Table> tables = manager.getAllCommittedTables();
    long _start = System.currentTimeMillis();
    for (Table table : tables) {
        AbstractTableManager tableManager = manager.getTableManager(table.name);
        if (!tableManager.isSystemTable()) {
            try {
                manager.createAndWriteTableCheksum(manager, tableSpace, tableManager.getTable().name, null);
            } catch (IOException | DataScannerException ex) {
                LOGGER.log(Level.SEVERE, "Error on check of tablespace " + tableSpace, ex);
                return new DataConsistencyStatementResult(false, "Error on check  of tablespace " + tableSpace + ":" + ex);
            }
        }
    }
    long _stop = System.currentTimeMillis();
    long tableSpace_check_duration = (_stop - _start);
    LOGGER.log(Level.INFO, "Check tablespace consistency for {0} Completed in {1} ms", new Object[] { tableSpace, tableSpace_check_duration });
    return new DataConsistencyStatementResult(true, "Check tablespace consistency for " + tableSpace + "completed in " + tableSpace_check_duration);
}
Also used : Table(herddb.model.Table) DataConsistencyStatementResult(herddb.model.DataConsistencyStatementResult) IOException(java.io.IOException) DataScannerException(herddb.model.DataScannerException)

Example 29 with DataScannerException

use of herddb.model.DataScannerException in project herddb by diennea.

the class SimpleDataScanner method next.

@Override
public DataAccessor next() throws DataScannerException {
    if (finished) {
        throw new DataScannerException("Scanner is exhausted");
    }
    DataAccessor _next = next;
    next = null;
    return _next;
}
Also used : DataAccessor(herddb.utils.DataAccessor) DataScannerException(herddb.model.DataScannerException)

Example 30 with DataScannerException

use of herddb.model.DataScannerException in project herddb by diennea.

the class TmpMapImpl method forEachKey.

@Override
public void forEachKey(Sink<K> sink) throws CollectionsException, SinkException {
    try (DataScanner dataScanner = tableSpaceManager.scan(scan, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION, false, false)) {
        while (dataScanner.hasNext()) {
            DataAccessor next = dataScanner.next();
            Object key = next.get(0);
            if (key instanceof RawString) {
                key = key.toString();
            }
            try {
                if (!sink.accept((K) key)) {
                    return;
                }
            } catch (Exception err) {
                throw new SinkException(err);
            }
        }
    } catch (SinkException err) {
        throw err;
    } catch (HerdDBInternalException | DataScannerException err) {
        throw new CollectionsException(err);
    }
}
Also used : DataScanner(herddb.model.DataScanner) HerdDBInternalException(herddb.core.HerdDBInternalException) RawString(herddb.utils.RawString) DataAccessor(herddb.utils.DataAccessor) DataScannerException(herddb.model.DataScannerException) HerdDBInternalException(herddb.core.HerdDBInternalException) StatementExecutionException(herddb.model.StatementExecutionException) DataScannerException(herddb.model.DataScannerException)

Aggregations

DataScannerException (herddb.model.DataScannerException)30 DataScanner (herddb.model.DataScanner)26 StatementExecutionException (herddb.model.StatementExecutionException)25 DataAccessor (herddb.utils.DataAccessor)24 ScanResult (herddb.model.ScanResult)19 TransactionContext (herddb.model.TransactionContext)18 StatementExecutionResult (herddb.model.StatementExecutionResult)15 Table (herddb.model.Table)13 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)12 ArrayList (java.util.ArrayList)12 Bytes (herddb.utils.Bytes)10 DMLStatement (herddb.model.DMLStatement)8 InsertStatement (herddb.model.commands.InsertStatement)8 ScanStatement (herddb.model.commands.ScanStatement)8 Column (herddb.model.Column)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 HerdDBInternalException (herddb.core.HerdDBInternalException)5 DuplicatePrimaryKeyException (herddb.model.DuplicatePrimaryKeyException)5 RecordFunction (herddb.model.RecordFunction)5