use of herddb.model.StatementExecutionException in project herddb by diennea.
the class TableSpaceManager method dropIndex.
private StatementExecutionResult dropIndex(DropIndexStatement statement, Transaction transaction) throws StatementExecutionException {
generalLock.writeLock().lock();
try {
if (!indexes.containsKey(statement.getIndexName())) {
if (statement.isIfExists()) {
return new DDLStatementExecutionResult(transaction != null ? transaction.transactionId : 0);
}
throw new IndexDoesNotExistException("index " + statement.getIndexName() + " does not exist " + statement.getIndexName() + " on tableSpace " + statement.getTableSpace());
}
if (transaction != null && transaction.isIndexDropped(statement.getIndexName())) {
if (statement.isIfExists()) {
return new DDLStatementExecutionResult(transaction.transactionId);
}
throw new IndexDoesNotExistException("index does not exist " + statement.getIndexName() + " on tableSpace " + statement.getTableSpace());
}
LogEntry entry = LogEntryFactory.dropIndex(statement.getIndexName(), transaction);
CommitLogResult pos;
try {
pos = log.log(entry, entry.transactionId <= 0);
} catch (LogNotAvailableException ex) {
throw new StatementExecutionException(ex);
}
apply(pos, entry, false);
return new DDLStatementExecutionResult(entry.transactionId);
} catch (DataStorageManagerException err) {
throw new StatementExecutionException(err);
} finally {
generalLock.writeLock().unlock();
}
}
use of herddb.model.StatementExecutionException in project herddb by diennea.
the class TableSpaceManager method beginTransaction.
private StatementExecutionResult beginTransaction() throws StatementExecutionException {
long id = newTransactionId.incrementAndGet();
LogEntry entry = LogEntryFactory.beginTransaction(id);
CommitLogResult pos;
generalLock.readLock().lock();
try {
pos = log.log(entry, false);
apply(pos, entry, false);
return new TransactionResult(id, TransactionResult.OutcomeType.BEGIN);
} catch (Exception err) {
throw new StatementExecutionException(err);
} finally {
generalLock.readLock().unlock();
}
}
use of herddb.model.StatementExecutionException in project herddb by diennea.
the class TableSpaceManager method commitTransaction.
private StatementExecutionResult commitTransaction(CommitTransactionStatement commitTransactionStatement) throws StatementExecutionException {
long txId = commitTransactionStatement.getTransactionId();
LogEntry entry = LogEntryFactory.commitTransaction(txId);
generalLock.readLock().lock();
try {
Transaction tx = transactions.get(txId);
if (tx == null) {
throw new StatementExecutionException("no such transaction " + commitTransactionStatement.getTransactionId());
}
CommitLogResult pos = log.log(entry, true);
apply(pos, entry, false);
} catch (Exception err) {
throw new StatementExecutionException(err);
} finally {
generalLock.readLock().unlock();
}
return new TransactionResult(txId, TransactionResult.OutcomeType.COMMIT);
}
use of herddb.model.StatementExecutionException in project herddb by diennea.
the class TableSpaceManager method createIndex.
private StatementExecutionResult createIndex(CreateIndexStatement statement, Transaction transaction) throws StatementExecutionException {
generalLock.writeLock().lock();
try {
if (indexes.containsKey(statement.getIndexefinition().name)) {
throw new IndexAlreadyExistsException(statement.getIndexefinition().name);
}
LogEntry entry = LogEntryFactory.createIndex(statement.getIndexefinition(), transaction);
CommitLogResult pos;
try {
pos = log.log(entry, entry.transactionId <= 0);
} catch (LogNotAvailableException ex) {
throw new StatementExecutionException(ex);
}
apply(pos, entry, false);
return new DDLStatementExecutionResult(entry.transactionId);
} catch (DataStorageManagerException err) {
throw new StatementExecutionException(err);
} finally {
generalLock.writeLock().unlock();
}
}
use of herddb.model.StatementExecutionException in project herddb by diennea.
the class TableSpaceManager method rollbackTransaction.
private StatementExecutionResult rollbackTransaction(RollbackTransactionStatement rollbackTransactionStatement) throws StatementExecutionException {
long txId = rollbackTransactionStatement.getTransactionId();
LogEntry entry = LogEntryFactory.rollbackTransaction(txId);
generalLock.readLock().lock();
try {
Transaction tx = transactions.get(txId);
if (tx == null) {
throw new StatementExecutionException("no such transaction " + rollbackTransactionStatement.getTransactionId());
}
CommitLogResult pos = log.log(entry, true);
apply(pos, entry, false);
} catch (Exception err) {
throw new StatementExecutionException(err);
} finally {
generalLock.readLock().unlock();
}
return new TransactionResult(txId, TransactionResult.OutcomeType.ROLLBACK);
}
Aggregations