Skip to content

Commit

Permalink
不需要对上层暴露StorageMapBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Oct 12, 2015
1 parent 4fb1ff9 commit 6e67e63
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 80 deletions.
20 changes: 8 additions & 12 deletions lealone-common/src/main/java/org/lealone/storage/Storage.java
Expand Up @@ -24,29 +24,25 @@

public interface Storage {

<M extends StorageMap<K, V>, K, V> M openMap(String name, StorageMapBuilder<M, K, V> builder);

<M extends StorageMap<K, V>, K, V> StorageMapBuilder<M, K, V> getStorageMapBuilder(String type);

<K, V> StorageMap<K, V> openMap(String name, String mapType, DataType keyType, DataType valueType,
Map<String, String> parameters);

void close();
boolean hasMap(String name);

String nextTemporaryMapName();

void removeTemporaryMaps(BitField objectIds);

void initTransactions();

void backupTo(String fileName);

void flush();

void sync();

void initTransactions();

void removeTemporaryMaps(BitField objectIds);
void close();

void closeImmediately();

String nextTemporaryMapName();

boolean hasMap(String name);

}
Expand Up @@ -59,7 +59,7 @@ public class StandardPrimaryIndex extends IndexBase {
private int mainIndexColumn = -1;

public StandardPrimaryIndex(StorageEngine storageEngine, Session session, StandardTable table, int id,
IndexColumn[] columns, IndexType indexType, String mapType) {
IndexColumn[] columns, IndexType indexType) {

initIndexBase(table, id, table.getName() + "_DATA", columns, indexType);

Expand All @@ -74,7 +74,8 @@ public StandardPrimaryIndex(StorageEngine storageEngine, Session session, Standa

Storage storage = database.getStorage(storageEngine);
TransactionEngine transactionEngine = database.getTransactionEngine();
dataMap = transactionEngine.beginTransaction(false).openMap(mapName, mapType, keyType, valueType, storage);
dataMap = transactionEngine.beginTransaction(false).openMap(mapName, table.getMapType(), keyType, valueType,
storage);

// TODO
// Fix bug when creating lots of temporary tables, where we could run out of transaction IDs
Expand Down
Expand Up @@ -45,7 +45,7 @@ public class StandardSecondaryIndex extends IndexBase implements StandardIndex {
private final StorageEngine storageEngine;

public StandardSecondaryIndex(StorageEngine storageEngine, Session session, StandardTable table, int id,
String indexName, IndexColumn[] columns, IndexType indexType, String mapType) {
String indexName, IndexColumn[] columns, IndexType indexType) {
this.storageEngine = storageEngine;
Database db = session.getDatabase();
this.table = table;
Expand All @@ -67,7 +67,8 @@ public StandardSecondaryIndex(StorageEngine storageEngine, Session session, Stan

Storage storage = database.getStorage(storageEngine);
TransactionEngine transactionEngine = database.getTransactionEngine();
dataMap = transactionEngine.beginTransaction(false).openMap(mapName, mapType, keyType, valueType, storage);
dataMap = transactionEngine.beginTransaction(false).openMap(mapName, table.getMapType(), keyType, valueType,
storage);

// TODO
// Fix bug when creating lots of temporary tables, where we could run out of transaction IDs
Expand Down Expand Up @@ -168,18 +169,9 @@ private TransactionMap<Value, Value> openMap(Session session, String mapName) {
ValueDataType valueType = new ValueDataType(null, null, null);

Storage storage = database.getStorage(storageEngine);
// TODO 能够指定Map类型
// StorageMapBuilder<StorageMap<Value, Value>, Value, Value> builder = storage.getStorageMapBuilder("AOMap");
// builder.keyType(keyType);
// builder.valueType(valueType);
// StorageMap<Value, Value> storageMap = storage.openMap(mapName, builder);
//
// TransactionEngine transactionEngine = database.getTransactionEngine();
// TransactionMap<Value, Value> map = transactionEngine.getTransactionMap(session, storageMap);

TransactionEngine transactionEngine = database.getTransactionEngine();
TransactionMap<Value, Value> map = transactionEngine.beginTransaction(false).openMap(mapName, keyType,
valueType, storage);
TransactionMap<Value, Value> map = transactionEngine.beginTransaction(false).openMap(mapName,
table.getMapType(), keyType, valueType, storage);

if (!keyType.equals(map.getKeyType())) {
throw DbException.throwInternalError("Incompatible key type");
Expand Down
Expand Up @@ -99,14 +99,18 @@ public StandardTable(CreateTableData data, StorageEngine storageEngine) {
mapType = null;

primaryIndex = new StandardPrimaryIndex(storageEngine, data.session, this, getId(),
IndexColumn.wrap(getColumns()), IndexType.createScan(true), mapType);
IndexColumn.wrap(getColumns()), IndexType.createScan(true));
indexes.add(primaryIndex);
}

public String getMapName() {
return primaryIndex.getMapName();
}

public String getMapType() {
return mapType;
}

@Override
public boolean lock(Session session, boolean exclusive, boolean forceLockEvenInMvcc) {
int lockMode = database.getLockMode();
Expand Down Expand Up @@ -437,8 +441,7 @@ public Index addIndex(Session session, String indexName, int indexId, IndexColum
index = new NonUniqueHashIndex(this, indexId, indexName, cols, indexType);
}
} else {
index = new StandardSecondaryIndex(storageEngine, session, this, indexId, indexName, cols, indexType,
mapType);
index = new StandardSecondaryIndex(storageEngine, session, this, indexId, indexName, cols, indexType);
}
if (index instanceof StandardIndex && index.needRebuild()) {
rebuildIndex(session, (StandardIndex) index, indexName);
Expand Down
10 changes: 0 additions & 10 deletions lealone-storage/src/main/java/org/lealone/storage/AOStorage.java
Expand Up @@ -109,7 +109,6 @@ public static void addAOMap(AOMap<?, ?> map) {
backgroundThread = new AOStorageBackgroundThread(this);
}

@Override
@SuppressWarnings("unchecked")
public synchronized <M extends StorageMap<K, V>, K, V> M openMap(String name, StorageMapBuilder<M, K, V> builder) {
M map = (M) maps.get(name);
Expand Down Expand Up @@ -263,15 +262,6 @@ private void flush() {
}
}

@SuppressWarnings("unchecked")
@Override
public <M extends StorageMap<K, V>, K, V> StorageMapBuilder<M, K, V> getStorageMapBuilder(String type) {

if ("AOMap".equalsIgnoreCase(type))
return (StorageMapBuilder<M, K, V>) new BTreeMap.Builder<>();
return null;
}

@Override
public <K, V> StorageMap<K, V> openMap(String name, String mapType, DataType keyType, DataType valueType,
Map<String, String> parameters) {
Expand Down

This file was deleted.

Expand Up @@ -22,23 +22,10 @@
import org.lealone.common.util.BitField;
import org.lealone.storage.Storage;
import org.lealone.storage.StorageMap;
import org.lealone.storage.StorageMapBuilder;
import org.lealone.storage.type.DataType;

public class MemoryStorage implements Storage {

@Override
public <M extends StorageMap<K, V>, K, V> M openMap(String name, StorageMapBuilder<M, K, V> builder) {
// TODO Auto-generated method stub
return null;
}

@SuppressWarnings("unchecked")
@Override
public <M extends StorageMap<K, V>, K, V> StorageMapBuilder<M, K, V> getStorageMapBuilder(String type) {
return (StorageMapBuilder<M, K, V>) new MemoryMapBuilder<>();
}

@Override
public void close() {
// TODO Auto-generated method stub
Expand Down

0 comments on commit 6e67e63

Please sign in to comment.