private OClass createClassInternal(final String className, final OClass superClass, final int[] clusterIdsToAdd) {
acquireSchemaWriteLock();
try {
if (className == null || className.length() == 0)
throw new OSchemaException("Found class name null or empty");
if (Character.isDigit(className.charAt(0)))
throw new OSchemaException("Found invalid class name. Cannot start with numbers");
final Character wrongCharacter = checkNameIfValid(className);
if (wrongCharacter != null)
throw new OSchemaException("Found invalid class name. Character '" + wrongCharacter + "' cannot be used in class name.");
final ODatabaseRecordInternal database = getDatabase();
final OStorage storage = database.getStorage();
checkEmbedded(storage);
checkClustersAreAbsent(clusterIdsToAdd);
final int[] clusterIds;
if (clusterIdsToAdd == null || clusterIdsToAdd.length == 0) {
// CREATE A NEW CLUSTER(S)
final int minimumClusters = storage.getConfiguration().getMinimumClusters();
clusterIds = new int[minimumClusters];
if (minimumClusters <= 1) {
clusterIds[0] = database.getClusterIdByName(className);
if (clusterIds[0] == -1)
clusterIds[0] = database.addCluster(className);
} else
for (int i = 0; i < minimumClusters; ++i) {
clusterIds[i] = database.getClusterIdByName(className + "_" + i);
if (clusterIds[i] == -1)
clusterIds[i] = database.addCluster(className + "_" + i);
}
} else
clusterIds = clusterIdsToAdd;
database.checkSecurity(ODatabaseSecurityResources.SCHEMA, ORole.PERMISSION_CREATE);
final String key = className.toLowerCase();
if (classes.containsKey(key))
throw new OSchemaException("Class " + className + " already exists in current database");
OClassImpl cls = new OClassImpl(this, className, clusterIds);
classes.put(key, cls);
if (cls.getShortName() != null)