Skip to content

Commit daa6ccf

Browse files
committed
Added schema synchronize in ObjectDatabase:
1) changed OMetadata as interface 2) added OMetadataDefault implementation (old OMetadata class) 3) created OObjectMetadata and OOBjectSchemaProxy as wrappers 4) moved schema object management in OObjectSchemaProxy class 5) added schema synchronizing (creates schema and classes of registered entities if non existent)
1 parent 44879df commit daa6ccf

32 files changed

Lines changed: 661 additions & 427 deletions

core/src/main/java/com/orientechnologies/orient/core/cache/OLevel1RecordCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.orientechnologies.orient.core.cache;
1717

18-
import static com.orientechnologies.orient.core.metadata.OMetadata.CLUSTER_INDEX_NAME;
18+
import static com.orientechnologies.orient.core.metadata.OMetadataDefault.CLUSTER_INDEX_NAME;
1919

2020
import com.orientechnologies.orient.core.Orient;
2121
import com.orientechnologies.orient.core.config.OGlobalConfiguration;

core/src/main/java/com/orientechnologies/orient/core/command/script/OScriptDocumentDatabaseWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public ODocument save(final Map<String, Object> iObject) {
203203
}
204204

205205
public ODocument save(final String iString) {
206-
//return database.save((ORecordInternal<?>) new ODocument().fromJSON(iString));
206+
// return database.save((ORecordInternal<?>) new ODocument().fromJSON(iString));
207207
return database.save((ORecordInternal<?>) new ODocument().fromJSON(iString, true));
208208
}
209209

