Search in sources :

Example 11 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class SQLRecordPredicateFunctions method compileLikePattern.

static Pattern compileLikePattern(String b, char escapeChar) throws HerdDBInternalException {
    /*
         * We presume that in string there will be 1 or 2 '%' or '_' characters. To avoid multiple array
         * copies in standard cases we preallocate a builder size of string input size plus 6 chars per
         * special character (4 chars for wrapping quoting sequence and 2 for pattern characters: \\E.*\\Q
         * or \\E.?\\Q) plus 4 chars for whole string wrapping quote sequence (\\Qstring\\E).
         */
    final StringBuilder builder = new StringBuilder(b.length() + 18);
    builder.append("\\Q");
    int limit = b.length();
    boolean escaping = false;
    for (int idx = 0; idx < limit; ++idx) {
        char ch = b.charAt(idx);
        if (ch == escapeChar) {
            escaping = true;
        } else {
            if (escaping) {
                builder.append(ch);
                escaping = false;
            } else {
                switch(ch) {
                    case '%':
                        builder.append("\\E.*\\Q");
                        break;
                    case '_':
                        builder.append("\\E.{1}\\Q");
                        break;
                    default:
                        builder.append(ch);
                        break;
                }
            }
        }
    }
    builder.append("\\E");
    String like = builder.toString();
    try {
        return Pattern.compile(like, Pattern.DOTALL);
    } catch (IllegalArgumentException err) {
        throw new HerdDBInternalException("Cannot compile LIKE expression '" + b + "': " + err);
    }
}
Also used : HerdDBInternalException(herddb.core.HerdDBInternalException)

Example 12 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class FileDataStorageManager method fullTableScan.

@Override
public void fullTableScan(String tableSpace, String tableName, FullTableScanConsumer consumer) throws DataStorageManagerException {
    try {
        TableStatus status = getLatestTableStatus(tableSpace, tableName);
        fullTableScan(tableSpace, tableName, status, consumer);
    } catch (HerdDBInternalException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) HerdDBInternalException(herddb.core.HerdDBInternalException) TableStatus(herddb.storage.TableStatus)

Example 13 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class FileDataStorageManager method fullTableScan.

@Override
public void fullTableScan(String tableSpace, String tableUuid, LogSequenceNumber sequenceNumber, FullTableScanConsumer consumer) throws DataStorageManagerException {
    try {
        TableStatus status = getTableStatus(tableSpace, tableUuid, sequenceNumber);
        fullTableScan(tableSpace, tableUuid, status, consumer);
    } catch (HerdDBInternalException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) HerdDBInternalException(herddb.core.HerdDBInternalException) TableStatus(herddb.storage.TableStatus)

Example 14 with HerdDBInternalException

use of herddb.core.HerdDBInternalException in project herddb by diennea.

the class BookKeeperDataStorageManager method fullTableScan.

@Override
public void fullTableScan(String tableSpace, String tableName, FullTableScanConsumer consumer) throws DataStorageManagerException {
    try {
        TableStatus status = getLatestTableStatus(tableSpace, tableName);
        fullTableScan(tableSpace, tableName, status, consumer);
    } catch (HerdDBInternalException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) HerdDBInternalException(herddb.core.HerdDBInternalException) TableStatus(herddb.storage.TableStatus)

Example 15 with HerdDBInternalException

use of herddb.core.HerdDBInternalException 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

HerdDBInternalException (herddb.core.HerdDBInternalException)23 TransactionContext (herddb.model.TransactionContext)8 HDBException (herddb.client.HDBException)5 DataScannerException (herddb.model.DataScannerException)5 SQLPlannedOperationStatement (herddb.model.commands.SQLPlannedOperationStatement)5 ScanStatement (herddb.model.commands.ScanStatement)5 TranslatedQuery (herddb.sql.TranslatedQuery)5 RawString (herddb.utils.RawString)5 TuplesList (herddb.utils.TuplesList)5 DataScanner (herddb.model.DataScanner)4 StatementExecutionException (herddb.model.StatementExecutionException)4 RollbackTransactionStatement (herddb.model.commands.RollbackTransactionStatement)4 DataStorageManagerException (herddb.storage.DataStorageManagerException)4 TableStatus (herddb.storage.TableStatus)4 ArrayList (java.util.ArrayList)4 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)3 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)3 Record (herddb.model.Record)3 Statement (herddb.model.Statement)3 StatementExecutionResult (herddb.model.StatementExecutionResult)3