diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseUtils.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseUtils.java index 5383de9b8271979e46053d7713d70973fba9eb46..6ef6fdb91039a7c24fb3e686c42b1bbf816638d3 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseUtils.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseUtils.java @@ -85,13 +85,27 @@ public class DatabaseUtils { return replacementCount; } - private static void processPropertiesStage1( - final List<Property> stage1Inserts, final Property p, final EntityInterface e) { - if (!p.isDescOverride() + /** + * Determines whether the property p of entity e needs a replacement property to be stored in the + * database. A property needs a replacement property if it overrides the description, name, or + * datatype and if it does not have a unique property ID, or if it has properties, or if it is + * some kind of collection (e.g. list). + * + * @param p + * @param e + * @return true if the property needs a replacement property, false otherwise + */ + private static boolean noReplacementneeded(final Property p, final EntityInterface e) { + return (!p.isDescOverride() && !p.isNameOverride() && !p.isDatatypeOverride() && (!p.hasProperties() || hasUniquePropertyId(p, e)) - && !(p.getDatatype() instanceof AbstractCollectionDatatype)) { + && !(p.getDatatype() instanceof AbstractCollectionDatatype)); + } + + private static void processPropertiesStage1( + final List<Property> stage1Inserts, final Property p, final EntityInterface e) { + if (noReplacementneeded(p, e)) { stage1Inserts.add(p); processSubPropertiesStage1(stage1Inserts, p); } else { @@ -127,6 +141,9 @@ public class DatabaseUtils { } } + /* + * Returns true if the entity e has no other property with the same ID as the property p. + */ private static boolean hasUniquePropertyId(final EntityInterface p, final EntityInterface e) { final EntityID id = p.getId(); for (final EntityInterface p2 : e.getProperties()) { diff --git a/src/main/java/org/caosdb/server/datatype/AbstractCollectionDatatype.java b/src/main/java/org/caosdb/server/datatype/AbstractCollectionDatatype.java index 1d816947d642e2ccb6f9867ced4478ea9a59c2d3..27f71b25c234b99836ca57739d3abe387f7916b8 100644 --- a/src/main/java/org/caosdb/server/datatype/AbstractCollectionDatatype.java +++ b/src/main/java/org/caosdb/server/datatype/AbstractCollectionDatatype.java @@ -35,6 +35,7 @@ public abstract class AbstractCollectionDatatype extends AbstractDatatype { private static HashMap<String, CollectionDatatypeFactory> instances = new HashMap<String, CollectionDatatypeFactory>(); static Pattern p = + // with < and > this evaluates to: "^([^<]+)<([^>]+)>$" Pattern.compile( "^([^" + LEFT_DELIMITER