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