Skip to content

Commit

Permalink
moved check for property consistence only on public api
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Mar 31, 2016
1 parent 40b0219 commit e329933
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Expand Up @@ -385,6 +385,11 @@ public OClass setSuperClassesByNames(List<String> classNames) {
@Override
public OClass setSuperClasses(final List<? extends OClass> classes) {
getDatabase().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 ODatabaseDocumentInternal database = getDatabase();
Expand Down Expand Up @@ -436,7 +441,6 @@ void setSuperClassesInternal(final List<? extends OClass> classes) {
newSuperClasses.add(cls);
}

checkParametersConflict(newSuperClasses);
List<OClassImpl> toAddList = new ArrayList<OClassImpl>(newSuperClasses);
toAddList.removeAll(superClasses);
List<OClassImpl> toRemoveList = new ArrayList<OClassImpl>(superClasses);
Expand All @@ -458,6 +462,7 @@ void setSuperClassesInternal(final List<? extends OClass> classes) {
@Override
public OClass addSuperClass(final OClass superClass) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
checkParametersConflict(superClass);
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
Expand Down Expand Up @@ -2548,7 +2553,6 @@ private void addClusterIdToIndexes(int iId) {
*/
private OClass addBaseClass(final OClassImpl iBaseClass) {
checkRecursion(iBaseClass);
checkParametersConflict(iBaseClass);

if (subclasses == null)
subclasses = new ArrayList<OClass>();
Expand All @@ -2573,23 +2577,31 @@ private void checkParametersConflict(final OClass baseClass) {
}
}

private void checkParametersConflict(List<OClassImpl> classes) {
final Map<String, OProperty> commulative = new HashMap<String, OProperty>();
protected static void checkParametersConflict(List<OClass> classes) {
final Map<String, OProperty> comulative = new HashMap<String, OProperty>();
final Map<String, OProperty> properties = new HashMap<String, OProperty>();

for (OClassImpl superClass : classes) {
superClass.propertiesMap(properties, false);
for (OClass superClass : classes) {
if (superClass == null)
continue;
OClassImpl impl;

if (superClass instanceof OClassAbstractDelegate)
impl = (OClassImpl) ((OClassAbstractDelegate) superClass).delegate;
else
impl = (OClassImpl) superClass;
impl.propertiesMap(properties, false);
for (Map.Entry<String, OProperty> entry : properties.entrySet()) {
if (commulative.containsKey(entry.getKey())) {
if (comulative.containsKey(entry.getKey())) {
final String property = entry.getKey();
final OProperty existingProperty = commulative.get(property);
final OProperty existingProperty = comulative.get(property);
if (!existingProperty.getType().equals(entry.getValue().getType())) {
throw new OSchemaException("Properties conflict detected: '" + existingProperty + "] vs [" + entry.getValue() + "]");
}
}
}

commulative.putAll(properties);
comulative.putAll(properties);
properties.clear();
}
}
Expand Down
Expand Up @@ -948,6 +948,9 @@ private OClass doCreateClass(final String className, final int[] clusterIds, int
StringBuilder cmd = null;

getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
if (superClasses != null)
OClassImpl.checkParametersConflict(Arrays.asList(superClasses));

acquireSchemaWriteLock();
try {

Expand Down Expand Up @@ -1034,6 +1037,8 @@ private OClass doCreateClass(final String className, final int clusters, final i
StringBuilder cmd = null;

getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
if(superClasses != null)
OClassImpl.checkParametersConflict(Arrays.asList(superClasses));
acquireSchemaWriteLock();
try {

Expand Down

0 comments on commit e329933

Please sign in to comment.