Skip to content

Commit 8279a22

Browse files
authored
Merge pull request #844 from tronprotocol/remove_db_create
Remove db create
2 parents 0e64cd4 + db04071 commit 8279a22

25 files changed

+62
-369
lines changed

src/main/java/org/tron/core/config/DefaultConfig.java

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,6 @@ public DefaultConfig() {
2626
Thread.setDefaultUncaughtExceptionHandler((t, e) -> logger.error("Uncaught exception", e));
2727
}
2828

29-
@Bean(name = "witness")
30-
public String witness() {
31-
return "witness";
32-
}
33-
34-
@Bean(name = "account")
35-
public String account() {
36-
return "account";
37-
}
38-
39-
@Bean(name = "asset-issue")
40-
public String assetIssue() {
41-
return "asset-issue";
42-
}
43-
44-
@Bean(name = "block")
45-
public String block() {
46-
return "block";
47-
}
48-
49-
@Bean(name = "votes")
50-
public String votes() {
51-
return "votes";
52-
}
53-
54-
@Bean(name = "trans")
55-
public String trans() {
56-
return "trans";
57-
}
58-
59-
@Bean(name = "utxo")
60-
public String utxo() {
61-
return "utxo";
62-
}
63-
64-
@Bean(name = "properties")
65-
public String properties() {
66-
return "properties";
67-
}
68-
69-
@Bean(name = "block_KDB")
70-
public String blockKdb() {
71-
return "block_KDB";
72-
}
73-
74-
@Bean(name = "block-index")
75-
public String blockIndex() {
76-
return "block-index";
77-
}
78-
79-
@Bean(name = "account-index")
80-
public String accountIndex() {
81-
return "account-index";
82-
}
83-
84-
@Bean(name = "witness_schedule")
85-
public String witnessSchedule() {
86-
return "witness_schedule";
87-
}
88-
89-
@Bean(name = "recent-block")
90-
public String recentBlock() {
91-
return "recent-block";
92-
}
93-
94-
9529
@Bean
9630
public IndexHelper indexHelper() {
9731
if (!Args.getInstance().isSolidityNode()) {

src/main/java/org/tron/core/db/AccountIndexStore.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.apache.commons.lang3.ArrayUtils;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.beans.factory.annotation.Qualifier;
8+
import org.springframework.beans.factory.annotation.Value;
89
import org.springframework.stereotype.Component;
910
import org.tron.core.capsule.AccountCapsule;
1011
import org.tron.core.capsule.BytesCapsule;
@@ -13,32 +14,10 @@
1314
public class AccountIndexStore extends TronStoreWithRevoking<BytesCapsule> {
1415

1516
@Autowired
16-
public AccountIndexStore(@Qualifier("account-index") String dbName) {
17+
public AccountIndexStore(@Value("account-index") String dbName) {
1718
super(dbName);
1819
}
1920

20-
private static AccountIndexStore instance;
21-
22-
public static void destroy() {
23-
instance = null;
24-
}
25-
26-
/**
27-
* create fun.
28-
*
29-
* @param dbName the name of database
30-
*/
31-
public static AccountIndexStore create(String dbName) {
32-
if (instance == null) {
33-
synchronized (AccountIndexStore.class) {
34-
if (instance == null) {
35-
instance = new AccountIndexStore(dbName);
36-
}
37-
}
38-
}
39-
return instance;
40-
}
41-
4221
public void put(AccountCapsule accountCapsule) {
4322
put(accountCapsule.getAccountName().toByteArray(),
4423
new BytesCapsule(accountCapsule.getAddress().toByteArray()));

src/main/java/org/tron/core/db/AccountStore.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.commons.lang3.ArrayUtils;
1313
import org.springframework.beans.factory.annotation.Autowired;
1414
import org.springframework.beans.factory.annotation.Qualifier;
15+
import org.springframework.beans.factory.annotation.Value;
1516
import org.springframework.stereotype.Component;
1617
import org.tron.core.Wallet;
1718
import org.tron.core.capsule.AccountCapsule;
@@ -21,35 +22,13 @@
2122
@Component
2223
public class AccountStore extends TronStoreWithRevoking<AccountCapsule> {
2324

24-
private static Map<String, byte[]> assertsAddress =
25-
new HashMap<String, byte[]>(); // key = name , value = address
26-
private static AccountStore instance;
25+
private static Map<String, byte[]> assertsAddress = new HashMap<>(); // key = name , value = address
2726

2827
@Autowired
29-
private AccountStore(@Qualifier("account") String dbName) {
28+
private AccountStore(@Value("account") String dbName) {
3029
super(dbName);
3130
}
3231

33-
public static void destroy() {
34-
instance = null;
35-
}
36-
37-
/**
38-
* create fun.
39-
*
40-
* @param dbName the name of database
41-
*/
42-
public static AccountStore create(String dbName) {
43-
if (instance == null) {
44-
synchronized (AccountStore.class) {
45-
if (instance == null) {
46-
instance = new AccountStore(dbName);
47-
}
48-
}
49-
}
50-
return instance;
51-
}
52-
5332
@Override
5433
public AccountCapsule get(byte[] key) {
5534
byte[] value = dbSource.getData(key);

src/main/java/org/tron/core/db/AssetIssueStore.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.commons.lang3.ArrayUtils;
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.beans.factory.annotation.Qualifier;
12+
import org.springframework.beans.factory.annotation.Value;
1213
import org.springframework.stereotype.Component;
1314
import org.tron.core.capsule.AssetIssueCapsule;
1415
import org.tron.core.db.common.iterator.AssetIssueIterator;
@@ -17,33 +18,11 @@
1718
@Component
1819
public class AssetIssueStore extends TronStoreWithRevoking<AssetIssueCapsule> {
1920

20-
private static AssetIssueStore instance;
21-
2221
@Autowired
23-
private AssetIssueStore(@Qualifier("asset-issue") String dbName) {
22+
private AssetIssueStore(@Value("asset-issue") String dbName) {
2423
super(dbName);
2524
}
2625

27-
public static void destroy() {
28-
instance = null;
29-
}
30-
31-
/**
32-
* create fun.
33-
*
34-
* @param dbName the name of database
35-
*/
36-
public static AssetIssueStore create(String dbName) {
37-
if (instance == null) {
38-
synchronized (AssetIssueStore.class) {
39-
if (instance == null) {
40-
instance = new AssetIssueStore(dbName);
41-
}
42-
}
43-
}
44-
return instance;
45-
}
46-
4726
@Override
4827
public AssetIssueCapsule get(byte[] key) {
4928
byte[] value = dbSource.getData(key);

src/main/java/org/tron/core/db/BlockIndexStore.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.apache.commons.lang3.ArrayUtils;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.beans.factory.annotation.Qualifier;
6+
import org.springframework.beans.factory.annotation.Value;
67
import org.springframework.stereotype.Component;
78
import org.tron.common.utils.ByteArray;
89
import org.tron.common.utils.Sha256Hash;
@@ -15,33 +16,11 @@ public class BlockIndexStore extends TronStoreWithRevoking<BytesCapsule> {
1516

1617

1718
@Autowired
18-
public BlockIndexStore(@Qualifier("block-index") String dbName) {
19+
public BlockIndexStore(@Value("block-index") String dbName) {
1920
super(dbName);
2021

2122
}
2223

23-
private static BlockIndexStore instance;
24-
25-
public static void destroy() {
26-
instance = null;
27-
}
28-
29-
/**
30-
* create fun.
31-
*
32-
* @param dbName the name of database
33-
*/
34-
public static BlockIndexStore create(String dbName) {
35-
if (instance == null) {
36-
synchronized (BlockIndexStore.class) {
37-
if (instance == null) {
38-
instance = new BlockIndexStore(dbName);
39-
}
40-
}
41-
}
42-
return instance;
43-
}
44-
4524
public void put(BlockId id) {
4625
put(ByteArray.fromLong(id.getNum()), new BytesCapsule(id.getBytes()));
4726
}

src/main/java/org/tron/core/db/BlockStore.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.commons.lang3.ArrayUtils;
2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.beans.factory.annotation.Qualifier;
28+
import org.springframework.beans.factory.annotation.Value;
2829
import org.springframework.stereotype.Component;
2930
import org.tron.common.utils.Sha256Hash;
3031
import org.tron.core.capsule.BlockCapsule;
@@ -40,19 +41,12 @@
4041
public class BlockStore extends TronStoreWithRevoking<BlockCapsule> {
4142

4243
private BlockCapsule head;
43-
private IndexedCollection<Block> blockIndex;
4444

4545
@Autowired
46-
private BlockStore(@Qualifier("block") String dbName) {
46+
private BlockStore(@Value("block") String dbName) {
4747
super(dbName);
4848
}
4949

50-
private static BlockStore instance;
51-
52-
public static void destroy() {
53-
instance = null;
54-
}
55-
5650
@Override
5751
public void put(byte[] key, BlockCapsule item) {
5852
super.put(key, item);
@@ -61,20 +55,6 @@ public void put(byte[] key, BlockCapsule item) {
6155
}
6256
}
6357

64-
/**
65-
* create fun.
66-
*/
67-
public static BlockStore create(String dbName) {
68-
if (instance == null) {
69-
synchronized (BlockStore.class) {
70-
if (instance == null) {
71-
instance = new BlockStore(dbName);
72-
}
73-
}
74-
}
75-
return instance;
76-
}
77-
7858
@Override
7959
public BlockCapsule get(byte[] key) throws ItemNotFoundException, BadItemException {
8060
byte[] value = dbSource.getData(key);

src/main/java/org/tron/core/db/DynamicPropertiesStore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.joda.time.DateTime;
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.beans.factory.annotation.Qualifier;
11+
import org.springframework.beans.factory.annotation.Value;
1112
import org.springframework.stereotype.Component;
1213
import org.tron.common.utils.ByteArray;
1314
import org.tron.common.utils.Sha256Hash;
@@ -78,7 +79,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
7879
private static final byte[] BLOCK_NET_USAGE = "BLOCK_NET_USAGE".getBytes();
7980

8081
@Autowired
81-
private DynamicPropertiesStore(@Qualifier("properties") String dbName) {
82+
private DynamicPropertiesStore(@Value("properties") String dbName) {
8283
super(dbName);
8384
try {
8485
this.getMaintenanceTimeInterval();

src/main/java/org/tron/core/db/KhaosDatabase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import lombok.Getter;
1515
import org.springframework.beans.factory.annotation.Autowired;
1616
import org.springframework.beans.factory.annotation.Qualifier;
17+
import org.springframework.beans.factory.annotation.Value;
1718
import org.springframework.stereotype.Component;
1819
import org.tron.common.utils.Sha256Hash;
1920
import org.tron.core.capsule.BlockCapsule;
@@ -135,7 +136,7 @@ public int size() {
135136
private KhaosStore miniUnlinkedStore = new KhaosStore();
136137

137138
@Autowired
138-
protected KhaosDatabase(@Qualifier("block_KDB") String dbName) {
139+
protected KhaosDatabase(@Value("block_KDB") String dbName) {
139140
super(dbName);
140141
}
141142

src/main/java/org/tron/core/db/Manager.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,6 @@ public Set<Node> readNeighbours() {
248248
return this.peersStore.get("neighbours".getBytes());
249249
}
250250

251-
// fot test only
252-
public void destory() {
253-
AccountStore.destroy();
254-
TransactionStore.destroy();
255-
BlockStore.destroy();
256-
WitnessStore.destory();
257-
AssetIssueStore.destroy();
258-
DynamicPropertiesStore.destroy();
259-
WitnessScheduleStore.destroy();
260-
BlockIndexStore.destroy();
261-
AccountIndexStore.destroy();
262-
}
263-
264251
@PostConstruct
265252
public void init() {
266253
revokingStore = RevokingStore.getInstance();

src/main/java/org/tron/core/db/RecentBlockStore.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.apache.commons.lang3.ArrayUtils;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.beans.factory.annotation.Qualifier;
6+
import org.springframework.beans.factory.annotation.Value;
67
import org.springframework.stereotype.Component;
78
import org.tron.core.capsule.BytesCapsule;
89
import org.tron.core.exception.ItemNotFoundException;
@@ -11,16 +12,10 @@
1112
public class RecentBlockStore extends TronStoreWithRevoking<BytesCapsule> {
1213

1314
@Autowired
14-
private RecentBlockStore(@Qualifier("recent-block") String dbName) {
15+
private RecentBlockStore(@Value("recent-block") String dbName) {
1516
super(dbName);
1617
}
1718

18-
private static BlockStore instance;
19-
20-
public static void destroy() {
21-
instance = null;
22-
}
23-
2419
@Override
2520
public void put(byte[] key, BytesCapsule item) {
2621
super.put(key, item);

0 commit comments

Comments
 (0)