diff --git a/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/DBConnection.java b/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/DBConnection.java index eea65d3f..a90248cc 100644 --- a/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/DBConnection.java +++ b/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/DBConnection.java @@ -12,5 +12,9 @@ public interface DBConnection { String get(String key); + T get(String key, Class type); + + void delete(String key); + boolean exist(String dbUrl); } diff --git a/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/MemoryDBConnection.java b/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/MemoryDBConnection.java index ac9e5755..49fe9857 100644 --- a/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/MemoryDBConnection.java +++ b/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/MemoryDBConnection.java @@ -44,4 +44,15 @@ public class MemoryDBConnection implements DBConnection { } return false; } + + @Override + public T get(String key, Class type) { + String record = memory.get(key); + return JSON.parseObject(record,type); + } + + @Override + public void delete(String key) { + memory.remove(key); + } } diff --git a/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/RocksDBConnection.java b/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/RocksDBConnection.java index ed32c519..893f6e67 100644 --- a/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/RocksDBConnection.java +++ b/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/RocksDBConnection.java @@ -73,6 +73,32 @@ public class RocksDBConnection implements DBConnection { return null; } + @Override + public T get(String key, Class type) { + try { + byte[] value = this.rocksDB.get(key.getBytes(UTF_8)); + if (value != null && value.length > 0) { + String strObj = new String(value, UTF_8); + return JSON.parseObject(strObj,type); + } + } catch (Exception e) { + throw new IllegalStateException(e); + } + return null; + } + + @Override + public void delete(String key) { + try { + byte[] value = this.rocksDB.get(key.getBytes(UTF_8)); + if (value != null && value.length > 0) { + this.rocksDB.delete(value); + } + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + @Override public boolean exist(String dbUrl) { // 首先该dbUrl是Rocksdb diff --git a/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/UmpDaoHandler.java b/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/UmpDaoHandler.java index 62cce01d..3e261577 100644 --- a/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/UmpDaoHandler.java +++ b/source/manager/manager-model/src/main/java/com/jd/blockchain/ump/dao/UmpDaoHandler.java @@ -68,6 +68,16 @@ public class UmpDaoHandler implements UmpDao, CommandLineRunner, DBConnection { return dbConnection.get(key); } + @Override + public T get(String key, Class type) { + return dbConnection.get(key,type); + } + + @Override + public void delete(String key) { + dbConnection.delete(key); + } + @Override public boolean exist(String dbUrl) { try { diff --git a/source/manager/manager-service/src/main/java/com/jd/blockchain/ump/service/DataAccountUmpService.java b/source/manager/manager-service/src/main/java/com/jd/blockchain/ump/service/DataAccountUmpService.java index 7d42cb47..2f1a8457 100644 --- a/source/manager/manager-service/src/main/java/com/jd/blockchain/ump/service/DataAccountUmpService.java +++ b/source/manager/manager-service/src/main/java/com/jd/blockchain/ump/service/DataAccountUmpService.java @@ -20,7 +20,7 @@ public interface DataAccountUmpService { */ boolean addDataAccountSchema(DataAccountSchema dataAccountSchema); - DataAccountSchema deleteDataAcccountSchema(String ledgerHash, String dataAccount); + void deleteDataAcccountSchema(String ledgerHash, String dataAccount); DataAccountSchema findDataAccountSchema(String ledgerHash, String dataAccount); } \ No newline at end of file diff --git a/source/manager/manager-service/src/main/java/com/jd/blockchain/ump/service/DataAccountUmpServiceImpl.java b/source/manager/manager-service/src/main/java/com/jd/blockchain/ump/service/DataAccountUmpServiceImpl.java index 1be066c0..4940c663 100644 --- a/source/manager/manager-service/src/main/java/com/jd/blockchain/ump/service/DataAccountUmpServiceImpl.java +++ b/source/manager/manager-service/src/main/java/com/jd/blockchain/ump/service/DataAccountUmpServiceImpl.java @@ -1,7 +1,9 @@ package com.jd.blockchain.ump.service; +import com.jd.blockchain.ump.dao.DBConnection; import com.jd.blockchain.ump.model.penetrate.DataAccountSchema; import com.jd.blockchain.ump.model.penetrate.store.MemStore; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import static com.jd.blockchain.ump.model.UmpConstant.SCHEMA_PREFIX; @@ -13,19 +15,27 @@ import static com.jd.blockchain.utils.BaseConstant.DELIMETER_UNDERLINE; */ @Service public class DataAccountUmpServiceImpl implements DataAccountUmpService { + @Autowired + private DBConnection dbConnection; + @Override public boolean addDataAccountSchema(DataAccountSchema dataAccountSchema) { - return MemStore.instance.put(SCHEMA_PREFIX+dataAccountSchema.getLedgerHash()+ - DELIMETER_UNDERLINE+dataAccountSchema.getDataAccount(),dataAccountSchema); + dbConnection.put(SCHEMA_PREFIX+dataAccountSchema.getLedgerHash()+ + DELIMETER_UNDERLINE+dataAccountSchema.getDataAccount(),dataAccountSchema,DataAccountSchema.class); + return true; +// return MemStore.instance.put(SCHEMA_PREFIX+dataAccountSchema.getLedgerHash()+ +// DELIMETER_UNDERLINE+dataAccountSchema.getDataAccount(),dataAccountSchema); } @Override - public DataAccountSchema deleteDataAcccountSchema(String ledgerHash, String dataAccount) { - return (DataAccountSchema)MemStore.instance.remove(SCHEMA_PREFIX+ledgerHash+ DELIMETER_UNDERLINE+dataAccount); + public void deleteDataAcccountSchema(String ledgerHash, String dataAccount) { + dbConnection.delete(SCHEMA_PREFIX+ledgerHash+ DELIMETER_UNDERLINE+dataAccount); +// MemStore.instance.remove(SCHEMA_PREFIX+ledgerHash+ DELIMETER_UNDERLINE+dataAccount); } @Override public DataAccountSchema findDataAccountSchema(String ledgerHash, String dataAccount) { - return (DataAccountSchema)MemStore.instance.get(SCHEMA_PREFIX+ledgerHash+ DELIMETER_UNDERLINE+dataAccount); + return dbConnection.get(SCHEMA_PREFIX+ledgerHash+ DELIMETER_UNDERLINE+dataAccount,DataAccountSchema.class); +// return (DataAccountSchema)MemStore.instance.get(SCHEMA_PREFIX+ledgerHash+ DELIMETER_UNDERLINE+dataAccount); } } diff --git a/source/manager/manager-web/src/main/java/com/jd/blockchain/ump/controller/RetrievalController.java b/source/manager/manager-web/src/main/java/com/jd/blockchain/ump/controller/RetrievalController.java index 8d6ec3ec..cde46f20 100644 --- a/source/manager/manager-web/src/main/java/com/jd/blockchain/ump/controller/RetrievalController.java +++ b/source/manager/manager-web/src/main/java/com/jd/blockchain/ump/controller/RetrievalController.java @@ -249,8 +249,8 @@ public class RetrievalController { public ApiResult deleteDataAccountSchema(@PathVariable(name = "ledgerHash") String ledgerHash, @PathVariable(name = "dataAccount") String dataAccount) { try { - DataAccountSchema dataAccountSchema = dataAccountUmpService.deleteDataAcccountSchema(ledgerHash, dataAccount); - return new ApiResult(ErrorCode.SUCCESS,dataAccountSchema); + dataAccountUmpService.deleteDataAcccountSchema(ledgerHash, dataAccount); + return new ApiResult(ErrorCode.SUCCESS); } catch (Exception e) { return new ApiResult(ErrorCode.SERVER_ERROR,e.getMessage()); }