summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevan Goodwin <dgoodwin@redhat.com>2009-12-02 11:44:59 -0400
committerDevan Goodwin <dgoodwin@redhat.com>2009-12-02 11:45:15 -0400
commitce5b41ea6b626d2a41b78b832e44135847ef3c06 (patch)
tree82efa92da3e56a04692c5d03686cc1f177303404
parent0fc5a95716e3627f0c66854ba80d6d90b3326121 (diff)
downloadcandlepin-ce5b41ea6b626d2a41b78b832e44135847ef3c06.tar.gz
candlepin-ce5b41ea6b626d2a41b78b832e44135847ef3c06.tar.xz
candlepin-ce5b41ea6b626d2a41b78b832e44135847ef3c06.zip
Map Consumer hierarchy.
-rw-r--r--proxy/code/src/META-INF/persistence.xml4
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java27
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java27
3 files changed, 43 insertions, 15 deletions
diff --git a/proxy/code/src/META-INF/persistence.xml b/proxy/code/src/META-INF/persistence.xml
index a28f6ca..47559cb 100644
--- a/proxy/code/src/META-INF/persistence.xml
+++ b/proxy/code/src/META-INF/persistence.xml
@@ -12,9 +12,7 @@
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
- <!--
- <property name="hibernate.show_sql" value="false" />
- -->
+ <property name="hibernate.show_sql" value="true" />
</properties>
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java
index 5e11a6a..3e3cc66 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java
@@ -66,8 +66,11 @@ public class Consumer {
private Owner owner;
// TODO: Is this worth mapping? Do we need a hierarchy amidst consumers?
- @Transient
- private Consumer parent;
+ @OneToMany(targetEntity=Consumer.class, cascade=CascadeType.ALL)
+ @JoinTable(name="cp_consumer_hierarchy",
+ joinColumns=@JoinColumn(name="PARENT_CONSUMER_ID"),
+ inverseJoinColumns=@JoinColumn(name="CHILD_CONSUMER_ID"))
+ private Set<Consumer> childConsumers;
// TODO: Are we sure we want to track this explicitly? Wouldn't we examine the
// entitlements we're consuming and the products associated to them for this info?
@@ -91,6 +94,7 @@ public class Consumer {
this.info = new ConsumerInfo();
this.info.setConsumer(this); // TODO: ???
+ this.childConsumers = new HashSet<Consumer>();
this.consumedProducts = new HashSet<Product>();
this.entitlements = new HashSet<Entitlement>();
}
@@ -98,6 +102,7 @@ public class Consumer {
public Consumer() {
this.info = new ConsumerInfo();
this.info.setConsumer(this); // TODO: ???
+ this.childConsumers = new HashSet<Consumer>();
this.consumedProducts = new HashSet<Product>();
this.entitlements = new HashSet<Entitlement>();
}
@@ -144,18 +149,16 @@ public class Consumer {
type = typeIn;
}
- /**
- * @return the parent
- */
- public Consumer getParent() {
- return parent;
+ public Set<Consumer> getChildConsumers() {
+ return childConsumers;
}
- /**
- * @param parent the parent to set
- */
- public void setParent(Consumer parent) {
- this.parent = parent;
+ public void setChildConsumers(Set<Consumer> childConsumers) {
+ this.childConsumers = childConsumers;
+ }
+
+ public void addChildConsumer(Consumer child) {
+ this.childConsumers.add(child);
}
/**
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java
index aedb49d..7fccd33 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java
@@ -152,4 +152,31 @@ public class ConsumerTest extends DatabaseTestFixture {
assertNull(lookedUp);
}
+ @Test
+ public void testConsumerHierarchy() {
+ beginTransaction();
+
+ Consumer child1 = new Consumer("child1asd", owner, consumerType);
+ child1.setMetadataField("foo6", "bar");
+// child1.addConsumedProduct(rhel);
+ em.persist(child1);
+ commitTransaction();
+
+ beginTransaction();
+ Consumer child2 = new Consumer("child2", owner, consumerType);
+ child2.setMetadataField("foo87", "bar");
+// child2.addConsumedProduct(rhel);
+ em.persist(child2);
+ commitTransaction();
+
+ beginTransaction();
+ consumer.addChildConsumer(child1);
+ consumer.addChildConsumer(child2);
+ em.persist(consumer);
+ commitTransaction();
+
+ Consumer lookedUp = (Consumer)em.find(Consumer.class, consumer.getId());
+ assertEquals(2, lookedUp.getChildConsumers().size());
+ }
+
}