Hi Ad,
for that purpose you can now simple call a method on o.e.c.jdo.Database.
/**
* Returns the object's identity. The identity will be determined by
* calling the getters of the fields defined as identities in the
* mapping. If a mapping for the objects class could not be found a
* ClassNotPersistenceCapableException will be thrown. Null is only
* returned if the objects identity is null. It is not required to
* have an active transaction when using this method.
* <p>
* <b>Note:</b> Prior to 0.9.9.1 release of castor the identity
* could only be determined if the object took part in the
* transaction. If this was not the case, the previous
* implementation also returned null.
*
* @param object The object.
* @return The object's identity, or null.
* @throws PersistenceException The class is not persistent capable.
*/
public Identity getIdentity(Object object)
throws PersistenceException;
Regards
Ralf
[EMAIL PROTECTED] schrieb:
> Hi Werner,
>
> I just talked to my old colleague Henk van Voorthuijsen en he told me that
> he made this piece of code together with you for a workaround for the
> getIdentity
>
> public Object getIdentity(final Object data) throws MappingException
> {
>
> AbstractConnectionFactory cf =
> DatabaseRegistry.getConnectionFactory(getDatabase().getDatabaseName());
> MappingResolver mappRes = cf.getMapping().getResolver(Mapping.JDO);
>
> ClassDescriptor clsDesc = mappRes.getDescriptor(data.getClass());
> FieldDescriptor[] identities = ((ClassDescriptorImpl)
> clsDesc).getIdentities();
> if ((identities != null) && (identities.length > 0))
> {
> Object[] values = new Object[identities.length];
> for (int i = 0; i < identities.length; i++)
> {
> values[i] = identities[i].getHandler().getValue(data);
> if (values[i] instanceof BigDecimal)
> {
> if (identities[i].getFieldType() == Integer.class)
> {
> values[i] = new Integer(((BigDecimal)
> values[i]).intValue());
> }
> if (identities[i].getFieldType() == Long.class)
> {
> values[i] = new Long(((BigDecimal)
> values[i]).longValue());
> }
> }
> }
> return (identities.length == 1
> ? values[0]
> : new Complex(values));
> }
> return null;
> }
> Met vriendelijke groet/with kind regards,
>
>
> Ad Kerremans
> Technical Consultant
>
> Serac Applications BV
> Postbus 83
> 3454 ZH De Meern
>
> BEZOEKADRES;
> Rijnzathe 36
> 3454 PV De Meern
>
> Direct: +31 (0)30 658 33 35
> Algemeen: +31 (0)30 - 658 33 33
> Fax: +31 (0)30 - 658 33 66
> Helpdesk: +31 (0)30 - 658 33 99
>
> Website: http://www.serac.nl
>
>
>
>
>
>
> [EMAIL PROTECTED]
>
> c.nl To:
> [email protected]
>
> cc:
>
> 15-11-2006 13:39 Subject: RE: [castor-user]
> problems upgrading to castor 1.0.5 from 1.0
> Please respond to
>
> user
>
>
>
>
>
>
>
>
> Hi Werner,
>
>
> I don't know why these classes are used this is an old piece of code. The
> person that did write this code is no longer working here.
>
> Met vriendelijke groet/with kind regards,
>
>
> Ad Kerremans
>
>
>
>
>
> "Werner Guttmann"
>
> <[EMAIL PROTECTED] To:
> <[email protected]>
>
> com> cc:
>
> Subject: RE: [castor-user]
> problems upgrading to castor 1.0.5 from 1.0
> 15-11-2006 13:21
>
> Please respond to
>
> user
>
>
>
>
>
>
> As far as I know, some of these classes have been refactroed recently.
> But let's wait to see what Ralf has got to sa. Having said that, I'd be
> interested to learn what you are trying to achieve by using that code.
> In other words, I would not expect that a user of Castor JDO would try
> to use these classes.
>
> Werner
>
>
>>-----Original Message-----
>>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>>Sent: Mittwoch, 15. November 2006 13:14
>>To: [email protected]
>>Subject: [castor-user] problems upgrading to castor 1.0.5 from 1.0
>>
>>Hi,
>>
>>I replaced the Castor 1.0 jar with the 1.0.5 jar.
>>My project is complaining that the classess MappingResolver
>>and Mapping.JDO cannot be resolved
>>
>>my imports are:
>>
>>import org.castor.jdo.engine.AbstractConnectionFactory;
>>import org.castor.jdo.engine.DatabaseRegistry;
>>import org.exolab.castor.jdo.*;
>>import org.exolab.castor.mapping.*;
>>import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
>>import org.exolab.castor.persist.spi.Complex;
>>
>>Piece of my code:
>>
>>AbstractConnectionFactory cf =
>>DatabaseRegistry.getConnectionFactory(getDatabase().getDatabas
>>eName());
>>MappingResolver mappRes = cf.getMapping().getResolver(Mapping.JDO);
>>
>>
>>Met vriendelijke groet/with kind regards,
>>
>>
>>Ad Kerremans
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe from this list please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
--
Syscon Ingenieurbüro für
Meß- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstraße 11
D-72127 Kusterdingen
Germany
Tel. +49 7071 3690 52
Mobil: +49 173 9630135
Fax +49 7071 3690 98
Email: [EMAIL PROTECTED]
Web: www.syscon-informatics.de
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email