From 7f39f3bd598eb31e7562fe53012e6275f41fd0bb Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Tue, 16 Aug 2022 16:01:56 +0200
Subject: [PATCH] WIP: entity-id

---
 .../caosdb/server/database/DatabaseUtils.java | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/caosdb/server/database/DatabaseUtils.java b/src/main/java/org/caosdb/server/database/DatabaseUtils.java
index 4f6a58a4..8cc4aa89 100644
--- a/src/main/java/org/caosdb/server/database/DatabaseUtils.java
+++ b/src/main/java/org/caosdb/server/database/DatabaseUtils.java
@@ -37,8 +37,10 @@ import org.caosdb.server.datatype.CollectionValue;
 import org.caosdb.server.datatype.IndexedSingleValue;
 import org.caosdb.server.datatype.ReferenceValue;
 import org.caosdb.server.datatype.SingleValue;
+import org.caosdb.server.entity.EntityID;
 import org.caosdb.server.entity.EntityInterface;
 import org.caosdb.server.entity.Message;
+import org.caosdb.server.entity.RetrieveEntity;
 import org.caosdb.server.entity.Role;
 import org.caosdb.server.entity.StatementStatus;
 import org.caosdb.server.entity.wrapper.Domain;
@@ -72,8 +74,7 @@ public class DatabaseUtils {
       final List<EntityInterface> stage1Inserts, final EntityInterface e) {
     // entity value
     if (e.hasValue()) {
-      final Property p = new Property();
-      p.setId(e.getId());
+      final Property p = new Property(e);
       p.setStatementStatus(StatementStatus.FIX);
       p.setPIdx(0);
       p.setDatatype(e.getDatatype());
@@ -116,7 +117,7 @@ public class DatabaseUtils {
   }
 
   private static boolean hasUniquePropertyId(final EntityInterface p, final EntityInterface e) {
-    final Integer id = p.getId();
+    final EntityID id = p.getId();
     for (final EntityInterface p2 : e.getProperties()) {
       if (Objects.equal(p2.getId(), id) && p2 != p) {
         return false;
@@ -189,7 +190,7 @@ public class DatabaseUtils {
    *
    * <p>Never returns null.
    */
-  public static SparseEntity parseNameRoleACL(ResultSet rs) throws SQLException {
+  public static SparseEntity parseNameRoleACL(final ResultSet rs) throws SQLException {
     final SparseEntity ret = new SparseEntity();
     ret.role = bytes2UTF8(rs.getBytes("EntityRole"));
     ret.name = bytes2UTF8(rs.getBytes("EntityName"));
@@ -206,7 +207,7 @@ public class DatabaseUtils {
    * <p>Never returns null.
    */
   public static SparseEntity parseEntityResultSet(final ResultSet rs) throws SQLException {
-    SparseEntity ret = parseNameRoleACL(rs);
+    final SparseEntity ret = parseNameRoleACL(rs);
     ret.id = rs.getInt("EntityID");
     ret.description = bytes2UTF8(rs.getBytes("EntityDesc"));
     ret.datatype = bytes2UTF8(rs.getBytes("Datatype"));
@@ -247,8 +248,7 @@ public class DatabaseUtils {
   public static void parseParentsFromVerySparseEntity(
       final EntityInterface entity, final List<VerySparseEntity> pars) {
     for (final VerySparseEntity vsp : pars) {
-      final Parent p = new Parent();
-      p.setId(vsp.id);
+      final Parent p = new Parent(new RetrieveEntity(new EntityID(vsp.id)));
       p.setName(vsp.name);
       p.setDescription(vsp.description);
       entity.addParent(p);
@@ -256,7 +256,7 @@ public class DatabaseUtils {
   }
 
   private static void replace(
-      final Property p, final HashMap<Integer, Property> domainMap, boolean isHead) {
+      final Property p, final Map<EntityID, Property> domainMap, final boolean isHead) {
     // ... find the corresponding domain and replace it
     ReferenceValue ref;
     try {
@@ -264,7 +264,7 @@ public class DatabaseUtils {
     } catch (final Message e) {
       throw new RuntimeException("This should never happen.");
     }
-    final EntityInterface replacement = domainMap.get((ref.getId()));
+    final EntityInterface replacement = domainMap.get(ref.getId());
     if (replacement == null) {
       if (isHead) {
         throw new NullPointerException("Replacement was null");
@@ -297,7 +297,7 @@ public class DatabaseUtils {
       final EntityInterface e, final List<Property> protoProperties) {
     // here we will store every domain we can find and we will index it by
     // its id.
-    final HashMap<Integer, Property> domainMap = new HashMap<Integer, Property>();
+    final Map<EntityID, Property> domainMap = new HashMap<>();
 
     // loop over all properties and collect the domains
     for (final Property p : protoProperties) {
@@ -323,7 +323,7 @@ public class DatabaseUtils {
     }
 
     // loop over all properties
-    boolean isHead =
+    final boolean isHead =
         e.getVersion().getSuccessors() == null || e.getVersion().getSuccessors().isEmpty();
     for (final Property p : protoProperties) {
 
@@ -368,7 +368,7 @@ public class DatabaseUtils {
   }
 
   private static Property parseFlatProperty(final FlatProperty fp) {
-    final Property property = new Property();
+    final Property property = new Property(new RetrieveEntity());
     property.parseFlatProperty(fp);
     return property;
   }
-- 
GitLab