-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: CompositeUserType with specified column length?
PostPosted: Sun Jul 26, 2009 11:52 am 
Newbie

Joined: Sun Jul 26, 2009 11:47 am
Posts: 3
Hi,

quick question: I want to set a specific length on my CompositeUserType, how do I do that?

Background info: My CompositeUserType consists of 4 columns (sort of an EAV) - where one is a text column. By default it gets set to a length of 255 - but I need 510.
Any advice?

Cheers,
Stephan


Top
 Profile  
 
 Post subject: Re: CompositeUserType with specified column length?
PostPosted: Wed Aug 12, 2009 7:17 am 
Newbie

Joined: Sun Jul 26, 2009 11:47 am
Posts: 3
I really can't figure it out, anyone to help?

Bottom line: How to make CompositeUserType with String DB Column 510 chars long (when generating with DDL)?


Top
 Profile  
 
 Post subject: Re: CompositeUserType with specified column length?
PostPosted: Wed Aug 12, 2009 7:18 am 
Newbie

Joined: Sun Jul 26, 2009 11:47 am
Posts: 3
By the way, here is the code for the CompositeUserType (I found it in some discussion board where Christian posted about EAV):

Code:
public class AttributeValueHibernate
        implements CompositeUserType {

    @Override
    public Class returnedClass () {

        return Object.class;
    }

    @Override
    public String[] getPropertyNames () {

        return new String[] {
                MetaAttributeType.LONG.name (),
                MetaAttributeType.DOUBLE.name (),
                MetaAttributeType.DATETIME.name (),
                MetaAttributeType.STRING.name ()
        };
    }

    @Override
    public Type[] getPropertyTypes () {

        return new Type[] {
                Hibernate.LONG,
                Hibernate.DOUBLE,
                Hibernate.TIMESTAMP,
                Hibernate.STRING
        };
    }

    @Override
    public Object getPropertyValue (final Object pComponent,
                                    final int pRoperty) throws HibernateException {

        switch (pRoperty) {
            case 0:
                return pComponent instanceof Long ? pComponent : null;
            case 1:
                return pComponent instanceof Double ? pComponent : null;
            case 2:
                return pComponent instanceof Date ? pComponent : null;
            case 3:
                return pComponent instanceof String ? pComponent : null;
        }

        throw new IllegalArgumentException ("Meta model doesn't support object of type: " + pComponent.getClass ());
    }

    @Override
    public void setPropertyValue (final Object pComponent,
                                  final int pRoperty,
                                  final Object pValue) throws HibernateException {

        throw new UnsupportedOperationException ();
    }

    @Override
    public Object nullSafeGet (final ResultSet pResultSet,
                               final String[] pNames,
                               final SessionImplementor pSession,
                               final Object pOwner)
            throws HibernateException, SQLException {

        Long intValue = (Long) Hibernate.LONG.nullSafeGet (pResultSet, pNames[0], pSession, pOwner);
        if (intValue != null) {
            return intValue;
        }

        Double doubleValue = (Double) Hibernate.DOUBLE.nullSafeGet (pResultSet, pNames[1], pSession, pOwner);
        if (doubleValue != null) {
            return doubleValue;
        }

        Date datetimeValue = (Date) Hibernate.TIMESTAMP.nullSafeGet (pResultSet, pNames[2], pSession, pOwner);
        if (datetimeValue != null) {
            return datetimeValue;
        }

        return (String) Hibernate.STRING.nullSafeGet (pResultSet, pNames[3], pSession, pOwner);
    }

    @Override
    public void nullSafeSet (final PreparedStatement pStatement,
                             final Object pValue,
                             final int pIndex,
                             final SessionImplementor pSession)
            throws HibernateException, SQLException {

        Hibernate.LONG.nullSafeSet (pStatement,
                                    pValue instanceof Long ? pValue : null, pIndex);

        Hibernate.DOUBLE.nullSafeSet (pStatement,
                                      pValue instanceof Double ? pValue : null, pIndex + 1);

        Hibernate.TIMESTAMP.nullSafeSet (pStatement,
                                         pValue instanceof Date ? pValue : null, pIndex + 2);

        Hibernate.STRING.nullSafeSet (pStatement,
                                      pValue instanceof String ? pValue : null, pIndex + 3);
    }

    @Override
    public boolean isMutable () {

        return false;
    }

    @Override
    public boolean equals (final Object pX,
                           final Object pY) throws HibernateException {

        if (pX == null) {
            return pY == null;
        } else {
            return pX.equals (pY);
        }
    }

    @Override
    public int hashCode (final Object pObject) throws HibernateException {

        return pObject.hashCode ();
    }

    @Override
    public Object replace (final Object pOriginal,
                           final Object pTarget,
                           final SessionImplementor pSession,
                           final Object pOwner) {

        return pOriginal;
    }

    @Override
    public Object deepCopy (final Object pValue) throws HibernateException {

        return pValue;
    }

    @Override
    public Serializable disassemble (final Object pValue,
                                     final SessionImplementor pSession) throws HibernateException {

        return (Serializable) pValue;
    }

    @Override
    public Object assemble (final Serializable pCached,
                            final SessionImplementor pSession,
                            final Object pOwner) throws HibernateException {

        return pCached;
    }

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.