Search in sources :

Example 6 with OIndexManagerProxy

use of com.orientechnologies.orient.core.index.OIndexManagerProxy in project orientdb by orientechnologies.

the class ODatabaseExport method exportIndexDefinitions.

private void exportIndexDefinitions() throws IOException {
    listener.onMessage("\nExporting index info...");
    writer.beginCollection(1, true, "indexes");
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    indexManager.reload();
    final Collection<? extends OIndex<?>> indexes = indexManager.getIndexes();
    for (OIndex<?> index : indexes) {
        if (index.getName().equals(ODatabaseImport.EXPORT_IMPORT_MAP_NAME))
            continue;
        final String clsName = index.getDefinition() != null ? index.getDefinition().getClassName() : null;
        // CHECK TO FILTER CLASS
        if (includeClasses != null) {
            if (!includeClasses.contains(clsName))
                continue;
        } else if (excludeClasses != null) {
            if (excludeClasses.contains(clsName))
                continue;
        }
        listener.onMessage("\n- Index " + index.getName() + "...");
        writer.beginObject(2, true, null);
        writer.writeAttribute(3, true, "name", index.getName());
        writer.writeAttribute(3, true, "type", index.getType());
        if (index.getAlgorithm() != null)
            writer.writeAttribute(3, true, "algorithm", index.getAlgorithm());
        if (!index.getClusters().isEmpty())
            writer.writeAttribute(3, true, "clustersToIndex", index.getClusters());
        if (index.getDefinition() != null) {
            writer.beginObject(4, true, "definition");
            writer.writeAttribute(5, true, "defClass", index.getDefinition().getClass().getName());
            writer.writeAttribute(5, true, "stream", index.getDefinition().toStream());
            writer.endObject(4, true);
        }
        final ODocument metadata = index.getMetadata();
        if (metadata != null)
            writer.writeAttribute(4, true, "metadata", metadata);
        final ODocument configuration = index.getConfiguration();
        if (configuration.field("blueprintsIndexClass") != null)
            writer.writeAttribute(4, true, "blueprintsIndexClass", configuration.field("blueprintsIndexClass"));
        writer.endObject(2, true);
        listener.onMessage("OK");
    }
    writer.endCollection(1, true);
    listener.onMessage("\nOK (" + indexes.size() + " indexes)");
}
Also used : OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OIndexManagerProxy

use of com.orientechnologies.orient.core.index.OIndexManagerProxy in project orientdb by orientechnologies.

the class OServerCommandGetDatabase method exec.

protected void exec(final OHttpRequest iRequest, final OHttpResponse iResponse, final String[] urlParts) throws InterruptedException, IOException {
    ODatabaseDocumentInternal db = null;
    try {
        if (urlParts.length > 2) {
            db = server.getDatabasePoolFactory().get(urlParts[1], urlParts[2], urlParts[3]).acquire();
        } else
            db = getProfiledDatabaseInstance(iRequest);
        final StringWriter buffer = new StringWriter();
        final OJSONWriter json = new OJSONWriter(buffer);
        json.beginObject();
        json.beginObject("server");
        json.writeAttribute("version", OConstants.ORIENT_VERSION);
        if (OConstants.getBuildNumber() != null)
            json.writeAttribute("build", OConstants.getBuildNumber());
        json.writeAttribute("osName", System.getProperty("os.name"));
        json.writeAttribute("osVersion", System.getProperty("os.version"));
        json.writeAttribute("osArch", System.getProperty("os.arch"));
        json.writeAttribute("javaVendor", System.getProperty("java.vm.vendor"));
        json.writeAttribute("javaVersion", System.getProperty("java.vm.version"));
        json.beginCollection("conflictStrategies");
        Set<String> strategies = Orient.instance().getRecordConflictStrategy().getRegisteredImplementationNames();
        int i = 0;
        for (String strategy : strategies) {
            json.write((i > 0 ? "," : "") + "\"" + strategy + "\"");
            i++;
        }
        json.endCollection();
        json.endObject();
        if (((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot().getClasses() != null) {
            json.beginCollection("classes");
            List<String> classNames = new ArrayList<String>();
            for (OClass cls : db.getMetadata().getSchema().getClasses()) classNames.add(cls.getName());
            Collections.sort(classNames);
            for (String className : classNames) {
                final OClass cls = db.getMetadata().getSchema().getClass(className);
                try {
                    exportClass(db, json, cls);
                } catch (Exception e) {
                    OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
                }
            }
            json.endCollection();
        }
        if (db.getClusterNames() != null) {
            json.beginCollection("clusters");
            OCluster cluster;
            for (String clusterName : db.getClusterNames()) {
                try {
                    cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));
                } catch (IllegalArgumentException e) {
                    OLogManager.instance().error(this, "Cluster '%s' does not exist in database", clusterName);
                    continue;
                }
                try {
                    final String conflictStrategy = cluster.getRecordConflictStrategy() != null ? cluster.getRecordConflictStrategy().getName() : null;
                    json.beginObject();
                    json.writeAttribute("id", cluster.getId());
                    json.writeAttribute("name", clusterName);
                    json.writeAttribute("records", cluster.getEntries() - cluster.getTombstonesCount());
                    json.writeAttribute("conflictStrategy", conflictStrategy);
                    json.writeAttribute("size", "-");
                    json.writeAttribute("filled", "-");
                    json.writeAttribute("maxSize", "-");
                    json.writeAttribute("files", "-");
                } catch (Exception e) {
                    json.writeAttribute("records", "? (Unauthorized)");
                }
                json.endObject();
            }
            json.endCollection();
        }
        if (db.getUser() != null) {
            json.writeAttribute("currentUser", db.getUser().getName());
        // exportSecurityInfo(db, json);
        }
        final OIndexManagerProxy idxManager = db.getMetadata().getIndexManager();
        json.beginCollection("indexes");
        for (OIndex<?> index : idxManager.getIndexes()) {
            json.beginObject();
            try {
                json.writeAttribute("name", index.getName());
                json.writeAttribute("configuration", index.getConfiguration());
            // Exclude index size because it's too costly
            // json.writeAttribute("size", index.getSize());
            } catch (Exception e) {
                OLogManager.instance().error(this, "Cannot serialize index configuration", e);
            }
            json.endObject();
        }
        json.endCollection();
        json.beginObject("config");
        json.beginCollection("values");
        json.writeObjects(null, new Object[] { "name", "dateFormat", "value", db.getStorage().getConfiguration().dateFormat }, new Object[] { "name", "dateTimeFormat", "value", db.getStorage().getConfiguration().dateTimeFormat }, new Object[] { "name", "localeCountry", "value", db.getStorage().getConfiguration().getLocaleCountry() }, new Object[] { "name", "localeLanguage", "value", db.getStorage().getConfiguration().getLocaleLanguage() }, new Object[] { "name", "charSet", "value", db.getStorage().getConfiguration().getCharset() }, new Object[] { "name", "timezone", "value", db.getStorage().getConfiguration().getTimeZone().getID() }, new Object[] { "name", "definitionVersion", "value", db.getStorage().getConfiguration().version }, new Object[] { "name", "clusterSelection", "value", db.getStorage().getConfiguration().getClusterSelection() }, new Object[] { "name", "minimumClusters", "value", db.getStorage().getConfiguration().getMinimumClusters() }, new Object[] { "name", "conflictStrategy", "value", db.getStorage().getConfiguration().getConflictStrategy() });
        json.endCollection();
        json.beginCollection("properties");
        if (db.getStorage().getConfiguration().getProperties() != null)
            for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().getProperties()) {
                if (entry != null) {
                    json.beginObject();
                    json.writeAttribute("name", entry.name);
                    json.writeAttribute("value", entry.value);
                    json.endObject();
                }
            }
        json.endCollection();
        json.endObject();
        json.endObject();
        json.flush();
        iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
    } finally {
        if (db != null)
            db.close();
    }
}
Also used : OJSONWriter(com.orientechnologies.orient.core.serialization.serializer.OJSONWriter) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) IOException(java.io.IOException) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) StringWriter(java.io.StringWriter) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCluster(com.orientechnologies.orient.core.storage.OCluster) OStorageEntryConfiguration(com.orientechnologies.orient.core.config.OStorageEntryConfiguration)

