diff options
author | Adrian Likins <adrian@alikins.usersys.redhat.com> | 2009-12-03 10:16:59 -0500 |
---|---|---|
committer | Adrian Likins <adrian@alikins.usersys.redhat.com> | 2009-12-03 10:16:59 -0500 |
commit | c26e628a4fd5d8796c777b0f7daa0f43110f96e9 (patch) | |
tree | 88bbcc022ae9aa95384ca6097a93e6a0a9ad9783 | |
parent | 0fc5a95716e3627f0c66854ba80d6d90b3326121 (diff) | |
download | candlepin-c26e628a4fd5d8796c777b0f7daa0f43110f96e9.tar.gz candlepin-c26e628a4fd5d8796c777b0f7daa0f43110f96e9.tar.xz candlepin-c26e628a4fd5d8796c777b0f7daa0f43110f96e9.zip |
add annotations for ForeignKeys, so the names are quite as ugly as the
autogenerated ones which are something along the lines of
"FKEF232442242"
6 files changed, 23 insertions, 1 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java index 5e11a6a..b22249d 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java @@ -36,6 +36,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.hibernate.annotations.ForeignKey; /** * A Consumer is the entity that uses a given Entitlement. It can be a user, @@ -60,9 +61,11 @@ public class Consumer { @ManyToOne @JoinColumn(nullable=false) + @ForeignKey(name="fk_consumer_consumer_type") private ConsumerType type; @ManyToOne + @ForeignKey(name="fk_consumer_owner") private Owner owner; // TODO: Is this worth mapping? Do we need a hierarchy amidst consumers? @@ -72,6 +75,9 @@ public class Consumer { // 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? @OneToMany + @ForeignKey(name = "fk_consumer_product_consumer_id", + inverseName = "fk_consumer_product_product_id") + @JoinTable(name="cp_consumer_products", joinColumns=@JoinColumn(name="consumer_id"), inverseJoinColumns=@JoinColumn(name="product_id")) diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java b/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java index f1614a8..3f7bb94 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java @@ -27,6 +27,9 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.hibernate.annotations.ForeignKey; + + /** * Entitlements are documents either signed XML or other certificate which @@ -55,10 +58,12 @@ public class Entitlement { private Long id; @ManyToOne + @ForeignKey(name="fk_entitlement_owner") @JoinColumn(nullable=false) private Owner owner; @ManyToOne + @ForeignKey(name="fk_entitlement_entitlement_pool") @JoinColumn(nullable=false) private EntitlementPool pool; diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java index 7829048..80b949b 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java @@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.hibernate.annotations.ForeignKey; /** * Represents a pool of products eligible to be consumed (entitled). @@ -44,10 +45,12 @@ public class EntitlementPool { private Long id; @ManyToOne + @ForeignKey(name="fk_entitlement_pool_owner") @JoinColumn(nullable=false) private Owner owner; @ManyToOne + @ForeignKey(name="fk_entitlement_pool_product") @JoinColumn(nullable=false) private Product product; diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java index 46f8999..4765410 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java @@ -29,6 +29,9 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; +import org.hibernate.annotations.ForeignKey; + + /** * Represents the owner of entitlements. * @@ -55,6 +58,7 @@ public class Owner { // EntitlementPool is the owning side of this relationship. @OneToMany(mappedBy="owner", targetEntity=EntitlementPool.class) + @ForeignKey(name="fk_user_owner_id") private List<EntitlementPool> entitlementPools; @Transient diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Product.java b/proxy/code/src/org/fedoraproject/candlepin/model/Product.java index 127287c..18447f1 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Product.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Product.java @@ -30,6 +30,7 @@ import javax.persistence.Table; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; +import org.hibernate.annotations.ForeignKey; /** * Represents a Product that can be consumed and entitled. Products define @@ -55,6 +56,8 @@ public class Product { private String name; @OneToMany(targetEntity=Product.class, cascade=CascadeType.ALL) + @ForeignKey(name = "fk_product_product_id", + inverseName = "fk_product_child_product_id") @JoinTable(name="cp_product_hierarchy", joinColumns=@JoinColumn(name="PARENT_PRODUCT_ID"), inverseJoinColumns=@JoinColumn(name="CHILD_PRODUCT_ID")) diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/User.java b/proxy/code/src/org/fedoraproject/candlepin/model/User.java index 33a6ab5..7594e9d 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/User.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/User.java @@ -15,7 +15,6 @@ package org.fedoraproject.candlepin.model; import java.util.Formatter; - import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -26,6 +25,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.hibernate.annotations.ForeignKey; /** * Represents the user. @@ -43,6 +43,7 @@ public class User { private Long id; @ManyToOne + @ForeignKey(name="fk_user_owner_id") private Owner owner; private String login; |