/** Execute the DROP CLASS. */ public Object execute(final Map<Object, Object> iArgs) { if (className == null) { throw new OCommandExecutionException( "Cannot execute the command because it has not been parsed yet"); } final ODatabaseDocument database = getDatabase(); if (ifExists && !database.getMetadata().getSchema().existsClass(className)) { return true; } final OClass cls = database.getMetadata().getSchema().getClass(className); if (cls == null) { return null; } final long records = cls.count(true); if (records > 0 && !unsafe) { // NOT EMPTY, CHECK IF CLASS IS OF VERTEX OR EDGES if (cls.isSubClassOf("V")) { // FOUND VERTEX CLASS throw new OCommandExecutionException( "'DROP CLASS' command cannot drop class '" + className + "' because it contains Vertices. Use 'DELETE VERTEX' command first to avoid broken edges in a database, or apply the 'UNSAFE' keyword to force it"); } else if (cls.isSubClassOf("E")) { // FOUND EDGE CLASS throw new OCommandExecutionException( "'DROP CLASS' command cannot drop class '" + className + "' because it contains Edges. Use 'DELETE EDGE' command first to avoid broken vertices in a database, or apply the 'UNSAFE' keyword to force it"); } } database.getMetadata().getSchema().dropClass(className); if (records > 0 && unsafe) { // NOT EMPTY, CHECK IF CLASS IS OF VERTEX OR EDGES if (cls.isSubClassOf("V")) { // FOUND VERTICES if (unsafe) OLogManager.instance() .warn( this, "Dropped class '%s' containing %d vertices using UNSAFE mode. Database could contain broken edges", className, records); } else if (cls.isSubClassOf("E")) { // FOUND EDGES OLogManager.instance() .warn( this, "Dropped class '%s' containing %d edges using UNSAFE mode. Database could contain broken vertices", className, records); } } return true; }
protected void checkClass() { // FORCE EARLY UNMARSHALLING final ODocument doc = getRecord(); doc.deserializeFields(); final OClass cls = ODocumentInternal.getImmutableSchemaClass(doc); if (cls == null || !cls.isSubClassOf(getBaseClassName())) throw new IllegalArgumentException( "The document received is not a " + getElementType() + ". Found class '" + cls + "'"); }
protected static final void checkType(final OClass iType) { if (iType == null) throw new IllegalArgumentException("Edge class is null"); if (!iType.isSubClassOf(CLASS_NAME)) throw new IllegalArgumentException( "Type error. The class " + iType + " does not extend class '" + CLASS_NAME + "' and therefore cannot be considered an Edge"); }
@Override protected void onConfigure() { super.onConfigure(); String critery = getPropertyObject(); if (OClassPrototyper.SUPER_CLASSES.equals(critery)) { Collection<OClass> superClasses = (Collection<OClass>) getEnteredValue(); AbstractMetaPanel<OClass, String, ?> onCreateFieldsPanel = getMetaComponent(CustomAttributes.ON_CREATE_FIELDS.getName()); AbstractMetaPanel<OClass, String, ?> onCreateIdentityTypePanel = getMetaComponent(CustomAttributes.ON_CREATE_IDENTITY_TYPE.getName()); if (onCreateFieldsPanel != null || onCreateIdentityTypePanel != null) { boolean visibility = false; for (OClass superClass : superClasses) { if (visibility = superClass.isSubClassOf(OSecurityShared.RESTRICTED_CLASSNAME)) break; } if (onCreateFieldsPanel != null) onCreateFieldsPanel.setVisibilityAllowed(visibility); if (onCreateIdentityTypePanel != null) onCreateIdentityTypePanel.setVisibilityAllowed(visibility); } } }
/** * Check if a class already exists, otherwise create it at the fly. If a transaction is running * commit changes, create the class and begin a new transaction. * * @param className Class's name */ protected String checkForClassInSchema(final String className) { if (className == null) return null; OrientBaseGraph graph = getGraph(); if (graph == null) return className; final OSchema schema = graph.getRawGraph().getMetadata().getSchema(); if (!schema.existsClass(className)) { // CREATE A NEW CLASS AT THE FLY try { graph.executeOutsideTx( new OCallable<OClass, OrientBaseGraph>() { @Override public OClass call(final OrientBaseGraph g) { return schema.createClass(className, schema.getClass(getBaseClassName())); } }, "Committing the active transaction to create the new type '", className, "' as subclass of '", getBaseClassName(), "'. The transaction will be reopen right after that. To avoid this behavior create the classes outside the transaction"); } catch (OSchemaException e) { if (!schema.existsClass(className)) throw e; } } else { // CHECK THE CLASS INHERITANCE final OClass cls = schema.getClass(className); if (!cls.isSubClassOf(getBaseClassName())) throw new IllegalArgumentException( "Class '" + className + "' is not an instance of " + getBaseClassName()); } return className; }