/** * Whether the session contains any uncommitted changes. * * @return true if yes */ public boolean containsUncommitted() { if (database.getMvStore() != null) { return transaction != null; } return firstUncommittedLog != Session.LOG_WRITTEN; }
private void endTransaction() { if (removeLobMap != null && removeLobMap.size() > 0) { if (database.getMvStore() == null) { // need to flush the transaction log, because we can't unlink // lobs if the commit record is not written database.flush(); } for (Value v : removeLobMap.values()) { v.remove(); } removeLobMap = null; } unlockAll(); }
/** * Create a savepoint to allow rolling back to this state. * * @return the savepoint */ public Savepoint setSavepoint() { Savepoint sp = new Savepoint(); sp.logIndex = undoLog.size(); if (database.getMvStore() != null) { sp.transactionSavepoint = getStatementSavepoint(); } return sp; }
/** * Create a savepoint that is linked to the current log position. * * @param name the savepoint name */ public void addSavepoint(String name) { if (savepoints == null) { savepoints = database.newStringMap(); } Savepoint sp = new Savepoint(); sp.logIndex = undoLog.size(); if (database.getMvStore() != null) { sp.transactionSavepoint = getStatementSavepoint(); } savepoints.put(name, sp); }
/** * Get the transaction to use for this session. * * @return the transaction */ public Transaction getTransaction() { if (transaction == null) { if (database.getMvStore().getStore().isClosed()) { database.shutdownImmediately(); throw DbException.get(ErrorCode.DATABASE_IS_CLOSED); } transaction = database.getMvStore().getTransactionStore().begin(); startStatement = -1; } return transaction; }
public Value getTransactionId() { if (database.getMvStore() != null) { if (transaction == null) { return ValueNull.INSTANCE; } return ValueString.get(Long.toString(getTransaction().getId())); } if (!database.isPersistent()) { return ValueNull.INSTANCE; } if (undoLog.size() == 0) { return ValueNull.INSTANCE; } return ValueString.get(firstUncommittedLog + "-" + firstUncommittedPos + "-" + id); }
@Override public void removeAllForTable(int tableId) { init(); if (database.getMvStore().getStore().isClosed()) { return; } // this might not be very efficient - // to speed it up, we would need yet another map ArrayList<Long> list = New.arrayList(); for (Entry<Long, Object[]> e : lobMap.entrySet()) { Object[] value = e.getValue(); int t = (Integer) value[1]; if (t == tableId) { list.add(e.getKey()); } } for (long lobId : list) { removeLob(tableId, lobId); } if (tableId == LobStorageFrontend.TABLE_ID_SESSION_VARIABLE) { removeAllForTable(LobStorageFrontend.TABLE_TEMP); removeAllForTable(LobStorageFrontend.TABLE_RESULT); } }
@Override public int getCacheSizeMax() { if (!database.isPersistent()) { return 0; } PageStore p = database.getPageStore(); if (p != null) { return p.getCache().getMaxMemory(); } return database.getMvStore().getStore().getCacheSize() * 1024; }
@Override public long getFileWriteCount() { if (!database.isPersistent()) { return 0; } PageStore p = database.getPageStore(); if (p != null) { return p.getWriteCount(); } return database.getMvStore().getStore().getFileStore().getReadCount(); }
@Override public long getFileReadCount() { if (!database.isPersistent()) { return 0; } PageStore p = database.getPageStore(); if (p != null) { return p.getReadCount(); } return database.getMvStore().getStore().getFileStore().getReadCount(); }
@Override public int getCacheSize() { if (!database.isPersistent()) { return 0; } PageStore p = database.getPageStore(); if (p != null) { return p.getCache().getMemory(); } return database.getMvStore().getStore().getCacheSizeUsed() * 1024; }
long savepointId = savepoint == null ? 0 : savepoint.transactionSavepoint; HashMap<String, MVTable> tableMap = database.getMvStore().getTables(); Iterator<Change> it = transaction.getChanges(savepointId); while (it.hasNext()) {
@Override public long getFileSize() { if (!database.isPersistent()) { return 0; } PageStore p = database.getPageStore(); if (p != null) { return p.getPageCount() * p.getPageSize() / 1024; } return database.getMvStore().getStore().getFileStore().size(); }
private void rebuildIndex(Session session, MVIndex index, String indexName) { try { if (session.getDatabase().getMvStore() == null || index instanceof MVSpatialIndex) { // in-memory rebuildIndexBuffered(session, index); } else { rebuildIndexBlockMerge(session, index); } } catch (DbException e) { getSchema().freeUniqueName(indexName); try { index.remove(session); } catch (DbException e2) { // this could happen, for example on failure in the storage // but if that is not the case it means // there is something wrong with the database trace.error(e2, "could not remove index"); throw e2; } throw e; } }
Cursor cursor = scan.find(session, null, null); long i = 0; Store store = session.getDatabase().getMvStore();
database.lockMeta(session); database.getMvStore().removeTable(this); super.removeChildrenAndResources(session);
private MVMap<ValueArray, Value> openMap(String mapName) { int[] sortTypes = new int[keyColumns]; for (int i = 0; i < indexColumns.length; i++) { sortTypes[i] = indexColumns[i].sortType; } sortTypes[keyColumns - 1] = SortOrder.ASCENDING; ValueDataType keyType = new ValueDataType( database.getCompareMode(), database, sortTypes); ValueDataType valueType = new ValueDataType(null, null, null); MVMap.Builder<ValueArray, Value> builder = new MVMap.Builder<ValueArray, Value>().keyType(keyType).valueType(valueType); MVMap<ValueArray, Value> map = database.getMvStore(). getStore().openMap(mapName, builder); if (!keyType.equals(map.getKeyType())) { throw DbException.throwInternalError("Incompatible key type"); } return map; }
@Override public Value[] next() { if (resultCursor == null) { Index idx; if (distinct || sort != null) { idx = index; } else { idx = table.getScanIndex(session); } if (session.getDatabase().getMvStore() != null) { // sometimes the transaction is already committed, // in which case we can't use the session if (idx.getRowCount(session) == 0 && rowCount > 0) { // this means querying is not transactional resultCursor = idx.find((Session) null, null, null); } else { // the transaction is still open resultCursor = idx.find(session, null, null); } } else { resultCursor = idx.find(session, null, null); } } if (!resultCursor.next()) { return null; } Row row = resultCursor.get(); return row.getValueList(); }
Store mvStore = db.getMvStore(); if (mvStore != null) { mvStore.flush();
new MVRTreeMap.Builder<VersionedValue>(). valueType(valueType); spatialMap = db.getMvStore().getStore().openMap(mapName, mapBuilder); Transaction t = mvTable.getTransactionBegin(); dataMap = t.openMap(spatialMap);