@@ -294,7 +294,7 @@ public <RET extends ODatabaseRecord> RET setValidationEnabled(boolean iValue) {
294294
public OUser getUser() {
295295
return database.getUser();
296296
}
297-
297+
298298
public void setUser(OUser user) {
299299
database.setUser(user);
300300
}

core/src/main/java/com/orientechnologies/orient/core/config/OGlobalConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import com.orientechnologies.orient.core.OConstants;
2929
import com.orientechnologies.orient.core.Orient;
3030
import com.orientechnologies.orient.core.cache.ODefaultCache;
31-
import com.orientechnologies.orient.core.metadata.OMetadata;
31+
import com.orientechnologies.orient.core.metadata.OMetadataDefault;
3232
import com.orientechnologies.orient.core.storage.fs.OMMapManagerOld;
3333

3434
/**
@@ -177,7 +177,7 @@ public void change(final Object iCurrentValue, final Object iNewValue) {
177177

178178
NON_TX_CLUSTERS_SYNC_IMMEDIATELY("nonTX.clusters.sync.immediately",
179179
"List of clusters to sync immediately after update separated by commas. Can be useful for manual index", String.class,
180-
OMetadata.CLUSTER_MANUAL_INDEX_NAME),
180+
OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME),
181181

182182
// TRANSACTIONS
183183
TX_USE_LOG("tx.useLog", "Transactions use log file to store temporary data to be rolled back in case of crash", Boolean.class,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public enum OPERATION_MODE {
8181
* Set user for current database instance
8282
*/
8383
public void setUser(OUser user);
84-
84+
8585
/**
8686
* Loads the entity and return it.
8787
*

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public OUser getUser() {
154154
public void setUser(OUser user) {
155155
underlying.setUser(user);
156156
}
157-
157+
158158
public OMetadata getMetadata() {
159159
return underlying.getMetadata();
160160
}
@@ -273,12 +273,12 @@ public <RET extends ORecordInternal<?>> RET save(final ORecordInternal<?> iRecor
273273
return (RET) underlying.save(iRecord, iClusterName);
274274
}
275275

276-
@Override
277-
public boolean updatedReplica(ORecordInternal<?> iObject) {
278-
return underlying.updatedReplica(iObject);
279-
}
276+
@Override
277+
public boolean updatedReplica(ORecordInternal<?> iObject) {
278+
return underlying.updatedReplica(iObject);
279+
}
280280

281-
public <RET extends ORecordInternal<?>> RET save(final ORecordInternal<?> iRecord, final OPERATION_MODE iMode,
281+
public <RET extends ORecordInternal<?>> RET save(final ORecordInternal<?> iRecord, final OPERATION_MODE iMode,
282282
boolean iForceCreate, final ORecordCallback<? extends Number> iRecordCreatedCallback,
283283
ORecordCallback<ORecordVersion> iRecordUpdatedCallback) {
284284
return (RET) underlying.save(iRecord, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);

core/src/main/java/com/orientechnologies/orient/core/db/record/ODatabaseRecordAbstract.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import com.orientechnologies.orient.core.index.OClassIndexManager;
5454
import com.orientechnologies.orient.core.index.OIndexManager;
5555
import com.orientechnologies.orient.core.iterator.ORecordIteratorCluster;
56-
import com.orientechnologies.orient.core.metadata.OMetadata;
56+
import com.orientechnologies.orient.core.metadata.OMetadataDefault;
5757
import com.orientechnologies.orient.core.metadata.function.OFunctionTrigger;
5858
import com.orientechnologies.orient.core.metadata.security.ODatabaseSecurityResources;
5959
import com.orientechnologies.orient.core.metadata.security.ORestrictedAccessHook;
@@ -81,7 +81,7 @@
8181
@SuppressWarnings("unchecked")
8282
public abstract class ODatabaseRecordAbstract extends ODatabaseWrapperAbstract<ODatabaseRaw> implements ODatabaseRecord {
8383

84-
private OMetadata metadata;
84+
private OMetadataDefault metadata;
8585
private OUser user;
8686
private static final String DEF_RECORD_FORMAT = "csv";
8787
private byte recordType;
@@ -119,7 +119,7 @@ public <DB extends ODatabase> DB open(final String iUserName, final String iUser
119119
super.open(iUserName, iUserPassword);
120120
level1Cache.startup();
121121

122-
metadata = new OMetadata();
122+
metadata = new OMetadataDefault();
123123
metadata.load();
124124

125125
recordFormat = DEF_RECORD_FORMAT;
@@ -191,7 +191,7 @@ public <DB extends ODatabase> DB create() {
191191
}
192192

193193
// CREATE THE DEFAULT SCHEMA WITH DEFAULT USER
194-
metadata = new OMetadata();
194+
metadata = new OMetadataDefault();
195195
metadata.create();
196196

197197
user = getMetadata().getSecurity().getUser(OUser.ADMIN);
@@ -528,7 +528,7 @@ public long countClusterElements(final String iClusterName) {
528528
return super.countClusterElements(iClusterName);
529529
}
530530

531-
public OMetadata getMetadata() {
531+
public OMetadataDefault getMetadata() {
532532
checkOpeness();
533533
return metadata;
534534
}

core/src/main/java/com/orientechnologies/orient/core/db/tool/ODatabaseCompare.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import com.orientechnologies.orient.core.index.OIndexManager;
3737
import com.orientechnologies.orient.core.index.hashindex.local.OLocalHashTable;
3838
import com.orientechnologies.orient.core.index.hashindex.local.OMurmurHash3HashFunction;
39-
import com.orientechnologies.orient.core.metadata.OMetadata;
39+
import com.orientechnologies.orient.core.metadata.OMetadataDefault;
4040
import com.orientechnologies.orient.core.metadata.schema.OType;
4141
import com.orientechnologies.orient.core.record.impl.ODocument;
4242
import com.orientechnologies.orient.core.record.impl.ODocumentHelper;
@@ -91,8 +91,8 @@ public ODatabaseCompare(String iDb1URL, String iDb2URL, final String userName, f
9191

9292
// exclude automatically generated clusters
9393
excludeClusters.add("orids");
94-
excludeClusters.add(OMetadata.CLUSTER_INDEX_NAME);
95-
excludeClusters.add(OMetadata.CLUSTER_MANUAL_INDEX_NAME);
94+
excludeClusters.add(OMetadataDefault.CLUSTER_INDEX_NAME);
95+
excludeClusters.add(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME);
9696
}
9797

9898
public boolean isCompareEntriesForAutomaticIndexes() {

core/src/main/java/com/orientechnologies/orient/core/db/tool/ODatabaseImpExpAbstract.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.orientechnologies.common.log.OLogManager;
2424
import com.orientechnologies.orient.core.command.OCommandOutputListener;
2525
import com.orientechnologies.orient.core.db.record.ODatabaseRecord;
26-
import com.orientechnologies.orient.core.metadata.OMetadata;
26+
import com.orientechnologies.orient.core.metadata.OMetadataDefault;
2727
import com.orientechnologies.orient.core.serialization.serializer.OStringSerializerHelper;
2828

2929
/**
@@ -62,8 +62,8 @@ public ODatabaseImpExpAbstract(final ODatabaseRecord iDatabase, final String iFi
6262

6363
listener = iListener;
6464
excludeClusters = new LinkedHashSet<String>();
65-
excludeClusters.add(OMetadata.CLUSTER_INDEX_NAME);
66-
excludeClusters.add(OMetadata.CLUSTER_MANUAL_INDEX_NAME);
65+
excludeClusters.add(OMetadataDefault.CLUSTER_INDEX_NAME);
66+
excludeClusters.add(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME);
6767
}
6868

6969
public ODatabaseImpExpAbstract setOptions(final String iOptions) {

core/src/main/java/com/orientechnologies/orient/core/db/tool/ODatabaseImport.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import com.orientechnologies.orient.core.index.hashindex.local.OLocalHashTable;
4949
import com.orientechnologies.orient.core.index.hashindex.local.OMurmurHash3HashFunction;
5050
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
51-
import com.orientechnologies.orient.core.metadata.OMetadata;
51+
import com.orientechnologies.orient.core.metadata.OMetadataDefault;
5252
import com.orientechnologies.orient.core.metadata.function.OFunction;
5353
import com.orientechnologies.orient.core.metadata.schema.OClass;
5454
import com.orientechnologies.orient.core.metadata.schema.OClassImpl;
@@ -591,8 +591,8 @@ private long importClusters() throws ParseException, IOException {
591591
}
592592

593593
if (name != null
594-
&& !(name.equalsIgnoreCase(OMetadata.CLUSTER_MANUAL_INDEX_NAME) || name.equalsIgnoreCase(OMetadata.CLUSTER_INTERNAL_NAME) || name
595-
.equalsIgnoreCase(OMetadata.CLUSTER_INDEX_NAME)))
594+
&& !(name.equalsIgnoreCase(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME) || name.equalsIgnoreCase(OMetadataDefault.CLUSTER_INTERNAL_NAME) || name
595+
.equalsIgnoreCase(OMetadataDefault.CLUSTER_INDEX_NAME)))
596596
database.getStorage().getClusterById(clusterId).truncate();
597597

598598
listener.onMessage("OK, assigned id=" + clusterId);
@@ -604,7 +604,7 @@ private long importClusters() throws ParseException, IOException {
604604
jsonReader.readNext(OJSONReader.COMMA_SEPARATOR);
605605

606606
if (recreateManualIndex) {
607-
database.addCluster(OStorage.CLUSTER_TYPE.PHYSICAL.toString(), OMetadata.CLUSTER_MANUAL_INDEX_NAME, null, null);
607+
database.addCluster(OStorage.CLUSTER_TYPE.PHYSICAL.toString(), OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME, null, null);
608608
database.getMetadata().getIndexManager().create();
609609

610610
listener.onMessage("\nManual index cluster was recreated.");
@@ -614,7 +614,7 @@ private long importClusters() throws ParseException, IOException {
614614

615615
if (database.load(new ORecordId(database.getStorage().getConfiguration().indexMgrRecordId)) == null) {
616616
ODocument indexDocument = new ODocument();
617-
indexDocument.save(OMetadata.CLUSTER_INTERNAL_NAME);
617+
indexDocument.save(OMetadataDefault.CLUSTER_INTERNAL_NAME);
618618

619619
database.getStorage().getConfiguration().indexMgrRecordId = indexDocument.getIdentity().toString();
620620
database.getStorage().getConfiguration().update();
@@ -632,7 +632,7 @@ protected void removeDefaultClusters() {
632632

633633
// In v4 new cluster for manual indexes has been implemented. To keep database consistent we should shift back
634634
// all clusters and recreate cluster for manual indexes in the end.
635-
database.dropCluster(OMetadata.CLUSTER_MANUAL_INDEX_NAME, true);
635+
database.dropCluster(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME, true);
636636

637637
final OSchema schema = database.getMetadata().getSchema();
638638
if (schema.existsClass(OUser.CLASS_NAME))
@@ -737,16 +737,16 @@ record = ORecordSerializerJSON.INSTANCE.fromString(value, record, null);
737737

738738
if (exporterVersion >= 3) {
739739
int oridsId = database.getClusterIdByName(OMVRBTreeRIDProvider.PERSISTENT_CLASS_NAME);
740-
int indexId = database.getClusterIdByName(OMetadata.CLUSTER_INDEX_NAME);
740+
int indexId = database.getClusterIdByName(OMetadataDefault.CLUSTER_INDEX_NAME);
741741

742742
if (record.getIdentity().getClusterId() == indexId || record.getIdentity().getClusterId() == oridsId)
743743
// JUMP INDEX RECORDS
744744
return null;
745745
}
746746

747-
final int manualIndexCluster = database.getClusterIdByName(OMetadata.CLUSTER_MANUAL_INDEX_NAME);
748-
final int internalCluster = database.getClusterIdByName(OMetadata.CLUSTER_INTERNAL_NAME);
749-
final int indexCluster = database.getClusterIdByName(OMetadata.CLUSTER_INDEX_NAME);
747+
final int manualIndexCluster = database.getClusterIdByName(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME);
748+
final int internalCluster = database.getClusterIdByName(OMetadataDefault.CLUSTER_INTERNAL_NAME);
749+
final int indexCluster = database.getClusterIdByName(OMetadataDefault.CLUSTER_INDEX_NAME);
750750

751751
if (exporterVersion >= 4) {
752752
if (record.getIdentity().getClusterId() == manualIndexCluster)
@@ -893,8 +893,8 @@ private void rewriteLinksInImportedDocuments() throws IOException {
893893

894894
Collection<String> clusterNames = database.getClusterNames();
895895
for (String clusterName : clusterNames) {
896-
if (OMetadata.CLUSTER_INDEX_NAME.equals(clusterName) || OMetadata.CLUSTER_INTERNAL_NAME.equals(clusterName)
897-
|| OMetadata.CLUSTER_MANUAL_INDEX_NAME.equals(clusterName))
896+
if (OMetadataDefault.CLUSTER_INDEX_NAME.equals(clusterName) || OMetadataDefault.CLUSTER_INTERNAL_NAME.equals(clusterName)
897+
|| OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME.equals(clusterName))
898898
continue;
899899

900900
long documents = 0;

core/src/main/java/com/orientechnologies/orient/core/entity/OEntityManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.orientechnologies.orient.core.entity;
1717

1818
import java.lang.reflect.InvocationTargetException;
19+
import java.util.Collection;
1920
import java.util.HashMap;
2021
import java.util.List;
2122
import java.util.Map;
@@ -179,6 +180,10 @@ public synchronized void setClassHandler(final OEntityManagerClassHandler iClass
179180
this.classHandler = iClassHandler;
180181
}
181182

183+
public synchronized Collection<Class<?>> getRegisteredEntities() {
184+
return classHandler.getRegisteredEntities();
185+
}
186+
182187
protected Object createInstance(final Class<?> iClass) throws InstantiationException, IllegalAccessException,
183188
InvocationTargetException {
184189
return classHandler.createInstance(iClass);

0 commit comments

Comments
 (0)