Skip to content

Commit 6933211

Browse files
committed
refactor: moved shared context init of the database in the constructor
1 parent ae54186 commit 6933211

9 files changed

Lines changed: 47 additions & 37 deletions

File tree

client/src/main/java/com/orientechnologies/orient/client/remote/db/document/ODatabaseDocumentRemote.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public class ODatabaseDocumentRemote extends ODatabaseDocumentAbstract {
115115
private ORemoteClient client;
116116

117117
public ODatabaseDocumentRemote(OSharedContextRemote sharedContext) {
118+
super(sharedContext);
118119
activateOnCurrentThread();
119120

120121
try {

core/src/main/java/com/orientechnologies/orient/core/db/ODatabaseDocumentEmbeddedPooled.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public class ODatabaseDocumentEmbeddedPooled extends ODatabaseDocumentEmbedded {
2727

2828
private ODatabasePoolInternal pool;
2929

30-
public ODatabaseDocumentEmbeddedPooled(ODatabasePoolInternal pool, OStorage storage) {
31-
super(storage);
30+
public ODatabaseDocumentEmbeddedPooled(
31+
ODatabasePoolInternal pool, OStorage storage, OSharedContext sharedContext) {
32+
super(storage, sharedContext);
3233
this.pool = pool;
3334
}
3435

core/src/main/java/com/orientechnologies/orient/core/db/OrientDBEmbedded.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,17 @@ public ODatabaseDocumentEmbedded openNoAuthenticate(String name, String user) {
324324
}
325325

326326
protected ODatabaseDocumentEmbedded newSessionInstance(OStorage storage, OrientDBConfig config) {
327-
ODatabaseDocumentEmbedded embedded = new ODatabaseDocumentEmbedded(storage);
328-
embedded.init(config, getOrCreateSharedContext(storage));
327+
OSharedContext sharedContext = getOrCreateSharedContext(storage);
328+
ODatabaseDocumentEmbedded embedded = new ODatabaseDocumentEmbedded(storage, sharedContext);
329+
embedded.init(config);
329330
return embedded;
330331
}
331332

332333
protected ODatabaseDocumentEmbedded newCreateSessionInstance(
333334
OStorage storage, OrientDBConfig config) {
334-
ODatabaseDocumentEmbedded embedded = new ODatabaseDocumentEmbedded(storage);
335-
embedded.internalCreate(config, getOrCreateSharedContext(storage));
335+
OSharedContext sharedContext = getOrCreateSharedContext(storage);
336+
ODatabaseDocumentEmbedded embedded = new ODatabaseDocumentEmbedded(storage, sharedContext);
337+
embedded.internalCreate(config, sharedContext);
336338
return embedded;
337339
}
338340

@@ -456,8 +458,9 @@ public ODatabaseDocumentInternal poolOpen(
456458

457459
protected ODatabaseDocumentEmbedded newPooledSessionInstance(
458460
ODatabasePoolInternal pool, OStorage storage, OSharedContext sharedContext) {
459-
ODatabaseDocumentEmbeddedPooled embedded = new ODatabaseDocumentEmbeddedPooled(pool, storage);
460-
embedded.init(pool.getConfig(), sharedContext);
461+
ODatabaseDocumentEmbeddedPooled embedded =
462+
new ODatabaseDocumentEmbeddedPooled(pool, storage, sharedContext);
463+
embedded.init(pool.getConfig());
461464
return embedded;
462465
}
463466

core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentAbstract.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ public abstract class ODatabaseDocumentAbstract extends OListenerManger<ODatabas
160160
protected long minRidbagPrefetchMs;
161161
protected long maxRidbagPrefetchMs;
162162

163-
protected ODatabaseDocumentAbstract() {
163+
protected ODatabaseDocumentAbstract(OSharedContext context) {
164164
// DO NOTHING IS FOR EXTENDED OBJECTS
165165
super(false);
166+
this.sharedContext = context;
166167
}
167168

168169
/**

core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentEmbedded.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public class ODatabaseDocumentEmbedded extends ODatabaseDocumentAbstract
151151
private OrientDBConfig config;
152152
private OStorage storage;
153153

154-
public ODatabaseDocumentEmbedded(final OStorage storage) {
154+
public ODatabaseDocumentEmbedded(final OStorage storage, OSharedContext sharedContext) {
155+
super(sharedContext);
155156
activateOnCurrentThread();
156157

157158
try {
@@ -176,8 +177,7 @@ public ODatabaseDocumentEmbedded(final OStorage storage) {
176177
}
177178
}
178179

179-
public void init(OrientDBConfig config, OSharedContext sharedContext) {
180-
this.sharedContext = sharedContext;
180+
public void init(OrientDBConfig config) {
181181
this.sharedContext.startSession();
182182
activateOnCurrentThread();
183183
this.config = config;
@@ -497,8 +497,8 @@ public <DB extends ODatabase> DB setCustom(final String name, final Object iValu
497497
public ODatabaseDocumentInternal copy() {
498498
var storage = (OStorage) getSharedContext().getStorage();
499499
storage.open(config.getConfigurations());
500-
ODatabaseDocumentEmbedded database = new ODatabaseDocumentEmbedded(storage);
501-
database.init(config, this.sharedContext);
500+
ODatabaseDocumentEmbedded database = new ODatabaseDocumentEmbedded(storage, this.sharedContext);
501+
database.init(config);
502502
String user;
503503
if (getUser() != null) {
504504
user = getUser().getName();

core/src/main/java/com/orientechnologies/orient/core/index/ORecreateIndexesTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public ORecreateIndexesTask(OIndexManagerShared indexManager, OSharedContext ctx
3030
public void run() {
3131
try {
3232
final ODatabaseDocumentEmbedded newDb =
33-
new ODatabaseDocumentEmbedded((OStorage) ctx.getStorage());
33+
new ODatabaseDocumentEmbedded((OStorage) ctx.getStorage(), ctx);
3434
newDb.activateOnCurrentThread();
35-
newDb.init(null, ctx);
35+
newDb.init(null);
3636
newDb.internalOpen("admin", "nopass", false);
3737

3838
final Collection<ODocument> indexesToRebuild;

distributed/src/main/java/com/orientechnologies/orient/distributed/db/OrientDBDistributed.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ protected OSharedContext createSharedContext(OStorage storage) {
242242

243243
protected ODatabaseDocumentEmbedded newSessionInstance(OStorage storage, OrientDBConfig config) {
244244
ODatabaseDocumentEmbedded embedded;
245+
OSharedContext sharedContext = getOrCreateSharedContext(storage);
245246
if (isDistributedDisabled(storage.getName())) {
246-
embedded = new ODatabaseDocumentEmbedded(storage);
247-
embedded.init(config, getOrCreateSharedContext(storage));
247+
embedded = new ODatabaseDocumentEmbedded(storage, sharedContext);
248+
embedded.init(config);
248249
} else {
249-
OSharedContext sharedContext = getOrCreateSharedContext(storage);
250-
embedded = new ODatabaseDocumentDistributed(storage, plugin);
251-
embedded.init(config, sharedContext);
250+
embedded = new ODatabaseDocumentDistributed(storage, sharedContext, plugin);
251+
embedded.init(config);
252252
}
253253
return embedded;
254254
}
@@ -265,13 +265,12 @@ protected ODatabaseDocumentEmbedded newCreateSessionInstance(
265265
OStorage storage, OrientDBConfig config) {
266266
ODatabaseDocumentEmbedded embedded;
267267

268+
OSharedContext sharedContext = getOrCreateSharedContext(storage);
268269
if (isDistributedDisabled(storage.getName())) {
269-
embedded = new ODatabaseDocumentEmbedded(storage);
270-
OSharedContext sharedContext = getOrCreateSharedContext(storage);
270+
embedded = new ODatabaseDocumentEmbedded(storage, sharedContext);
271271
embedded.internalCreate(config, sharedContext);
272272
} else {
273-
embedded = new ODatabaseDocumentDistributed(storage, plugin);
274-
OSharedContext sharedContext = getOrCreateSharedContext(storage);
273+
embedded = new ODatabaseDocumentDistributed(storage, sharedContext, plugin);
275274
embedded.internalCreate(config, sharedContext);
276275
// getOrInitDistributedConfiguration(storage.getName());
277276
}
@@ -282,11 +281,11 @@ protected ODatabaseDocumentEmbedded newPooledSessionInstance(
282281
ODatabasePoolInternal pool, OStorage storage, OSharedContext sharedContext) {
283282
ODatabaseDocumentEmbedded embedded;
284283
if (isDistributedDisabled(storage.getName())) {
285-
embedded = new ODatabaseDocumentEmbeddedPooled(pool, storage);
286-
embedded.init(pool.getConfig(), getOrCreateSharedContext(storage));
284+
embedded = new ODatabaseDocumentEmbeddedPooled(pool, storage, sharedContext);
285+
embedded.init(pool.getConfig());
287286
} else {
288-
embedded = new ODatabaseDocumentDistributedPooled(pool, storage, plugin);
289-
embedded.init(pool.getConfig(), getOrCreateSharedContext(storage));
287+
embedded = new ODatabaseDocumentDistributedPooled(pool, storage, sharedContext, plugin);
288+
embedded.init(pool.getConfig());
290289
// getOrInitDistributedConfiguration(storage.getName());
291290
}
292291
return embedded;

distributed/src/main/java/com/orientechnologies/orient/server/distributed/impl/ODatabaseDocumentDistributed.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ public class ODatabaseDocumentDistributed extends ODatabaseDocumentEmbedded {
117117

118118
private final ODistributedPlugin distributedManager;
119119

120-
public ODatabaseDocumentDistributed(OStorage storage, ODistributedPlugin distributedPlugin) {
121-
super(storage);
120+
public ODatabaseDocumentDistributed(
121+
OStorage storage, OSharedContext sharedContext, ODistributedPlugin distributedPlugin) {
122+
super(storage, sharedContext);
122123
this.distributedManager = distributedPlugin;
123124
}
124125

@@ -179,8 +180,8 @@ public boolean isDistributed() {
179180
@Override
180181
public ODatabaseDocumentInternal copy() {
181182
ODatabaseDocumentDistributed database =
182-
new ODatabaseDocumentDistributed(getStorage(), distributedManager);
183-
database.init(getConfig(), getSharedContext());
183+
new ODatabaseDocumentDistributed(getStorage(), getSharedContext(), distributedManager);
184+
database.init(getConfig());
184185
String user;
185186
if (getUser() != null) {
186187
user = getUser().getName();
@@ -267,10 +268,10 @@ public ODistributedResponse executeTaskOnNode(ORemoteTask task, String nodeName)
267268
}
268269

269270
@Override
270-
public void init(OrientDBConfig config, OSharedContext sharedContext) {
271+
public void init(OrientDBConfig config) {
271272
OScenarioThreadLocal.executeAsDistributed(
272273
() -> {
273-
super.init(config, sharedContext);
274+
super.init(config);
274275
return null;
275276
});
276277
}

distributed/src/main/java/com/orientechnologies/orient/server/distributed/impl/ODatabaseDocumentDistributedPooled.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
44
import com.orientechnologies.orient.core.db.ODatabasePoolInternal;
55
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
6+
import com.orientechnologies.orient.core.db.OSharedContext;
67
import com.orientechnologies.orient.core.storage.OStorage;
78

89
/** Created by tglman on 30/03/17. */
@@ -11,8 +12,11 @@ public class ODatabaseDocumentDistributedPooled extends ODatabaseDocumentDistrib
1112
private ODatabasePoolInternal pool;
1213

1314
public ODatabaseDocumentDistributedPooled(
14-
ODatabasePoolInternal pool, OStorage storage, ODistributedPlugin distributedPlugin) {
15-
super(storage, distributedPlugin);
15+
ODatabasePoolInternal pool,
16+
OStorage storage,
17+
OSharedContext sharedContext,
18+
ODistributedPlugin distributedPlugin) {
19+
super(storage, sharedContext, distributedPlugin);
1620
this.pool = pool;
1721
}
1822

0 commit comments

Comments
 (0)