private void walkIterable(Iterable iterable, OType fieldType, ODocumentFieldVisitor fieldWalker, Set<ODocument> walked) { for (Object value : iterable) { if (value instanceof ODocument) { final ODocument doc = (ODocument) value; // only embedded documents are walked if (OType.EMBEDDEDLIST.equals(fieldType) || OType.EMBEDDEDSET.equals(fieldType) || doc.isEmbedded()) walkDocument((ODocument) value, fieldWalker, walked); } } }
private static void checkTypes(OClass oClass, List<String> fieldNames, List<OType> types) { if (fieldNames.size() != types.size()) throw new IllegalArgumentException("Count of field names doesn't match count of field types. It was " + fieldNames.size() + " fields, but " + types.size() + " types."); for (int i = 0, fieldNamesSize = fieldNames.size(); i < fieldNamesSize; i++) { String fieldName = fieldNames.get(i); OType type = types.get(i); final OProperty property = oClass.getProperty(fieldName); if (property != null && !type.equals(property.getType())) { throw new IllegalArgumentException("Property type list not match with real property types"); } } }
private void walkMap(Map map, OType fieldType, ODocumentFieldVisitor fieldWalker, Set<ODocument> walked) { for (Object value : map.values()) { if (value instanceof ODocument) { final ODocument doc = (ODocument) value; // only embedded documents are walked if (OType.EMBEDDEDMAP.equals(fieldType) || doc.isEmbedded()) walkDocument((ODocument) value, fieldWalker, walked); } } }
@Override public FilterCriteriaType getFilterCriteriaType() { OProperty property = getPropertyModel().getObject(); if (property != null) { OType type = property.getType(); return type.equals(OType.LINKSET) ? FilterCriteriaType.LINKSET : FilterCriteriaType.LINKLIST; } return FilterCriteriaType.LINKLIST; }
protected static void checkParametersConflict(List<OClass> classes) { final Map<String, OProperty> comulative = new HashMap<String, OProperty>(); final Map<String, OProperty> properties = new HashMap<String, OProperty>(); for (OClass superClass : classes) { if (superClass == null) continue; OClassImpl impl; if (superClass instanceof OClassAbstractDelegate) impl = (OClassImpl) ((OClassAbstractDelegate) superClass).delegate; else impl = (OClassImpl) superClass; impl.propertiesMap(properties); for (Map.Entry<String, OProperty> entry : properties.entrySet()) { if (comulative.containsKey(entry.getKey())) { final String property = entry.getKey(); final OProperty existingProperty = comulative.get(property); if (!existingProperty.getType().equals(entry.getValue().getType())) { throw new OSchemaException("Properties conflict detected: '" + existingProperty + "] vs [" + entry.getValue() + "]"); } } } comulative.putAll(properties); properties.clear(); } }
public OGlobalProperty createGlobalProperty(final String name, final OType type, final Integer id) { OGlobalProperty global; if (id < properties.size() && (global = properties.get(id)) != null) { if (!global.getName().equals(name) || !global.getType().equals(type)) throw new OSchemaException("A property with id " + id + " already exist "); return global; } global = new OGlobalPropertyImpl(name, type, id); ensurePropertiesSize(id); properties.set(id, global); propertiesByNameType.put(global.getName() + "|" + global.getType().name(), global); return global; }
for(OProperty property: properties) { OType type = property.getType(); if(OType.LINK.equals(type)) { OClass linkedClass = property.getLinkedClass(); OProperty nameProperty = oClassIntrospector.getNameProperty(linkedClass); OType linkedClassType = nameProperty.getType(); String map = property.getName()+'.'+nameProperty.getName(); if (OType.EMBEDDEDMAP.equals(linkedClassType)) { sb.append("coalesce(").append(map).append('[').append(thisLang).append("], "); if(!thisLang.equals(systemLang)) {
public void checkPersistentPropertyType(final ODatabaseInternal<ORecord> database, final String propertyName, final OType type) { if (OType.ANY.equals(type)) { return; } final boolean strictSQL = database.getStorage().getConfiguration().isStrictSql(); final StringBuilder builder = new StringBuilder(256); builder.append("select count(*) as count from "); builder.append(getEscapedName(name, strictSQL)); builder.append(" where "); builder.append(getEscapedName(propertyName, strictSQL)); builder.append(".type() not in ["); final Iterator<OType> cur = type.getCastable().iterator(); while (cur.hasNext()) { builder.append('"').append(cur.next().name()).append('"'); if (cur.hasNext()) builder.append(","); } builder.append("] and ").append(getEscapedName(propertyName, strictSQL)).append(" is not null "); if (type.isMultiValue()) builder.append(" and ").append(getEscapedName(propertyName, strictSQL)).append(".size() <> 0 limit 1"); try (final OResultSet res = database.command(builder.toString())) { if (((Long) res.next().getProperty("count")) > 0) throw new OSchemaException("The database contains some schema-less data in the property '" + name + "." + propertyName + "' that is not compatible with the type " + type + ". Fix those records and change the schema again"); } }
public Object getDocumentValueToIndex(final ODocument iDocument) { if (OType.LINK.equals(keyType)) { final OIdentifiable identifiable = iDocument.field(field); if (identifiable != null) return createValue(identifiable.getIdentity()); else return null; } return createValue(iDocument.<Object>field(field)); }
try { if (fieldType != null && fieldType.getDefaultJavaType() != null && fieldType.getDefaultJavaType().equals(Date.class)) { if (fieldType.equals(OType.DATE)) doc.field(fieldName, transformToDate(fieldValueAsString)); else
/** * Create {@link OProperty} if required * @param propertyName property name to create * @param type type of property to create * @return this helper */ public OSchemaHelper oProperty(String propertyName, OType type) { checkOClass(); lastProperty = lastClass.getProperty(propertyName); if(lastProperty==null) { lastProperty = lastClass.createProperty(propertyName, type); } else { if(!type.equals(lastProperty.getType())) { lastProperty.setType(type); } } return this; }
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 + "'"); } } }
&& !(OType.LINK.equals(fieldType) || OType.LINKBAG.equals(fieldType) || OType.LINKLIST.equals(fieldType) || OType.LINKSET.equals(fieldType) || (fieldValue instanceof ORecordLazyMultiValue))) { if (fieldWalker.goDeeper(fieldType, linkedType, fieldValue)) { if (fieldValue instanceof Map) else if (fieldValue instanceof ODocument) { final ODocument doc = (ODocument) fieldValue; if (OType.EMBEDDED.equals(fieldType) || doc.isEmbedded()) walkDocument((ODocument) fieldValue, fieldWalker); } else if (OMultiValue.isIterable(fieldValue))
/** * Create {@link OProperty} if required * @param propertyName property name to create * @param type type of property to create * @return this helper */ public OSchemaHelper oProperty(String propertyName, OType type) { checkOClass(); lastProperty = lastClass.getProperty(propertyName); if(lastProperty==null) { lastProperty = lastClass.createProperty(propertyName, type); } else { if(!type.equals(lastProperty.getType())) { lastProperty.setType(type); } } return this; }
@Override public OProperty getNameProperty(OClass oClass) { if(oClass==null) return null; OProperty ret = CustomAttribute.PROP_NAME.getValue(oClass); if(ret!=null) return ret; ret = oClass.getProperty("name"); if(ret!=null) return ret; for(OProperty p: oClass.properties()) { if(!p.getType().isMultiValue()) { ret = p; if(OType.STRING.equals(p.getType())) break; } } return ret; }
if (ODocumentInternal.getImmutableSchemaClass(record) != null) { final OProperty property = ODocumentInternal.getImmutableSchemaClass(record).getProperty(entry.getKey()); if (property != null && (property.getType() != null && (!property.getType().equals(OType.EMBEDDEDMAP) && !property .getType().equals(OType.LINKMAP)))) { throw new OCommandExecutionException("field " + entry.getKey() + " is not defined as a map"); if (property != null && property.getType().equals(OType.LINKMAP) && !(value instanceof OIdentifiable)) { throw new OCommandExecutionException("field " + entry.getKey() + " defined of type LINKMAP accept only link values"); if (OType.LINKMAP.equals(OType.getTypeByValue(fieldValue)) && !(value instanceof OIdentifiable)) { map = new OTrackedMap(record, map, Object.class); record.field(entry.getKey(), map, OType.EMBEDDEDMAP);
final DefaultVisualizer visualizer = DefaultVisualizer.INSTANCE; final OType linkedType = property.getLinkedType(); final OType oType = linkedType != null ? linkedType : (OType.LINKMAP.equals(property.getType()) ? OType.LINK :OType.ANY); IModel<Set<Map.Entry<String, V>>> entriesModel = new PropertyModel<>(getModel(), "entrySet()"); ListView<Map.Entry<String, V>> listView =
@Override protected void onConfigure() { super.onConfigure(); String critery = getPropertyObject(); if(OPropertyPrototyper.TYPE.equals(critery)) { OType oType = (OType)getEnteredValue(); // Show Linked Class if type is a some kind of link AbstractMetaPanel<OProperty, String, ?> metaPanel = getMetaComponent(OPropertyPrototyper.LINKED_CLASS); if(metaPanel!=null) metaPanel.setVisibilityAllowed(oType!=null && (oType.isLink() || oType.isEmbedded())); // Show Linked Type if type is a some kind of embedded metaPanel = getMetaComponent(OPropertyPrototyper.LINKED_TYPE); if(metaPanel!=null) metaPanel.setVisibilityAllowed(oType!=null && oType.isEmbedded() && !OType.EMBEDDED.equals(oType)); // Show inverse if current type is a link metaPanel = getMetaComponent(CustomAttribute.PROP_INVERSE.getName()); if(metaPanel!=null) metaPanel.setVisibilityAllowed(oType!=null && oType.isLink()); } else if(CustomAttribute.CALCULABLE.getName().equals(critery)) { Boolean calculable = (Boolean) getEnteredValue(); AbstractMetaPanel<OProperty, String, ?> metaPanel = getMetaComponent(CustomAttribute.CALC_SCRIPT.getName()); if(metaPanel!=null) metaPanel.setVisibilityAllowed(calculable!=null && calculable); } }
public void load() { final OClass userClass = getDatabase().getMetadata().getSchema().getClass("OUser"); if (userClass != null) { // @COMPATIBILITY <1.3.0 if (!userClass.existsProperty("status")) { userClass.createProperty("status", OType.STRING).setMandatory(true).setNotNull(true); } OProperty p = userClass.getProperty("name"); if (p == null) p = userClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true).setMin("1") .setRegexp("\\S+(.*\\S+)*"); if (userClass.getInvolvedIndexes("name") == null) p.createIndex(INDEX_TYPE.UNIQUE); // ROLE final OClass roleClass = getDatabase().getMetadata().getSchema().getClass("ORole"); final OProperty rules = roleClass.getProperty("rules"); if (rules != null && !OType.EMBEDDEDMAP.equals(rules.getType())) { roleClass.dropProperty("rules"); } if (!roleClass.existsProperty("inheritedRole")) { roleClass.createProperty("inheritedRole", OType.LINK, roleClass); } p = roleClass.getProperty("name"); if (p == null) p = roleClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true); if (roleClass.getInvolvedIndexes("name") == null) p.createIndex(INDEX_TYPE.UNIQUE); } }