use of com.orientechnologies.common.listener.OProgressListener in project orientdb by orientechnologies.
the class AutoShardingTest method beforeMethod.
@BeforeMethod
public void beforeMethod() throws Exception {
super.beforeMethod();
hashFunction.setValueSerializer(new OIntegerSerializer());
if (database.getMetadata().getSchema().existsClass("AutoShardingTest"))
database.getMetadata().getSchema().dropClass("AutoShardingTest");
cls = database.getMetadata().getSchema().createClass("AutoShardingTest");
cls.createProperty("id", OType.INTEGER);
idx = cls.createIndex("testAutoSharding", OClass.INDEX_TYPE.NOTUNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "id" });
clusterIds = cls.getClusterIds();
}
use of com.orientechnologies.common.listener.OProgressListener in project orientdb by orientechnologies.
the class ODatabaseImport method importClusters.
private long importClusters() throws ParseException, IOException {
listener.onMessage("\nImporting clusters...");
long total = 0;
jsonReader.readNext(OJSONReader.BEGIN_COLLECTION);
boolean recreateManualIndex = false;
if (exporterVersion <= 4) {
removeDefaultClusters();
recreateManualIndex = true;
}
final Set<String> indexesToRebuild = new HashSet<String>();
@SuppressWarnings("unused") ORecordId rid = null;
while (jsonReader.lastChar() != ']') {
jsonReader.readNext(OJSONReader.BEGIN_OBJECT);
String name = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"name\"").readString(OJSONReader.COMMA_SEPARATOR);
if (name.length() == 0)
name = null;
name = OClassImpl.decodeClassName(name);
if (name != null)
// CHECK IF THE CLUSTER IS INCLUDED
if (includeClusters != null) {
if (!includeClusters.contains(name)) {
jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
continue;
}
} else if (excludeClusters != null) {
if (excludeClusters.contains(name)) {
jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
continue;
}
}
int id;
if (exporterVersion < 9) {
id = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"id\"").readInteger(OJSONReader.COMMA_SEPARATOR);
String type = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"type\"").readString(OJSONReader.NEXT_IN_OBJECT);
} else
id = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"id\"").readInteger(OJSONReader.NEXT_IN_OBJECT);
String type;
if (jsonReader.lastChar() == ',')
type = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"type\"").readString(OJSONReader.NEXT_IN_OBJECT);
else
type = "PHYSICAL";
if (jsonReader.lastChar() == ',') {
rid = new ORecordId(jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"rid\"").readString(OJSONReader.NEXT_IN_OBJECT));
} else
rid = null;
listener.onMessage("\n- Creating cluster " + (name != null ? "'" + name + "'" : "NULL") + "...");
int clusterId = name != null ? database.getClusterIdByName(name) : -1;
if (clusterId == -1) {
// CREATE IT
if (!preserveClusterIDs)
clusterId = database.addCluster(name);
else {
clusterId = database.addCluster(name, id, null);
assert clusterId == id;
}
}
if (clusterId != id) {
if (!preserveClusterIDs) {
if (database.countClusterElements(clusterId - 1) == 0) {
listener.onMessage("Found previous version: migrating old clusters...");
database.dropCluster(name, true);
database.addCluster("temp_" + clusterId, null);
clusterId = database.addCluster(name);
} else
throw new OConfigurationException("Imported cluster '" + name + "' has id=" + clusterId + " different from the original: " + id + ". To continue the import drop the cluster '" + database.getClusterNameById(clusterId - 1) + "' that has " + database.countClusterElements(clusterId - 1) + " records");
} else {
database.dropCluster(clusterId, false);
database.addCluster(name, id, null);
}
}
if (name != null && !(name.equalsIgnoreCase(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME) || name.equalsIgnoreCase(OMetadataDefault.CLUSTER_INTERNAL_NAME) || name.equalsIgnoreCase(OMetadataDefault.CLUSTER_INDEX_NAME))) {
if (!merge)
database.command(new OCommandSQL("truncate cluster `" + name + "`")).execute();
for (OIndex existingIndex : database.getMetadata().getIndexManager().getIndexes()) {
if (existingIndex.getClusters().contains(name)) {
indexesToRebuild.add(existingIndex.getName());
}
}
}
listener.onMessage("OK, assigned id=" + clusterId);
total++;
jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
}
jsonReader.readNext(OJSONReader.COMMA_SEPARATOR);
listener.onMessage("\nRebuilding indexes of truncated clusters ...");
for (final String indexName : indexesToRebuild) database.getMetadata().getIndexManager().getIndex(indexName).rebuild(new OProgressListener() {
private long last = 0;
@Override
public void onBegin(Object iTask, long iTotal, Object metadata) {
listener.onMessage("\n- Cluster content was updated: rebuilding index '" + indexName + "'...");
}
@Override
public boolean onProgress(Object iTask, long iCounter, float iPercent) {
final long now = System.currentTimeMillis();
if (last == 0)
last = now;
else if (now - last > 1000) {
listener.onMessage(String.format("\nIndex '%s' is rebuilding (%.2f/100)", indexName, iPercent));
last = now;
}
return true;
}
@Override
public void onCompletition(Object iTask, boolean iSucceed) {
listener.onMessage(" Index " + indexName + " was successfully rebuilt.");
}
});
listener.onMessage("\nDone " + indexesToRebuild.size() + " indexes were rebuilt.");
if (recreateManualIndex) {
database.addCluster(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME);
database.getMetadata().getIndexManager().create();
listener.onMessage("\nManual index cluster was recreated.");
}
listener.onMessage("\nDone. Imported " + total + " clusters");
if (database.load(new ORecordId(database.getStorage().getConfiguration().indexMgrRecordId)) == null) {
ODocument indexDocument = new ODocument();
indexDocument.save(OMetadataDefault.CLUSTER_INTERNAL_NAME);
database.getStorage().getConfiguration().indexMgrRecordId = indexDocument.getIdentity().toString();
database.getStorage().getConfiguration().update();
}
return total;
}
use of com.orientechnologies.common.listener.OProgressListener in project orientdb by orientechnologies.
the class IndexManagerTest method createCompositeIndexTestWithListener.
@Test
public void createCompositeIndexTestWithListener() {
final AtomicInteger atomicInteger = new AtomicInteger(0);
final OProgressListener progressListener = new OProgressListener() {
@Override
public void onBegin(final Object iTask, final long iTotal, Object metadata) {
atomicInteger.incrementAndGet();
}
@Override
public boolean onProgress(final Object iTask, final long iCounter, final float iPercent) {
return true;
}
@Override
public void onCompletition(final Object iTask, final boolean iSucceed) {
atomicInteger.incrementAndGet();
}
};
final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
final OIndex result = indexManager.createIndex("compositetwo", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OCompositeIndexDefinition(CLASS_NAME, Arrays.asList(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER), new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING), new OPropertyIndexDefinition(CLASS_NAME, "fThree", OType.BOOLEAN)), -1), new int[] { database.getClusterIdByName(CLASS_NAME) }, progressListener, null);
assertEquals(result.getName(), "compositetwo");
assertEquals(atomicInteger.get(), 2);
indexManager.reload();
assertEquals(database.getMetadata().getIndexManager().getClassIndex(CLASS_NAME, "compositetwo").getName(), result.getName());
}
use of com.orientechnologies.common.listener.OProgressListener in project orientdb by orientechnologies.
the class ClassIndexTest method createCompositeIndexTestWithListener.
@Test
public void createCompositeIndexTestWithListener() {
final AtomicInteger atomicInteger = new AtomicInteger(0);
final OProgressListener progressListener = new OProgressListener() {
@Override
public void onBegin(final Object iTask, final long iTotal, Object metadata) {
atomicInteger.incrementAndGet();
}
@Override
public boolean onProgress(final Object iTask, final long iCounter, final float iPercent) {
return true;
}
@Override
public void onCompletition(final Object iTask, final boolean iSucceed) {
atomicInteger.incrementAndGet();
}
};
final OIndex result = oClass.createIndex("ClassIndexTestCompositeTwo", OClass.INDEX_TYPE.UNIQUE.toString(), progressListener, new ODocument().fields("ignoreNullValues", true), new String[] { "fOne", "fTwo", "fThree" });
assertEquals(result.getName(), "ClassIndexTestCompositeTwo");
assertEquals(oClass.getClassIndex("ClassIndexTestCompositeTwo").getName(), result.getName());
assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeTwo").getName(), result.getName());
assertEquals(atomicInteger.get(), 2);
}
Aggregations