-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate with different Domain Model
PostPosted: Fri Feb 03, 2006 1:52 pm 
Newbie

Joined: Fri Feb 03, 2006 1:35 pm
Posts: 1
Location: Brazil / SC / Joinville
Hi,

In Progress we have boolean in Oracle integer.
In Progress we have integer in Oracle big_decimal.

How the default here is progress. I'm trying to do
a UserType to do this convertions at runtime.

BigDecimal to Integer ( Loading )
Integer to BigDecimal ( Saving )

Code:
public class NumericUserType implements UserType {
   
   private static final int[] SQL_TYPE = { Types.NUMERIC };
   
   /**
    * {@link UserType#sqlTypes()}
    */
   public int[] sqlTypes() {
      return SQL_TYPE;
   }

   /**
    * {@link UserType#returnedClass()}
    */
   public Class returnedClass() {
      return DispositControlAces.class;
   }

   /**
    * {@link UserType#equals(Object, Object)}
    */
   public boolean equals(Object obj0, Object obj1) throws HibernateException {
      return EqualsBuilder.reflectionEquals(obj0, obj1);
   }

   /**
    * {@link UserType#hashCode(Object)}
    */
   public int hashCode(Object obj0) throws HibernateException {
      return HashCodeBuilder.reflectionHashCode(obj0);
   }

   /**
    * {@link UserType#nullSafeGet(ResultSet, String[], Object)}
    */
   public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
      
      Integer integer = resultSet.getBigDecimal(names[0]).intValue();
      
      return integer;
      
   }

   /**
    * {@link UserType#nullSafeSet(PreparedStatement, Object, int)}
    */
   public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
      if (value == null) {
            preparedStatement.setNull( index, Types.NUMERIC );
        } else {
            preparedStatement.setBigDecimal(index, new BigDecimal( ((Integer)value).intValue() ) );
        }
   }

   /**
    * {@link UserType#deepCopy(Object)}
    */
   public Object deepCopy(Object obj0) throws HibernateException {
      return obj0;
   }

   /**
    * {@link UserType#isMutable()}
    */
   public boolean isMutable() {
      return false;
   }

   /**
    * {@link UserType#disassemble(Object)}
    */
   public Serializable disassemble(Object arg0) throws HibernateException {
      return (Serializable) this.deepCopy( arg0 );
   }

   /**
    * {@link UserType#assemble(Serializable, Object)}
    */
   public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
      return this.deepCopy(arg0);
   }

   /**
    * {@link UserType#replace(Object, Object, Object)}
    */
   public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
      return this.deepCopy(arg0);
   }
   
}


This class is ok?
Thanks.

_________________
Good programmers write code that humans can understand. - Martin Fowler


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

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.