protected void checkParametersConflict(final OClass baseClass) { final Collection<OProperty> baseClassProperties = baseClass.properties(); for (OProperty property : baseClassProperties) { OProperty thisProperty = getProperty(property.getName()); if (thisProperty != null && !thisProperty.getType().equals(property.getType())) { throw new OSchemaException( "Cannot add base class '" + baseClass.getName() + "', because of property conflict: '" + thisProperty + "' vs '" + property + "'"); } } }
@Override protected void defineType(final OClass type) { type.createProperty(P_NAME, OType.STRING).setMandatory(true).setMax(MAX_NAME_LENGTH).setNotNull(true); type.createProperty(P_NOTES, OType.STRING).setMandatory(false).setNotNull(false); type.createProperty(P_FORMAT, OType.STRING).setMandatory(true).setNotNull(true); type.createProperty(P_MODE, OType.STRING).setMandatory(true).setNotNull(true); type.createProperty(P_CRITERIA, OType.EMBEDDEDMAP).setMandatory(true).setNotNull(true); type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME); type.createIndex(I_FORMAT, INDEX_TYPE.NOTUNIQUE, P_FORMAT); }
private void modifyCaseInsensitiveNameField(final OClass type) { log.info("Modifying case-insensitive name field on component"); OProperty ciNameProperty = type.getProperty(P_CI_NAME); if (!ciNameProperty.isMandatory()) { ciNameProperty.setMandatory(true); } if (!ciNameProperty.isNotNull()) { ciNameProperty.setNotNull(true); } }
@Override protected void defineType(final OClass type) { type.createProperty(P_ID, OType.STRING) .setMandatory(true) .setNotNull(true); type.createProperty(P_ALIAS, OType.STRING) .setMandatory(false) .setNotNull(false); }
message("\nCLASS '" + cls.getName() + "'\n"); final long count = currentDatabase.countClass(cls.getName(), false); message("\nRecords..............: " + count); if (cls.getShortName() != null) message("\nAlias................: " + cls.getShortName()); if (cls.hasSuperClasses()) for (final OProperty p : cls.properties()) { try { final ODocument row = new ODocument(); resultSet.add(row); row.field("NAME", p.getName()); row.field("TYPE", p.getType()); row.field("LINKED-TYPE/CLASS", p.getLinkedClass() != null ? p.getLinkedClass() : p.getLinkedType()); row.field("MANDATORY", p.isMandatory()); row.field("READONLY", p.isReadonly()); row.field("NOT-NULL", p.isNotNull()); row.field("MIN", p.getMin() != null ? p.getMin() : ""); row.field("MAX", p.getMax() != null ? p.getMax() : ""); row.field("COLLATE", p.getCollate() != null ? p.getCollate().getName() : ""); row.field("DEFAULT", p.getDefaultValue() != null ? p.getDefaultValue() : "");
writer.writeAttribute(0, false, "name", cls.getName()); writer.writeAttribute(0, false, "name", p.getName()); writer.writeAttribute(0, false, "type", p.getType().toString()); if (p.isMandatory()) writer.writeAttribute(0, false, "mandatory", p.isMandatory()); if (p.isReadonly()) writer.writeAttribute(0, false, "readonly", p.isReadonly()); if (p.isNotNull()) writer.writeAttribute(0, false, "not-null", p.isNotNull()); if (p.getLinkedClass() != null) writer.writeAttribute(0, false, "linked-class", p.getLinkedClass().getName()); if (p.getLinkedType() != null) writer.writeAttribute(0, false, "linked-type", p.getLinkedType().toString()); if (p.getMin() != null) writer.writeAttribute(0, false, "min", p.getMin()); if (p.getMax() != null) writer.writeAttribute(0, false, "max", p.getMax()); if (p.getCollate() != null) writer.writeAttribute(0, false, "collate", p.getCollate().getName()); if (p.getDefaultValue() != null) writer.writeAttribute(0, false, "default-value", p.getDefaultValue()); if (p.getRegexp() != null) writer.writeAttribute(0, false, "regexp", p.getRegexp()); final Set<String> customKeys = p.getCustomKeys(); final Map<String, String> custom = new HashMap<String, String>(); for (String key : customKeys) custom.put(key, p.getCustom(key));
if (content != null) { final ODocument fieldsToPreserve = new ODocument(); final OClass restricted = getDatabase().getMetadata().getSchema().getClass(OSecurity.RESTRICTED_CLASSNAME); if (restricted != null && restricted.isSuperClassOf(record.getSchemaClass())) { for (OProperty prop : restricted.properties()) { fieldsToPreserve.field(prop.getName(), record.<Object>field(prop.getName())); if (recordClass != null && recordClass.isSubClassOf("V")) { for (String fieldName : record.fieldNames()) { if (fieldName.startsWith("in_") || fieldName.startsWith("out_")) {
message("\nPROPERTY '" + prop.getFullName() + "'\n"); message("\nType.................: " + prop.getType()); message("\nMandatory............: " + prop.isMandatory()); message("\nNot null.............: " + prop.isNotNull()); message("\nRead only............: " + prop.isReadonly()); message("\nDefault value........: " + prop.getDefaultValue()); message("\nMinimum value........: " + prop.getMin()); message("\nMaximum value........: " + prop.getMax()); message("\nREGEXP...............: " + prop.getRegexp()); message("\nCollate..............: " + prop.getCollate()); message("\nLinked class.........: " + prop.getLinkedClass()); message("\nLinked type..........: " + prop.getLinkedType()); if (prop.getCustomKeys().size() > 0) { message("\n\nCUSTOM ATTRIBUTES"); for (final String k : prop.getCustomKeys()) { try { final ODocument row = new ODocument(); resultSet.add(row); row.field("NAME", k); row.field("VALUE", prop.getCustom(k)); final Collection<OIndex<?>> indexes = prop.getAllIndexes(); if (!indexes.isEmpty()) { message("\n\nINDEXES (" + indexes.size() + " altogether)");
private void removeLink(ODocument doc, OProperty property, ODocument value) { if(doc==null || property ==null || value == null || isUnderTheLock(doc)) return; String field = property.getName(); if(doc.getSchemaClass().isSubClassOf(property.getOwnerClass())) { Object wrappedValue = value.getIdentity().isPersistent()?value.getIdentity():value; if(property.getType().isMultiValue()) { Collection<Object> objects = doc.field(field); if(objects!=null && objects.remove(wrappedValue)) { doc.field(field, objects); //It's safe for multivalue docs saveOutOfHook(doc); } } else { if(value.getIdentity().equals(doc.field(field, ORID.class))) { doc.field(field, (Object) null); doc.save(); } } } }
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; }
public OImmutableProperty(OProperty property, OImmutableClass owner) { name = property.getName(); fullName = property.getFullName(); type = property.getType(); description = property.getDescription(); if (property.getLinkedClass() != null) linkedClassName = property.getLinkedClass().getName(); else linkedClassName = null; linkedType = property.getLinkedType(); notNull = property.isNotNull(); collate = property.getCollate(); mandatory = property.isMandatory(); min = property.getMin(); max = property.getMax(); defaultValue = property.getDefaultValue(); regexp = property.getRegexp(); customProperties = new HashMap<String, String>(); for (String key : property.getCustomKeys()) customProperties.put(key, property.getCustom(key)); id = property.getId(); readOnly = property.isReadonly();
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); } } } }
@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 testOPropertyPrototyper() throws Exception OClass newClass = wicket.getTester().getSchema().createClass("NewClass"); OProperty toCompare = newClass.createProperty("toCompare", OType.STRING); try assertNull(newClass.getProperty("newProperty")); newProperty.setName("newProperty"); assertEquals("newProperty", newProperty.getName()); assertNull(newClass.getProperty("newProperty")); assertEquals("NewClass.newProperty", newProperty.getFullName()); newProperty.setType(OType.STRING); assertEquals(OType.STRING, newProperty.getType()); newProperty.setCustom("myCustom", "myCustomValue"); assertEquals("myCustomValue", newProperty.getCustom("myCustom")); assertTrue(newProperty.compareTo(toCompare)<0); OProperty realizedNewProperty = ((IPrototype<OProperty>)newProperty).realizePrototype(); assertEquals(newClass.getProperty("newProperty"), realizedNewProperty); assertEquals("myCustomValue", realizedNewProperty.getCustom("myCustom")); wicket.getTester().getSchema().dropClass(newClass.getName());
/** * Checks and convert the field of the document matching the types specified by the class. **/ private void convertFieldsToClass(final OClass _clazz) { for (OProperty prop : _clazz.properties()) { ODocumentEntry entry = _fields != null ? _fields.get(prop.getName()) : null; if (entry != null && entry.exist()) { if (entry.type == null || entry.type != prop.getType()) { boolean preChanged = entry.changed; boolean preCreated = entry.created; ; field(prop.getName(), entry.value, prop.getType()); if (_recordId.isNew()) { entry.changed = preChanged; entry.created = preCreated; } } } else { String defValue = prop.getDefaultValue(); if (defValue != null && /*defValue.length() > 0 && */!containsField(prop.getName())) { Object curFieldValue = OSQLHelper.parseDefaultValue(this, defValue); Object fieldValue = ODocumentHelper.convertField(this, prop.getName(), prop.getType(), null, curFieldValue); rawField(prop.getName(), fieldValue, prop.getType()); } } } }
@Override protected String load() { String filename = docModel.getObject().field(propModel.getObject().getName()+BinaryEditPanel.FILENAME_SUFFIX, String.class); if(Strings.isEmpty(filename)){ filename = oClassIntrospector.getDocumentName(docModel.getObject()); filename += "."+propModel.getObject().getName()+".bin"; } return filename; }
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); }
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()); }
Object field = iFromVertex.field(iOutFieldName); if (field != null) if (field instanceof Collection<?>) field = iToVertex.field(iInFieldName); if (field != null) if (field instanceof Collection<?>) for (OProperty p : cls.properties()) { if (p.isMandatory() || p.isNotNull() || !p.getOwnerClass().getInvolvedIndexes(p.getName()).isEmpty()) return false;
private static RecordType getRecordType(OClass oClass) { RecordType type = new RecordType(oClass.getName()); for (OProperty oProperty : oClass.properties()) { OType oType = oProperty.getType(); Class javaType = oType.getDefaultJavaType(); if (oType == OType.LINK) { javaType = RecordId.class; } FieldDefinition field = new FieldDefinition(oProperty.getName(), javaType); field.withNotNull(oProperty.isNotNull()); for (OIndex oIndex : oProperty.getAllIndexes()) { OIndexDefinition def = oIndex.getDefinition(); if (def.isAutomatic() && def.getFields().size() == 1) { boolean unique = oIndex.getType().equalsIgnoreCase(INDEX_TYPE.UNIQUE.name()); field.withIndexed(true).withUnique(unique); } } type.withField(field); } type.withStrict(oClass.isStrictMode()); OClass oSuperClass = oClass.getSuperClass(); if (oSuperClass != null) { type.withSuperType(getRecordType(oSuperClass)); } type.withAbstract(oClass.isAbstract()); return type; }