protected OClassImpl createClassInstance(String className, int[] clusterIds) { return new OClassEmbedded(this, className, clusterIds); }
protected void clearCustomInternal() { acquireSchemaWriteLock(); try { checkEmbedded(); customFields = null; } finally { releaseSchemaWriteLock(); } }
@Override public OProperty call() throws Exception { return addPropertyInternal(propertyName, type, linkedType, linkedClass, unsafe); } });
protected OClass removeBaseClassInternal(final OClass baseClass) { acquireSchemaWriteLock(); try { checkEmbedded(); if (subclasses == null) return this; if (subclasses.remove(baseClass)) removePolymorphicClusterIds((OClassImpl) baseClass); return this; } finally { releaseSchemaWriteLock(); } }
protected void setStrictModeInternal(final boolean iStrict) { getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); acquireSchemaWriteLock(); try { checkEmbedded(); this.strictMode = iStrict; } finally { releaseSchemaWriteLock(); } }
public OClassImpl setEncryption(final String iValue) { final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String.format("alter class `%s` encryption %s", name, iValue); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); setEncryptionInternal(database, iValue); } else setEncryptionInternal(database, iValue); } finally { releaseSchemaWriteLock(); } return this; }
protected void setAbstractInternal(ODatabaseDocumentInternal database, final boolean isAbstract) { database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); acquireSchemaWriteLock(); try { if (isAbstract) { if (count() > 0) throw new IllegalStateException("Cannot set the class as abstract because contains records."); tryDropCluster(defaultClusterId); for (int clusterId : getClusterIds()) { tryDropCluster(clusterId); removePolymorphicClusterId(clusterId); ((OSchemaEmbedded) owner).removeClusterForClass(database, clusterId, this); setClusterIds(new int[] { NOT_EXISTENT_CLUSTER_ID }); this.clusterIds[0] = this.defaultClusterId; this.polymorphicClusterIds = Arrays.copyOf(clusterIds, clusterIds.length); for (OClass clazz : getAllSubclasses()) { if (clazz instanceof OClassImpl) { addPolymorphicClusterIds((OClassImpl) clazz); } else { OLogManager.instance().warn(this, "Warning: cannot set polymorphic cluster IDs for class " + name); releaseSchemaWriteLock();
public OClass addClusterId(final int clusterId) { final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); if (isAbstract()) { throw new OSchemaException("Impossible to associate a cluster to an abstract class class"); } acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String.format("alter class `%s` addcluster %d", name, clusterId); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); addClusterIdInternal(database, clusterId); } else addClusterIdInternal(database, clusterId); } finally { releaseSchemaWriteLock(); } return this; }
checkPersistentPropertyType(getDatabase(), name, type); OPropertyImpl.checkSupportLinkedClass(type); acquireSchemaWriteLock(); try { checkEmbedded(); prop = createPropertyInstance(global); prop.setLinkedClassInternal(linkedClass); } finally { releaseSchemaWriteLock(); fireDatabaseMigration(getDatabase(), name, type);
public void clearCustom() { final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String.format("alter class `%s` custom clear", getName()); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); clearCustomInternal(); } else clearCustomInternal(); } finally { releaseSchemaWriteLock(); } }
public OClassImpl setCustom(final String name, final String value) { final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String.format("alter class `%s` custom `%s`=%s", getName(), name, value); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); setCustomInternal(name, value); } else setCustomInternal(name, value); return this; } finally { releaseSchemaWriteLock(); } }
@Override public OClass addSuperClass(final OClass superClass) { final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); checkParametersConflict(superClass); acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String .format("alter class `%s` superclass +`%s`", name, superClass != null ? superClass.getName() : null); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); addSuperClassInternal(database, superClass); } else addSuperClassInternal(database, superClass); } finally { releaseSchemaWriteLock(); } return this; }
public OClass removeClusterId(final int clusterId) { final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); if (clusterIds.length == 1 && clusterId == clusterIds[0]) throw new ODatabaseException(" Impossible to remove the last cluster of class '" + getName() + "' drop the class instead"); acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String.format("alter class `%s` removecluster %d", name, clusterId); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); removeClusterIdInternal(database, clusterId); } else removeClusterIdInternal(database, clusterId); } finally { releaseSchemaWriteLock(); } return this; }
@Override public OClass setSuperClasses(final List<? extends OClass> classes) { final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); if (classes != null) { List<OClass> toCheck = new ArrayList<OClass>(classes); toCheck.add(this); checkParametersConflict(toCheck); acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); setSuperClassesInternal(classes); } else setSuperClassesInternal(classes); releaseSchemaWriteLock();
public OClass setName(final String name) { if (getName().equals(name)) return this; final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); final Character wrongCharacter = OSchemaShared.checkClassNameIfValid(name); OClass oClass = database.getMetadata().getSchema().getClass(name); if (oClass != null) { String error = String.format("Cannot rename class %s to %s. A Class with name %s exists", this.name, name, name); throw new OSchemaException(error); } if (wrongCharacter != null) throw new OSchemaException( "Invalid class name found. Character '" + wrongCharacter + "' cannot be used in class name '" + name + "'"); acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String.format("alter class `%s` name `%s`", this.name, name); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); setNameInternal(database, name); } else setNameInternal(database, name); } finally { releaseSchemaWriteLock(); } return this; }
/** * {@inheritDoc} */ @Override public OClass truncateCluster(String clusterName) { getDatabase().checkSecurity(ORule.ResourceGeneric.CLASS, ORole.PERMISSION_DELETE, name); acquireSchemaReadLock(); try { final ODatabaseDocumentInternal database = getDatabase(); final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String.format("truncate cluster %s", clusterName); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); truncateClusterInternal(clusterName, database); } else truncateClusterInternal(clusterName, database); } finally { releaseSchemaReadLock(); } return this; }
protected void setNameInternal(ODatabaseDocumentInternal database, final String name) { database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); acquireSchemaWriteLock(); try { checkEmbedded(); final String oldName = this.name; owner.changeClassName(database, this.name, name, this); this.name = name; renameCluster(oldName, this.name); } finally { releaseSchemaWriteLock(); } }
private OClass removeClusterIdInternal(ODatabaseDocumentInternal database, final int clusterToRemove) { acquireSchemaWriteLock(); try { checkEmbedded(); removePolymorphicClusterId(clusterToRemove); releaseSchemaWriteLock();
protected OClass addClusterIdInternal(ODatabaseDocumentInternal database, final int clusterId) { acquireSchemaWriteLock(); try { checkEmbedded(); owner.checkClusterCanBeAdded(clusterId, this); for (int currId : clusterIds) if (currId == clusterId) // ALREADY ADDED return this; clusterIds = OArrays.copyOf(clusterIds, clusterIds.length + 1); clusterIds[clusterIds.length - 1] = clusterId; Arrays.sort(clusterIds); addPolymorphicClusterId(clusterId); if (defaultClusterId == NOT_EXISTENT_CLUSTER_ID) defaultClusterId = clusterId; ((OSchemaEmbedded) owner).addClusterForClass(database, clusterId, this); return this; } finally { releaseSchemaWriteLock(); } }
protected void addSuperClassInternal(ODatabaseDocumentInternal database, final OClass superClass) { acquireSchemaWriteLock(); try { final OClassImpl cls; if (superClass instanceof OClassAbstractDelegate) cls = (OClassImpl) ((OClassAbstractDelegate) superClass).delegate; else cls = (OClassImpl) superClass; if (cls != null) { // CHECK THE USER HAS UPDATE PRIVILEGE AGAINST EXTENDING CLASS final OSecurityUser user = database.getUser(); if (user != null) user.allow(ORule.ResourceGeneric.CLASS, cls.getName(), ORole.PERMISSION_UPDATE); if (superClasses.contains(superClass)) { throw new OSchemaException( "Class: '" + this.getName() + "' already has the class '" + superClass.getName() + "' as superclass"); } cls.addBaseClass(this); superClasses.add(cls); } } finally { releaseSchemaWriteLock(); } }