Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 76327 invoked from network); 20 Feb 2008 20:42:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Feb 2008 20:42:19 -0000 Received: (qmail 90754 invoked by uid 500); 20 Feb 2008 20:42:14 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 90720 invoked by uid 500); 20 Feb 2008 20:42:14 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 90711 invoked by uid 99); 20 Feb 2008 20:42:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Feb 2008 12:42:14 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Feb 2008 20:41:26 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 8CBE2234C064 for ; Wed, 20 Feb 2008 12:41:00 -0800 (PST) Message-ID: <1565375762.1203540060575.JavaMail.www-data@brutus> Date: Wed, 20 Feb 2008 12:41:00 -0800 (PST) From: confluence@apache.org To: commits@jackrabbit.apache.org Subject: [CONF] Apache Jackrabbit: Mapping Atomic Fields (page edited) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Mapping Atomic Fields (JCR) edited by Jukka Zitting Page: http://cwiki.apache.org/confluence/display/JCR/Mapping+Atomic+Fields Changes: http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=75359&originalVersion=1&revisedVersion=2 Comment: --------------------------------------------------------------------- Change summary: --------------------------------------------------------------------- Change summary: --------------------------------------------------------------------- Change summary: --------------------------------------------------------------------- Change summary: --------------------------------------------------------------------- Content: --------------------------------------------------------------------- The field-descriptor maps a bean attribute based on a Java primitive type into a JCR property. By default, the persistence manager uses the correct mapping in function of the attribute type (see below the section "Supported Types"). Based on our model defined here, the following field-descriptor maps the bean field "title" (String type) into the JCR property "my:title". h2. Supported Types It is not necessary to specify the type in the field-descriptor. The Persistence Manager uses the java introspection to get information on each atomic field. || Java Type || Jcr Type || | String | STRING | | Boolean, boolean | BOOLEAN | | Double, double | DOUBLE | | Integer, int | DOUBLE | | Long, long | LONG | | byte\[\] | BINARY | | java.io.InputStream | BINARY | | java.util.Calendar | LONG (corresponding to Calendar.getTimeInMillis() | | java.sql.Timestamp | LONG (corresponding to Timestamp.getTime() | | java.util.Date | LONG (corresponding to java.util.Date.getTime() | Due to some issues with Jackrabbit (mainly with xpath queries), Calendar, Timestamp and date are converted into JCR LONG. We plan to add other converters for those types in the next release. h2. Using Another Atomic Type Converter The OCM framework gives you the freedom to choose another kind of mapping for atomic fields. For example, you can convert java.util.Date bean field into a JCR Date type instead of a JCR Long type. This can be done by writing your own atomic type converter class. Let's start with a simple example. If you want to use a mapping strategy which convert a boolean bean field into a JCR Long type, you have to make the following steps: h3. Specify the converter class in the field descriptor {code} {code} h3. Implement the converter class Use the interface org.apache.jackrabbit.ocm.persistence.atomic.AtomicTypeConverter {code:title=Int2BooleanTypeConverterImpl.java} package org.apache.jackrabbit.ocm.persistence.atomic; import javax.jcr.Value; import javax.jcr.ValueFactory; import org.apache.jackrabbit.ocm.exception.IncorrectAtomicTypeException; import org.apache.jackrabbit.ocm.persistence.atomictypeconverter.AtomicTypeConverter; /** * This is a simple converter which convert a boolean field value into a jcr long property. * * @author Christophe Lombart */ public class Int2BooleanTypeConverterImpl implements AtomicTypeConverter { /** * * @see org.apache.jackrabbit.ocm.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object) */ public Value getValue(ValueFactory valueFactory, Object propValue) { if (propValue == null) { return null; } boolean value = ((Boolean) propValue).booleanValue(); int jcrValue = 0; if (value) { jcrValue = 1; } return valueFactory.createValue(jcrValue); } /** * * @see org.apache.jackrabbit.ocm.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value) */ public Object getObject(Value value) { try { long jcrValue = value.getLong(); if (jcrValue == 1) { return new Boolean(true); } else { return new Boolean(false); } } catch (Exception e) { throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString() , e); } } /** * * @see org.apache.jackrabbit.ocm.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object) */ public String getStringValue(Object object) { return ((Boolean) object).booleanValue() ? "1" : "0"; } } {code} --------------------------------------------------------------------- CONFLUENCE INFORMATION This message is automatically generated by Confluence Unsubscribe or edit your notifications preferences http://cwiki.apache.org/confluence/users/viewnotifications.action If you think it was sent incorrectly contact one of the administrators http://cwiki.apache.org/confluence/administrators.action If you want more information on Confluence, or have a bug to report see http://www.atlassian.com/software/confluence