Skip to content

Commit

Permalink
Fixed issue #4614
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jul 22, 2015
1 parent 1c0141a commit 8f9869e
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 23 deletions.
Expand Up @@ -42,8 +42,18 @@
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.type.tree.provider.OMVRBTreeMapProvider;

import java.io.*;
import java.util.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream;

Expand Down Expand Up @@ -483,8 +493,8 @@ private void exportSchema() throws IOException {
writer.writeAttribute(0, false, "oversize", cls.getClassOverSize());
if (cls.isStrictMode())
writer.writeAttribute(0, false, "strictMode", cls.isStrictMode());
if (cls.getSuperClass() != null)
writer.writeAttribute(0, false, "super-class", cls.getSuperClass().getName());
if (!cls.getSuperClasses().isEmpty())
writer.writeAttribute(0, false, "super-classes", cls.getSuperClassesNames());
if (cls.getShortName() != null)
writer.writeAttribute(0, false, "short-name", cls.getShortName());
if (cls.isAbstract())
Expand Down
Expand Up @@ -34,12 +34,22 @@
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.index.*;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexDefinition;
import com.orientechnologies.orient.core.index.OIndexFactory;
import com.orientechnologies.orient.core.index.OIndexManagerProxy;
import com.orientechnologies.orient.core.index.OIndexes;
import com.orientechnologies.orient.core.index.ORuntimeKeyIndexDefinition;
import com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition;
import com.orientechnologies.orient.core.index.hashindex.local.OMurmurHash3HashFunction;
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
import com.orientechnologies.orient.core.metadata.OMetadataDefault;
import com.orientechnologies.orient.core.metadata.function.OFunction;
import com.orientechnologies.orient.core.metadata.schema.*;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OClassImpl;
import com.orientechnologies.orient.core.metadata.schema.OPropertyImpl;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.metadata.security.ORole;
import com.orientechnologies.orient.core.metadata.security.OSecurityShared;
import com.orientechnologies.orient.core.metadata.security.OUser;
Expand All @@ -59,11 +69,25 @@
import com.orientechnologies.orient.core.type.tree.provider.OMVRBTreeRIDProvider;
import com.orientechnologies.orient.core.version.OVersionFactory;

import java.io.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.*;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.zip.GZIPInputStream;

/**
Expand All @@ -76,7 +100,7 @@ public class ODatabaseImport extends ODatabaseImpExpAbstract {
public static final int IMPORT_RECORD_DUMP_LAP_EVERY_MS = 5000;

private Map<OPropertyImpl, String> linkedClasses = new HashMap<OPropertyImpl, String>();
private Map<OClass, String> superClasses = new HashMap<OClass, String>();
private Map<OClass, List<String>> superClasses = new HashMap<OClass, List<String>>();
private OJSONReader jsonReader;
private ORecord record;
private boolean schemaImported = false;
Expand Down Expand Up @@ -811,8 +835,26 @@ private void importSchema() throws IOException, ParseException {
final String shortName = jsonReader.readString(OJSONReader.NEXT_IN_OBJECT);
cls.setShortName(shortName);
} else if (value.equals("\"super-class\"")) {
// @compatibility <2.1 SINGLE CLASS ONLY
final String classSuper = jsonReader.readString(OJSONReader.NEXT_IN_OBJECT);
superClasses.put(cls, classSuper);
final List<String> superClassNames = new ArrayList<String>();
superClassNames.add(classSuper);
superClasses.put(cls, superClassNames);
} else if (value.equals("\"super-classes\"")) {
// MULTIPLE CLASSES
jsonReader.readNext(OJSONReader.BEGIN_COLLECTION);

final List<String> superClassNames = new ArrayList<String>();
while (jsonReader.lastChar() != ']') {
jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);

final String clsName = jsonReader.getValue();

superClassNames.add(OStringSerializerHelper.getStringContent(clsName));
}
jsonReader.readNext(OJSONReader.NEXT_IN_OBJECT);

superClasses.put(cls, superClassNames);
} else if (value.equals("\"properties\"")) {
// GET PROPERTIES
jsonReader.readNext(OJSONReader.BEGIN_COLLECTION);
Expand Down Expand Up @@ -841,8 +883,10 @@ private void importSchema() throws IOException, ParseException {
} while (jsonReader.lastChar() == ',');

// REBUILD ALL THE INHERITANCE
for (Map.Entry<OClass, String> entry : superClasses.entrySet())
entry.getKey().setSuperClass(database.getMetadata().getSchema().getClass(entry.getValue()));
for (Map.Entry<OClass, List<String>> entry : superClasses.entrySet())
for (String s : entry.getValue()) {
entry.getKey().addSuperClass(database.getMetadata().getSchema().getClass(s));
}

// SET ALL THE LINKED CLASSES
for (Map.Entry<OPropertyImpl, String> entry : linkedClasses.entrySet()) {
Expand Down Expand Up @@ -1362,7 +1406,8 @@ else if (fieldName.equals("definition")) {
i++;
}

OIndex index = indexManager.createIndex(indexName, indexType, indexDefinition, clusterIdsToIndex, null, metadata,indexAlgorithm);
OIndex index = indexManager.createIndex(indexName, indexType, indexDefinition, clusterIdsToIndex, null, metadata,
indexAlgorithm);
if (blueprintsIndexClass != null) {
ODocument configuration = index.getConfiguration();
configuration.field("blueprintsIndexClass", blueprintsIndexClass);
Expand Down
@@ -1,15 +1,14 @@
package com.orientechnologies.orient.core.db.tool;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class TestSchemaImportExport {

Expand Down Expand Up @@ -47,4 +46,37 @@ public void testExportImportCustomData() throws IOException {
db1.drop();
}
}

@Test
public void testExportImportMultipleInheritance() throws IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + TestSchemaImportExport.class.getSimpleName()
+ "MultipleInheritance");
db.create();
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.addSuperClass(db.getMetadata().getSchema().getClass("ORestricted"));
clazz.addSuperClass(db.getMetadata().getSchema().getClass("OIdentity"));

ODatabaseExport exp = new ODatabaseExport(db, output, new MockOutputListener());
exp.exportDatabase();
} finally {
db.drop();
}

ODatabaseDocumentTx db1 = new ODatabaseDocumentTx("memory:imp_" + TestSchemaImportExport.class.getSimpleName()
+ "MultipleInheritance");
db1.create();
try {
ODatabaseImport imp = new ODatabaseImport(db1, new ByteArrayInputStream(output.toByteArray()), new MockOutputListener());
imp.importDatabase();
db1.close();
db1.open("admin", "admin");
OClass clas1 = db1.getMetadata().getSchema().getClass("Test");
Assert.assertTrue(clas1.isSubClassOf("OIdentity"));
Assert.assertTrue(clas1.isSubClassOf("ORestricted"));
} finally {
db1.drop();
}
}
}
Expand Up @@ -20,8 +20,6 @@
import com.orientechnologies.common.console.annotation.ConsoleParameter;
import com.orientechnologies.orient.console.OConsoleDatabaseApp;
import com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException;
import com.orientechnologies.orient.core.config.OStorageEntryConfiguration;
import com.orientechnologies.orient.core.db.ODatabase;
import com.orientechnologies.orient.core.db.tool.ODatabaseImportException;
import com.orientechnologies.orient.core.exception.OStorageException;
import com.orientechnologies.orient.core.serialization.serializer.OStringSerializerHelper;
Expand Down Expand Up @@ -113,7 +111,7 @@ public void importDatabase(@ConsoleParameter(name = "options", description = "Im
try {
final Map<String, List<String>> opts = parseOptions(options);

final OrientGraph g = new OrientGraph((com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) currentDatabase);
final OrientGraph g = new OrientGraph(currentDatabase);
g.setUseLog(false);
g.setWarnOnForceClosingTx(false);
new OGraphMLReader(g).setOptions(opts).inputGraph(g, fileName);
Expand Down

0 comments on commit 8f9869e

Please sign in to comment.