Example 8 with OIndexManagerProxy

use of com.orientechnologies.orient.core.index.OIndexManagerProxy 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());
}
Also used : OProgressListener(com.orientechnologies.common.listener.OProgressListener) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) Test(org.testng.annotations.Test)

Example 9 with OIndexManagerProxy

use of com.orientechnologies.orient.core.index.OIndexManagerProxy in project orientdb by orientechnologies.

the class IndexManagerTest method createCompositeIndexTestWithoutListener.

@Test
public void createCompositeIndexTestWithoutListener() {
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    final OIndex result = indexManager.createIndex("compositeone", 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)), -1), new int[] { database.getClusterIdByName(CLASS_NAME) }, null, null);
    assertEquals(result.getName(), "compositeone");
    indexManager.reload();
    assertEquals(database.getMetadata().getIndexManager().getClassIndex(CLASS_NAME, "compositeone").getName(), result.getName());
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) Test(org.testng.annotations.Test)

Example 10 with OIndexManagerProxy

use of com.orientechnologies.orient.core.index.OIndexManagerProxy in project orientdb by orientechnologies.

the class IndexManagerTest method testCreateSimpleKeyInvalidNameIndex.

@Test
public void testCreateSimpleKeyInvalidNameIndex() {
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    try {
        indexManager.createIndex("simple:key", OClass.INDEX_TYPE.UNIQUE.toString(), new OSimpleKeyIndexDefinition(-1, OType.INTEGER), null, null, null);
        fail();
    } catch (Exception e) {
        Throwable cause = e;
        while (cause.getCause() != null) cause = cause.getCause();
        assertTrue((cause instanceof IllegalArgumentException) || (cause instanceof OCommandSQLParsingException));
    }
}
Also used : OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) Test(org.testng.annotations.Test)

Aggregations

OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)12 Test (org.testng.annotations.Test)6 OIndex (com.orientechnologies.orient.core.index.OIndex)5 OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)2 OSimpleKeyIndexDefinition (com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition)2 IOException (java.io.IOException)2 OException (com.orientechnologies.common.exception.OException)1 OProgressListener (com.orientechnologies.common.listener.OProgressListener)1 OBinarySerializer (com.orientechnologies.common.serialization.types.OBinarySerializer)1 OCommandCacheSoftRefs (com.orientechnologies.orient.core.cache.OCommandCacheSoftRefs)1 OStorageEntryConfiguration (com.orientechnologies.orient.core.config.OStorageEntryConfiguration)1 OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)1 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)1 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)1 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)1 OIndexManagerRemote (com.orientechnologies.orient.core.index.OIndexManagerRemote)1 OIndexManagerShared (com.orientechnologies.orient.core.index.OIndexManagerShared)1