/** * Register schema. */ public OClass register(final ODatabaseDocumentTx db) { checkNotNull(db); OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(DB_CLASS); if (type == null) { type = schema.createClass(DB_CLASS); type.createProperty(P_PATH, OType.STRING).setNotNull(true); type.createIndex(P_PATH + "idx", INDEX_TYPE.UNIQUE, P_PATH); type.createProperty(P_BLOBID, OType.STRING).setNotNull(true); type.createProperty(P_MIMETYPE, OType.STRING).setNotNull(true); log.info("Created schema: {}, properties: {}", type, type.properties()); } return type; }
private String getLowerSubclass(ODatabase db, String className1, String className2) { OSchema schema = db.getMetadata().getSchema(); OClass class1 = schema.getClass(className1); OClass class2 = schema.getClass(className2); if (class1.isSubClassOf(class2)) { return class1.getName(); } if (class2.isSubClassOf(class1)) { return class2.getName(); } return null; }
private OType deriveFieldType(String iFieldName, ODocumentEntry entry, OType[] iFieldType) { OType fieldType; if (iFieldType != null && iFieldType.length == 1) { entry.type = iFieldType[0]; fieldType = iFieldType[0]; } else fieldType = null; OClass _clazz = getImmutableSchemaClass(); if (_clazz != null) { // SCHEMA-FULL? final OProperty prop = _clazz.getProperty(iFieldName); if (prop != null) { entry.property = prop; fieldType = prop.getType(); if (fieldType != OType.ANY) entry.type = fieldType; } } return fieldType; }
private void createSignatureType(OSchema schema) { OClass signatures = schema.createClass("Signatures"); signatures.createProperty(String.valueOf(DocumentAttributes.SHA1), OType.STRING).setNotNull(true); signatures.createIndex("sha1Idx", OClass.INDEX_TYPE.UNIQUE, DocumentAttributes.SHA1.toString()); }
@Override protected void defineType(final OClass type) { type.createProperty(P_USER_ID, OType.STRING) .setNotNull(true); type.createProperty(P_SOURCE, OType.STRING) .setNotNull(true); type.createProperty(P_ROLES, OType.EMBEDDEDSET); type.createIndex(I_USER_ID_SOURCE, INDEX_TYPE.UNIQUE, P_USER_ID, P_SOURCE); }
@Test public void testRemovingReadonlyField() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass classA = schema.createClass("TestRemovingField"); classA.createProperty("name", OType.STRING); OProperty property = classA.createProperty("property", OType.STRING); property.setReadonly(true); ODocument doc = new ODocument(classA); doc.field("name", "My Name"); doc.field("property", "value1"); doc.save(); doc.field("name", "My Name 2"); doc.field("property", "value2"); doc.undo("property"); doc.save(); }
@Ignore //TODO: Uncomment when OrientDB issue will be fixed: https://github.com/orientechnologies/orientdb/issues/8067 @Test public void testLinkToOUser() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); final OClass classA = schema.createClass("TestLinkToOUser"); classA.createProperty("name", OType.STRING); classA.createProperty("user", OType.LINK).setLinkedClass(schema.getClass("OUser")); ORID userRid = new ORecordId("#5:0"); ODocument doc = new ODocument(classA); wicket.getTester().signIn("writer", "writer"); db = wicket.getTester().getDatabase(); db.begin(); ODocument userDoc = userRid.getRecord(); userDoc.field("roles"); doc.field("Admin"); doc.field("user", userDoc); doc.save(); db.commit(); } }
private Object convertToCatalogLinkIfAble(Object value,OProperty fieldProperty,ODocument mainDoc){ String catalogsLinkNameAttribute = getOrientDBEndpoint().getCatalogsLinkAttr();// String catalogsLinkName = getOrientDBEndpoint().getCatalogsLinkName();// String catalogNameField = fieldProperty.getLinkedClass().getCustom(catalogsLinkNameAttribute); if (catalogNameField==null){ catalogNameField = catalogsLinkName; } List<OIdentifiable> catalogLinks = curDb.query(new OSQLSynchQuery<OIdentifiable>( "select from "+fieldProperty.getLinkedClass().getName()+" where "+catalogNameField+"=?"), value); if (catalogLinks.size()>0){ value = catalogLinks.get(0).getIdentity(); }else{ boolean updateCatalogs = getOrientDBEndpoint().isCatalogsUpdate();// if (updateCatalogs){ ODocument catalogRecord = new ODocument(fieldProperty.getLinkedClass()); catalogRecord.field(catalogNameField,value); catalogRecord.save(true); value = catalogRecord.getIdentity(); } } return value; }
@Before public void init() { doc = DBClosure.sudo(db -> { OSchema schema = db.getMetadata().getSchema(); OClass test = schema.createClass("Customer"); test.createProperty("name", OType.STRING); test.createProperty("phone", OType.STRING); ODocument document = new ODocument("Customer"); document.field("name", "Test Name"); document.save(); return document; }); }
@Test public void testGettingFields() { OSchema schema = wicket.getTester().getSchema(); OClass classA = schema.createClass("GettingFields"); classA.createProperty("title", OType.STRING); classA.createProperty("link", OType.LINK).setLinkedClass(classA); classA.createProperty("multi", OType.LINKLIST).setLinkedClass(classA); ODocument doc = new ODocument(classA); doc.field("title", "test"); doc.save(); doc.field("link", doc); doc.field("multi", Arrays.asList(doc)); doc.save(); doc.reload(); String title = doc.field("title"); ODocument link = doc.field("link"); Collection<ODocument> multi = doc.field("multi"); }
@Override public ODocument createWidgetDocument(IWidgetType<?> widgetType) { String oClassName = widgetType.getOClassName(); if(oClassName==null) oClassName = OCLASS_WIDGET; OClass oClass = getDatabase().getMetadata().getSchema().getClass(oClassName); if(oClass==null || !oClass.isSubClassOf(OCLASS_WIDGET)) throw new WicketRuntimeException("Wrong OClass specified for widget settings: "+oClassName); ODocument widgetDoc = new ODocument(oClass); widgetDoc.field(OPROPERTY_TYPE_ID, widgetType.getId()); return widgetDoc; }
@Test public void testDeletionOfDependentClass2() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass classAbs = schema.createAbstractClass("TestDeletionAbst"); OClass classA = schema.createClass("TestDeletionA", classAbs); ODocument doc = new ODocument(classA); doc.save(); assertEquals(1, classA.count()); OClass classB = schema.createClass("TestDeletionB", classA); doc = new ODocument(classB); doc.save(); assertEquals(1, classB.count()); assertEquals(2, classA.count()); schema.dropClass(classB.getName()); assertEquals(1, classA.count()); }
public static void realizeMandatory(ODocument doc) { OClass oClass = doc.getSchemaClass(); if(oClass!=null) { for(OProperty property : oClass.properties()) { if(property.isMandatory() && Strings.isEmpty(property.getDefaultValue()) && !doc.containsField(property.getName())) { doc.field(property.getName(), (Object) null); } } } }
public <T> T getProperty(final String key) { if (key == null) return null; if (key.equals("_class")) return (T) getRecord().getSchemaClass().getName(); else if (key.equals("_version")) return (T) new Integer(getRecord().getVersion()); else if (key.equals("_rid")) return (T) rawElement.getIdentity().toString(); return getRecord().field(key); }
@Test public void testBrowsePages() throws Exception { ODatabaseDocument db = getDatabase(); Collection<OClass> classes = db.getMetadata().getSchema().getClasses(); PageParameters parameters = new PageParameters(); for (OClass oClass : classes) { parameters.set("className", oClass.getName()); LOG.info("Rendering browse page for class '"+oClass.getName()+"'"); tester.startPage(BrowseOClassPage.class, parameters); tester.assertRenderedPage(BrowseOClassPage.class); } }
public void create(ODatabaseDocumentInternal database) { if (database.getMetadata().getSchema().existsClass(OScheduledEvent.CLASS_NAME)) return; final OClass f = database.getMetadata().getSchema().createClass(OScheduledEvent.CLASS_NAME); f.createProperty(OScheduledEvent.PROP_NAME, OType.STRING, (OType) null, true).setMandatory(true).setNotNull(true); f.createProperty(OScheduledEvent.PROP_RULE, OType.STRING, (OType) null, true).setMandatory(true).setNotNull(true); f.createProperty(OScheduledEvent.PROP_ARGUMENTS, OType.EMBEDDEDMAP, (OType) null, true); f.createProperty(OScheduledEvent.PROP_STATUS, OType.STRING, (OType) null, true); f.createProperty(OScheduledEvent.PROP_FUNC, OType.LINK, database.getMetadata().getSchema().getClass(OFunction.CLASS_NAME), true) .setMandatory(true).setNotNull(true); f.createProperty(OScheduledEvent.PROP_STARTTIME, OType.DATETIME, (OType) null, true); }
@Override public void setValue(Object object, Object value, PropertyResolverConverter converter) { ODocument doc = toODocument(object); if(value!=null && ! OType.isSimpleType(value)) { //Try to convert if type is not simple OClass schemaClass = doc.getSchemaClass(); OProperty property = schemaClass.getProperty(exp); if(property!=null) { value = converter.convert(value, property.getType().getDefaultJavaType()); } } doc.field(exp, value); }
@Test public void testPropertyRenaming() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass classA = schema.createClass("TestPropertyRenaming"); OProperty property = classA.createProperty("propertyOld", OType.STRING); assertEquals(property, classA.getProperty("propertyOld")); assertNull(classA.getProperty("propertyNew")); property.setName("propertyNew"); schema.reload(); classA = schema.getClass("TestPropertyRenaming"); assertNull(classA.getProperty("propertyOld")); assertEquals(property, classA.getProperty("propertyNew")); }
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); } } }
private boolean matchesClass(OIdentifiable identifiable, OClass oClass) { if (identifiable == null) { return false; } ORecord record = identifiable.getRecord(); if (record == null) { return false; } if (record instanceof ODocument) { return ((ODocument) record).getSchemaClass().isSubClassOf(oClass); } return false; }