Search in sources :

Example 31 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class OLuceneIndexEngineAbstract method checkCollectionIndex.

private void checkCollectionIndex(OIndexDefinition indexDefinition) {
    List<String> fields = indexDefinition.getFields();
    OClass aClass = getDatabase().getMetadata().getSchema().getClass(indexDefinition.getClassName());
    for (String field : fields) {
        OProperty property = aClass.getProperty(field);
        if (property.getType().isEmbedded() && property.getLinkedType() != null) {
            collectionFields.put(field, true);
        } else {
            collectionFields.put(field, false);
        }
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 32 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class OrientJdbcDatabaseMetaData method getColumns.

@Override
public ResultSet getColumns(final String catalog, final String schemaPattern, final String tableNamePattern, final String columnNamePattern) throws SQLException {
    database.activateOnCurrentThread();
    final List<ODocument> records = new ArrayList<ODocument>();
    OSchema schema = database.getMetadata().getSchema();
    for (OClass clazz : schema.getClasses()) {
        if (OrientJdbcUtils.like(clazz.getName(), tableNamePattern)) {
            for (OProperty prop : clazz.properties()) {
                if (columnNamePattern == null) {
                    records.add(getPropertyAsDocument(clazz, prop));
                } else {
                    if (OrientJdbcUtils.like(prop.getName(), columnNamePattern)) {
                        records.add(getPropertyAsDocument(clazz, prop));
                    }
                }
            }
        }
    }
    return new OrientJdbcResultSet(new OrientJdbcStatement(connection), records, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 33 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class OFunctionLibraryImpl method init.

protected void init() {
    final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
    if (db.getMetadata().getSchema().existsClass("OFunction")) {
        final OClass f = db.getMetadata().getSchema().getClass("OFunction");
        OProperty prop = f.getProperty("name");
        if (prop.getAllIndexes().isEmpty())
            prop.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
        return;
    }
    final OClass f = db.getMetadata().getSchema().createClass("OFunction");
    OProperty prop = f.createProperty("name", OType.STRING, (OType) null, true);
    prop.set(OProperty.ATTRIBUTES.NOTNULL, true);
    prop.set(OProperty.ATTRIBUTES.MANDATORY, true);
    prop.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
    f.createProperty("code", OType.STRING, (OType) null, true);
    f.createProperty("language", OType.STRING, (OType) null, true);
    f.createProperty("idempotent", OType.BOOLEAN, (OType) null, true);
    f.createProperty("parameters", OType.EMBEDDEDLIST, OType.STRING, true);
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 34 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class GraphValidationTest method testPropertyReadOnly.

@Test(expected = OValidationException.class)
public void testPropertyReadOnly() {
    OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL);
    OrientVertexType testType = graphNoTx.createVertexType("Test");
    OProperty prop;
    prop = testType.createProperty("name", OType.STRING).setReadonly(true);
    graphNoTx.shutdown();
    // this one passes
    Assert.assertTrue(prop.isReadonly());
    OrientGraph graph = new OrientGraph(URL);
    try {
        OrientVertex vert1 = graph.addVertex("class:Test", "name", "Sam");
        graph.commit();
        // should throw an exception
        vert1.setProperty("name", "Ben");
        graph.commit();
        // fails
        Assert.assertEquals(vert1.getProperty("name"), "Sam");
    } finally {
        graph.shutdown();
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 35 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class OServerCommandPostDatabase method exportClass.

protected void exportClass(final ODatabaseDocument db, final OJSONWriter json, final OClass cls) throws IOException {
    json.beginObject(2, true, null);
    json.writeAttribute(3, true, "name", cls.getName());
    json.writeAttribute(3, true, "superClass", cls.getSuperClass() != null ? cls.getSuperClass().getName() : "");
    json.writeAttribute(3, true, "alias", cls.getShortName());
    json.writeAttribute(3, true, "clusters", cls.getClusterIds());
    json.writeAttribute(3, true, "defaultCluster", cls.getDefaultClusterId());
    json.writeAttribute(3, true, "clusterSelection", cls.getClusterSelection().getName());
    try {
        json.writeAttribute(3, false, "records", db.countClass(cls.getName()));
    } catch (OSecurityAccessException e) {
        json.writeAttribute(3, false, "records", "? (Unauthorized)");
    }
    if (cls.properties() != null && cls.properties().size() > 0) {
        json.beginCollection(3, true, "properties");
        for (final OProperty prop : cls.properties()) {
            json.beginObject(4, true, null);
            json.writeAttribute(4, true, "name", prop.getName());
            if (prop.getLinkedClass() != null)
                json.writeAttribute(4, true, "linkedClass", prop.getLinkedClass().getName());
            if (prop.getLinkedType() != null)
                json.writeAttribute(4, true, "linkedType", prop.getLinkedType().toString());
            json.writeAttribute(4, true, "type", prop.getType().toString());
            json.writeAttribute(4, true, "mandatory", prop.isMandatory());
            json.writeAttribute(4, true, "readonly", prop.isReadonly());
            json.writeAttribute(4, true, "notNull", prop.isNotNull());
            json.writeAttribute(4, true, "min", prop.getMin());
            json.writeAttribute(4, true, "max", prop.getMax());
            json.endObject(3, true);
        }
        json.endCollection(1, true);
    }
    final Set<OIndex<?>> indexes = cls.getIndexes();
    if (!indexes.isEmpty()) {
        json.beginCollection(3, true, "indexes");
        for (final OIndex<?> index : indexes) {
            json.beginObject(4, true, null);
            json.writeAttribute(4, true, "name", index.getName());
            json.writeAttribute(4, true, "type", index.getType());
            final OIndexDefinition indexDefinition = index.getDefinition();
            if (indexDefinition != null && !indexDefinition.getFields().isEmpty())
                json.writeAttribute(4, true, "fields", indexDefinition.getFields());
            json.endObject(3, true);
        }
        json.endCollection(1, true);
    }
    json.endObject(1, false);
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OIndex(com.orientechnologies.orient.core.index.OIndex)

Aggregations

OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)121 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)84 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)41 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)32 Test (org.testng.annotations.Test)30 Test (org.junit.Test)28 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)25 OType (com.orientechnologies.orient.core.metadata.schema.OType)15 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 FilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.FilterCriteriaManager)10 IFilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 OIndex (com.orientechnologies.orient.core.index.OIndex)8 Date (java.util.Date)8 Set (java.util.Set)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 Map (java.util.Map)7 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)6 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 Collection (java.util.Collection)6