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);
}
}
}
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);
}
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);
}
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();
}
}
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);
}
Aggregations