diff --git a/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OClassImpl.java b/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OClassImpl.java index 2d0d474e441..d78d92efad9 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OClassImpl.java +++ b/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OClassImpl.java @@ -20,7 +20,17 @@ package com.orientechnologies.orient.core.metadata.schema; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import com.orientechnologies.common.listener.OProgressListener; import com.orientechnologies.common.util.OArrays; @@ -583,6 +593,10 @@ void removeSuperClassInternal(final OClass superClass) { public OClass setName(final String name) { getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); + final Character wrongCharacter = OSchemaShared.checkClassNameIfValid(name); + if (wrongCharacter != null) + throw new OSchemaException("Invalid class name found. Character '" + wrongCharacter + "' cannot be used in class name '" + + name + "'"); acquireSchemaWriteLock(); try { final ODatabaseDocumentInternal database = getDatabase(); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLAlterClass.java b/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLAlterClass.java index 789795162dc..5f61ae001bf 100644 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLAlterClass.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLAlterClass.java @@ -90,6 +90,12 @@ public OCommandExecutorSQLAlterClass parse(final OCommandRequest iRequest) { value = parserText.substring(pos + 1).trim(); + if (parserTextUpperCase.endsWith("UNSAFE")) { + unsafe = true; + value = value.substring(0, value.length() - "UNSAFE".length()); + for (int i = value.length() - 1; value.charAt(i) == ' ' || value.charAt(i) == '\t'; i--) + value = value.substring(0, value.length() - 1); + } if (value.length() == 0) throw new OCommandSQLParsingException("Missed the property's value to change for attribute '" + attribute + "'", parserText, oldPos); @@ -97,9 +103,6 @@ public OCommandExecutorSQLAlterClass parse(final OCommandRequest iRequest) { if (value.equalsIgnoreCase("null")) value = null; - if (parserTextUpperCase.endsWith("UNSAFE")) - unsafe = true; - return this; } diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/SQLAlterClassTest.java b/core/src/test/java/com/orientechnologies/orient/core/sql/SQLAlterClassTest.java new file mode 100644 index 00000000000..87de126d72d --- /dev/null +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/SQLAlterClassTest.java @@ -0,0 +1,34 @@ +package com.orientechnologies.orient.core.sql; + +import static org.testng.AssertJUnit.assertNotNull; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.orientechnologies.orient.core.db.document.ODatabaseDocument; +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.orient.core.exception.OSchemaException; + +public class SQLAlterClassTest { + + @Test + public void alterClassRenameTest() { + ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + SQLAlterClassTest.class.getName()); + db.create(); + try { + db.getMetadata().getSchema().createClass("TestClass"); + + try { + db.command(new OCommandSQL("alter class TestClass name = 'test_class'")).execute(); + Assert.fail("the rename should fail for wrong syntax"); + } catch (OSchemaException ex) { + + } + assertNotNull(db.getMetadata().getSchema().getClass("TestClass")); + + } finally { + db.drop(); + } + } + +}