Return-Path: Delivered-To: apmail-db-jdo-dev-archive@www.apache.org Received: (qmail 33100 invoked from network); 10 Jul 2007 19:19:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Jul 2007 19:19:51 -0000 Received: (qmail 55558 invoked by uid 500); 10 Jul 2007 19:19:52 -0000 Mailing-List: contact jdo-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-dev@db.apache.org Received: (qmail 55547 invoked by uid 99); 10 Jul 2007 19:19:52 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Jul 2007 12:19:52 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [192.18.43.133] (HELO sca-es-mail-2.sun.com) (192.18.43.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Jul 2007 12:19:47 -0700 Received: from fe-sfbay-09.sun.com ([192.18.43.129]) by sca-es-mail-2.sun.com (8.13.7+Sun/8.12.9) with ESMTP id l6AJJRsk000847 for ; Tue, 10 Jul 2007 12:19:27 -0700 (PDT) Received: from conversion-daemon.fe-sfbay-09.sun.com by fe-sfbay-09.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) id <0JKZ00G019N20I00@fe-sfbay-09.sun.com> (original mail from Craig.Russell@Sun.COM) for jdo-dev@db.apache.org; Tue, 10 Jul 2007 12:19:26 -0700 (PDT) Received: from [129.145.132.68] by fe-sfbay-09.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) with ESMTPSA id <0JKZ000FJ9OEUP40@fe-sfbay-09.sun.com> for jdo-dev@db.apache.org; Tue, 10 Jul 2007 12:19:26 -0700 (PDT) Date: Tue, 10 Jul 2007 12:19:24 -0700 From: Craig L Russell Subject: JDO Spec clarifications for mapping metadata Sender: Craig.Russell@Sun.COM To: Apache JDO project , JDO Expert Group Message-id: <4199328E-FA12-45C6-B9C6-7E2618452B07@SUN.com> MIME-version: 1.0 X-Mailer: Apple Mail (2.752.3) Content-type: multipart/signed; protocol="application/pkcs7-signature"; boundary=Apple-Mail-93--370465921; micalg=sha1 X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-93--370465921 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Here's a work in progress on some changes to annotations to better align with xml metadata. Mapping Basic Fields/Properties Basic fields/properties are non-relationship fields and methods that are typically mapped to a single column in the primary table for the class/interface in the database. It is possible to map to multiple columns but this behavior is not standardized. The column of the row corresponding to the instance contains the value of the field/ property. If the mapped column is in the primary table for the class/ interface, then the column name is the only required mapping data. If the column is in a secondary table, then the secondary table name, column name in the secondary table, and join condition are needed. The join condition can be specified either at the class/interface level or at the field/property level. The column in the join metadata refers to the column in the secondary table that is joined to the target column in the primary table. The default target column is the primary key column of the primary table. The join column might be specified simply by name. For multiple primary key columns, the join columns must be explicitly specified with their corresponding target columns. If the join condition is specified at the class/interface level, the same join condition can be shared among several fields/properties. In this case, the join metadata contains both the join and the secondary table information. If the join condition is specified at the field/property level, then the join condition applies only to that field/property. In this case, the table is specified by the field/property metadata and the join condition is specified in the join metadata associated with the field/ property. Mapping Direct Relationship Fields/Properties Direct relationship fields/properties are of a type of a persistence- capable class or interface, and are mapped to a column or columns in the primary or secondary table. The column(s) contain the same value (s) as the row(s) in the primary table of the related class. The usage of join metadata is the same as for basic field/property mapping. Mapping Both Sides of a Relationship If one side of a relationship is a direct relationship and the other side is a multi-valued type (Collection or subclass) then both sides might be mapped to the same database artifact. In this case, the direct side is mapped by specifying the column metadata and the multi- valued side is mapped by specifying the corresponding field of the other side. Mapping Direct Relationships Using a Join Table If one side of a relationship is a direct relationship and the other side is a multi-valued type (Array or Collection) and the relationship uses a join table, there will typically be a unique constraint on the column(s) in the join table that are mapped to the class containing the direct relationship. In this case, the join table is considered a secondary table of the class/interface containing the direct relationship, and the unique column(s) comprise the join condition. There is no shared join information at the class/ interface level. Mapping Key-Only Join Tables Key-only join tables are used to represent many-to-many relationships. Each of the types in the domain classes is a multi- valued type referring to the other side. The mapping on one side identifies the join table in the field/property metadata. There is no shared join information at the class/interface level. The join metadata of the field identifies the column(s) in the join table that refer to the primary key column(s) in the primary table. The mapping metadata on the other side names the corresponding field/property where the mapping is specified. Specifying Database Constraints and Indexes for Columns There are several places where database constraints or indexes are usefully applied to mapped columns. These fall into four categories: primary key, foreign key, uniqueness constraints, and indexes. Primary Key Constraints Primary key constraints for primary tables are implied by declaring the primary key field(s) for the class. Unless explicitly specified, a system-defined primary key constraint name is generated. If a primary key constraint name is desired, it can be specified using the primary key metadata associated with the class/interface. Primary key constraints for secondary tables need to be explicitly declared if desired. If the primary key is associated with the joined columns, the only additional information is the name of the primary key constraint. In this case, the primary key name is specified via the join metadata at either the class/interface level or the field/ property level. *[This is missing from the Join annotation]. Primary key constraints join tables for relationship field mappings must be explicitly declared if desired. In this case, they are declared as metadata on the field/property. The table on which the primary keys are being declared is the table associated with the field/property. The columns composing the primary key constraint are named in the primary key metadata. Foreign Key Constraints Foreign key constraints associated with columns in the primary table mapped to relationship fields/properties are declared on the associated field/property. *[This is missing from the Field/Property annotation]. Foreign key constraints associated with secondary tables are either associated with the join condition or with the relationship to a third table. If a foreign key constraint is desired on the join condition, the only additional information is the name of the foreign key constraint. *[This is missing from the Join annotation]. If a foreign key constraint is desired on the relationship to a third table, the name of the foreign key constraint is given on the foreign key metadata associated with the field/property. Unique Key Constraints Unique key constraints associated with a column in the primary or secondary table mapped to a field/property are declared on the associated field/property. *[This is missing from the Field/Property annotation]. Unique key constraints not associated with a column in the primary or secondary table mapped to a field/property are declared in the metadata for the class/interface. Indexes Indexes associated with a column in the primary or secondary table mapped to a field/property are declared on the associated field/ property. *[This is missing from the Field/Property annotation]. Indexes not associated with a column in the primary or secondary table mapped to a field/property are declared in the metadata for the class/interface. Changes needed to annotations: 1. Provide a way to specify the primary key name for Join annotation, e.g. String primaryKey(). 2. Provide a way to specify the foreign key name for Join annotation, e.g. String foreignKey(). 3. Provide a way to specify the foreign key name for a Field and Property annotation, e.g. String foreignKey(). 4. Provide a way to specify the unique key constraint name for Field and Property annotation, e.g. String uniqueKey(). This element provides the name of the unique key constraint and sets the String unique() element to "true". 5. Provide a way to specify the index name for Field and Property annotation, e.g. String index(). This element provides the name of the index and sets the String indexed() element to "true". Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:Craig.Russell@sun.com P.S. A good JDO? O, Gasp! --Apple-Mail-93--370465921 Content-Transfer-Encoding: base64 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Disposition: attachment; filename=smime.p7s MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGUDCCAwkw ggJyoAMCAQICECpJVMO68ii+Xfsc1O1YYFIwDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UEBhMCWkEx JTAjBgNVBAoTHFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMTI1RoYXd0ZSBQ ZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBMB4XDTA2MTIwOTE5NTEwNVoXDTA3MTIwOTE5NTEw NVowbDEQMA4GA1UEBBMHUnVzc2VsbDEUMBIGA1UEKhMLQ3JhaWcgTGFpcmQxHDAaBgNVBAMTE0Ny YWlnIExhaXJkIFJ1c3NlbGwxJDAiBgkqhkiG9w0BCQEWFUNyYWlnLlJ1c3NlbGxAU3VuLkNPTTCC ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMNAB4Ih+ShsCt89HzqIdwEx8L4o1UHiY6V7 16mrCedfd4Y0/uI7z9Zam8ysgEh+F7aDnQEKmEsVFN35G4nPMfLU6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