Rebuild the full mapping from persistence-jpa-1.5.1 to reproduce the bug
[jpa-converters] / src / test / java / de / juplo / yourshouter / api / persistence / jpa / PrimaryKey.java
diff --git a/src/test/java/de/juplo/yourshouter/api/persistence/jpa/PrimaryKey.java b/src/test/java/de/juplo/yourshouter/api/persistence/jpa/PrimaryKey.java
new file mode 100644 (file)
index 0000000..83f6942
--- /dev/null
@@ -0,0 +1,129 @@
+package de.juplo.yourshouter.api.persistence.jpa;
+
+
+import de.juplo.yourshouter.api.model.DataEntry.NodeType;
+import de.juplo.yourshouter.api.model.Node;
+import de.juplo.yourshouter.api.model.NodeData;
+import de.juplo.yourshouter.api.storage.Storage;
+import de.juplo.yourshouter.api.storage.Uri;
+import java.io.Serializable;
+import java.net.URI;
+import java.util.Objects;
+
+
+
+/**
+ * Class, that acts as primary key for {@link Node}s.
+ * @author Kai Moritz
+ */
+public class PrimaryKey implements Serializable
+{
+  private URI source;
+  private NodeType nodeType;
+  private String id;
+
+
+  public PrimaryKey() {}
+
+  public PrimaryKey(Uri uri)
+  {
+    this.source = uri.source;
+    this.nodeType = uri.type;
+    this.id = uri.id;
+  }
+
+  public PrimaryKey(NodeData node)
+  {
+    this.source = node.getSource();
+    this.nodeType = node.getNodeType();
+    this.id = node.getId();
+  }
+
+  public PrimaryKey(NodeType type, String id)
+  {
+    this(Storage.getSource(), type, id);
+  }
+
+  public PrimaryKey(URI source, NodeType type, String id)
+  {
+    this.source = source;
+    this.nodeType = type;
+    this.id = id;
+  }
+
+
+  public URI getSource()
+  {
+    return source;
+  }
+
+  public void setSource(URI source)
+  {
+    this.source = source;
+  }
+
+  public NodeType getNodeType()
+  {
+    return nodeType;
+  }
+
+  public void setNodeType(NodeType nodeType)
+  {
+    this.nodeType = nodeType;
+  }
+
+  public String getId()
+  {
+    return id;
+  }
+
+  public void setId(String id)
+  {
+    this.id = id;
+  }
+
+
+  @Override
+  public int hashCode()
+  {
+    int hash = 3;
+    hash = 53 * hash + Objects.hashCode(this.source);
+    hash = 53 * hash + Objects.hashCode(this.nodeType);
+    hash = 53 * hash + Objects.hashCode(this.id);
+    return hash;
+  }
+
+  @Override
+  public boolean equals(Object o)
+  {
+    if (this == o)
+      return true;
+
+    if (o == null)
+      return false;
+
+    if (!(o instanceof PrimaryKey))
+      return false;
+
+    final PrimaryKey other = (PrimaryKey)o;
+    if (!Objects.equals(this.source, other.source))
+      return false;
+    if (this.nodeType != other.nodeType)
+      return false;
+    return Objects.equals(this.id, other.id);
+  }
+
+
+  @Override
+  public String toString()
+  {
+    StringBuilder builder = new StringBuilder();
+    builder.append(source);
+    builder.append('/');
+    builder.append(nodeType);
+    builder.append('/');
+    builder.append(id);
+    builder.append('/');
+    return builder.toString();
+  }
+}