@Override public boolean apply(OClass input) { return !input.isAbstract(); }
@Override public boolean isAbstract() { return delegate.isAbstract(); }
public void describe(Writer writer, OClass oClass) { PrintWriter out = toPrintWriter(writer); out.append(oClass.isAbstract()?"abstract":"class").append(" ").append(oClass.getName()); List<OClass> superClasses = oClass.getSuperClasses(); if(superClasses!=null && !superClasses.isEmpty()) { for(int i=0; i<superClasses.size();i++){ out.append(i==0?" extends ":", "); out.append(superClasses.get(i).getName()); } } out.println(); for(OProperty property: oClass.declaredProperties()) { describe(out, property); } out.println(); }
protected void setClass(final OClass iClass) { if (iClass != null && iClass.isAbstract()) throw new OSchemaException("Cannot create a document of the abstract class '" + iClass + "'"); if (iClass == null) _className = null; else _className = iClass.getName(); _immutableClazz = null; _immutableSchemaVersion = -1; if (iClass != null) convertFieldsToClass(iClass); }
public OImmutableClass(final OClass oClass, final OImmutableSchema schema) { isAbstract = oClass.isAbstract(); strictMode = oClass.isStrictMode(); this.schema = schema; superClassesNames = oClass.getSuperClassesNames(); superClasses = new ArrayList<OImmutableClass>(superClassesNames.size()); name = oClass.getName(); streamAbleName = oClass.getStreamableName(); clusterSelection = oClass.getClusterSelection(); defaultClusterId = oClass.getDefaultClusterId(); clusterIds = oClass.getClusterIds(); polymorphicClusterIds = oClass.getPolymorphicClusterIds(); baseClassesNames = new ArrayList<String>(); for (OClass baseClass : oClass.getSubclasses()) baseClassesNames.add(baseClass.getName()); overSize = oClass.getOverSize(); classOverSize = oClass.getClassOverSize(); shortName = oClass.getShortName(); properties = new HashMap<String, OProperty>(); for (OProperty p : oClass.declaredProperties()) properties.put(p.getName(), new OImmutableProperty(p, this)); Map<String, String> customFields = new HashMap<String, String>(); for (String key : oClass.getCustomKeys()) customFields.put(key, oClass.getCustom(key)); this.customFields = Collections.unmodifiableMap(customFields); this.description = oClass.getDescription(); }
/** * Create if required {@link OClass} * @param className name of a class to create * @param abstractClass is this class abstract * @param superClasses list of superclasses * @return this helper */ private OSchemaHelper oClass(String className, boolean abstractClass, String... superClasses) { lastClass = schema.getClass(className); if(lastClass==null) { OClass[] superClassesArray = new OClass[superClasses.length]; for (int i = 0; i < superClasses.length; i++) { String superClassName = superClasses[i]; superClassesArray[i] = schema.getClass(superClassName); } lastClass = abstractClass ? schema.createAbstractClass(className, superClassesArray) : schema.createClass(className, superClassesArray); } else { boolean currentlyAbstract = lastClass.isAbstract(); if(currentlyAbstract!=abstractClass) lastClass.setAbstract(abstractClass); } lastProperty = null; lastIndex = null; return this; }
boolean fullySorted = true; if (!iSchemaClass.isAbstract()) { Iterator<OIdentifiable> parentClassIterator = (Iterator<OIdentifiable>) searchInClasses(iSchemaClass, false, true); if (parentClassIterator.hasNext()) {
/** * Create if required {@link OClass} * @param className name of a class to create * @param abstractClass is this class abstract * @param superClasses list of superclasses * @return this helper */ private OSchemaHelper oClass(String className, boolean abstractClass, String... superClasses) { lastClass = schema.getClass(className); if(lastClass==null) { OClass[] superClassesArray = new OClass[superClasses.length]; for (int i = 0; i < superClasses.length; i++) { String superClassName = superClasses[i]; superClassesArray[i] = schema.getClass(superClassName); } lastClass = abstractClass ? schema.createAbstractClass(className, superClassesArray) : schema.createClass(className, superClassesArray); } else { boolean currentlyAbstract = lastClass.isAbstract(); if(currentlyAbstract!=abstractClass) lastClass.setAbstract(abstractClass); } lastProperty = null; lastIndex = null; return this; }
if (cls.isAbstract()) clusters.append("-"); else {
schemaClass = ODocumentInternal.getImmutableSchemaClass(this, ((ODocument) record)); if (schemaClass != null) { if (schemaClass.isAbstract()) throw new OSchemaException("Document belongs to abstract class " + schemaClass.getName() + " and cannot be saved"); rid.setClusterId(schemaClass.getClusterForNewInstance((ODocument) record));
if (cls.getShortName() != null) writer.writeAttribute(0, false, "short-name", cls.getShortName()); if (cls.isAbstract()) writer.writeAttribute(0, false, "abstract", cls.isAbstract()); writer.writeAttribute(0, false, "cluster-selection", cls.getClusterSelection().getName()); // @SINCE 1.7
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; }
public String getClusterName(final ORecord record) { if (ODatabaseRecordThreadLocal.instance().get().getStorage().isRemote()) // DON'T ASSIGN CLUSTER WITH REMOTE: SERVER KNOWS THE RIGHT CLUSTER BASED ON LOCALITY return null; int clusterId = record.getIdentity().getClusterId(); if (clusterId == ORID.CLUSTER_ID_INVALID) { // COMPUTE THE CLUSTER ID OClass schemaClass = null; if (record instanceof ODocument) schemaClass = ODocumentInternal.getImmutableSchemaClass(getDatabase(), (ODocument) record); if (schemaClass != null) { // FIND THE RIGHT CLUSTER AS CONFIGURED IN CLASS if (schemaClass.isAbstract()) throw new OSchemaException("Document belongs to abstract class '" + schemaClass.getName() + "' and cannot be saved"); clusterId = schemaClass.getClusterForNewInstance((ODocument) record); return database.getClusterNameById(clusterId); } else { return database.getClusterNameById(database.getStorage().getDefaultClusterId()); } } else { return database.getClusterNameById(clusterId); } }