}
private void importIndexes() throws IOException, ParseException {
listener.onMessage("\nImporting indexes ...");
OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
indexManager.reload();
jsonReader.readNext(OJSONReader.BEGIN_COLLECTION);
int n = 0;
while (jsonReader.lastChar() != ']') {
jsonReader.readNext(OJSONReader.BEGIN_OBJECT);
String blueprintsIndexClass = null;
String indexName = null;
String indexType = null;
Set<String> clustersToIndex = new HashSet<String>();
OIndexDefinition indexDefinition = null;
ODocument metadata = null;
while (jsonReader.lastChar() != '}') {
final String fieldName = jsonReader.readString(OJSONReader.FIELD_ASSIGNMENT);
if (fieldName.equals("name"))
indexName = jsonReader.readString(OJSONReader.NEXT_IN_OBJECT);
else if (fieldName.equals("type"))
indexType = jsonReader.readString(OJSONReader.NEXT_IN_OBJECT);
else if (fieldName.equals("clustersToIndex"))
clustersToIndex = importClustersToIndex();
else if (fieldName.equals("definition")) {
indexDefinition = importIndexDefinition();
jsonReader.readNext(OJSONReader.NEXT_IN_OBJECT);
} else if (fieldName.equals("metadata")) {
String jsonMetadata = jsonReader.readString(OJSONReader.END_OBJECT, true);
metadata = new ODocument().fromJSON(jsonMetadata);
jsonReader.readNext(OJSONReader.NEXT_IN_OBJECT);
} else if (fieldName.equals("blueprintsIndexClass"))
blueprintsIndexClass = jsonReader.readString(OJSONReader.NEXT_IN_OBJECT);
}
if (indexName == null)
throw new IllegalArgumentException("Index name is missing");
jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
// drop automatically created indexes
if (!indexName.equalsIgnoreCase(EXPORT_IMPORT_MAP_NAME)) {
listener.onMessage("\n- Index '" + indexName + "'...");
indexManager.dropIndex(indexName);
indexesToRebuild.remove(indexName.toLowerCase());
int[] clusterIdsToIndex = new int[clustersToIndex.size()];
int i = 0;
for (final String clusterName : clustersToIndex) {
clusterIdsToIndex[i] = database.getClusterIdByName(clusterName);
i++;
}
OIndex index = indexManager.createIndex(indexName, indexType, indexDefinition, clusterIdsToIndex, null, metadata);
if (blueprintsIndexClass != null) {
ODocument configuration = index.getConfiguration();
configuration.field("blueprintsIndexClass", blueprintsIndexClass);
indexManager.save();
}
n++;
listener.onMessage("OK");