/*
Name: 
    - TimePointToDateMapping 

Description: 
    -  

Requires:
    - 
    
Provides:
    - 

Part of: ProcessPuzzle Framework, Domain and Business Model Ready Architecture. Provides content, workflow and social networking functionality. 
http://www.processpuzzle.com

ProcessPuzzle - Content and Workflow Management Integration Business Platform

Author(s): 
    - Zsolt Zsuffa

Copyright: (C) 2011 This program is free software: you can redistribute it and/or modify it under the terms of the 
GNU General Public License as published by the Free Software Foundation, either version 3 of the License, 
or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.processpuzzle.persistence.typemapping.domain;

import java.io.Serializable;
import java.util.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.Type;
import org.hibernate.usertype.CompositeUserType;

import com.processpuzzle.fundamental_types.domain.TimePoint;

public class TimePointToDateMapping implements CompositeUserType {
   public static final int[] TYPES     = { Types.DATE };

   public Class<TimePoint> returnedClass() {
      return TimePoint.class;
   }

   public boolean equals( Object x, Object y ) throws HibernateException {
      if( x == y )
         return true;
      if( x == null || y == null )
         return false;
      return x.equals( y );
   }

   public Object deepCopy( Object x ) throws HibernateException {
      if( x == null )
         return null;
      TimePoint input = (TimePoint) x;
      TimePoint result = input;
      return result;
   }

   public boolean isMutable() {
      return false;
   }

   public Object nullSafeGet( ResultSet resultSet, String[] names, SessionImplementor session, Object owner ) throws HibernateException, SQLException {
      java.util.Date savedDate = (Date) Hibernate.DATE.nullSafeGet( resultSet, names[0] );
      return new TimePoint( savedDate );
   }

   public void nullSafeSet( PreparedStatement statement, Object objectToSave, int index, SessionImplementor session ) throws HibernateException, SQLException {
      if( objectToSave == null ){
         statement.setNull( index + 1, Types.DATE );
      }else{
         Hibernate.DATE.nullSafeSet( statement, ((TimePoint) objectToSave).getValue(), index );
      }
   }

   public String[] getPropertyNames() {
      return new String[] { "date" };
   }

   public Type[] getPropertyTypes() {
      return new Type[] { Hibernate.DATE };
   }

   public Object getPropertyValue( Object component, int property ) throws HibernateException {
      TimePoint timePoint = (TimePoint) component;
      if( timePoint.getValue() != null )
         return timePoint.getValue();
      else
         return null;
   }

   public Object assemble( Serializable cached, SessionImplementor session, Object owner ) throws HibernateException {
      return deepCopy( cached );
   }

   public Serializable disassemble( Object value, SessionImplementor session ) throws HibernateException {
      return (Serializable) deepCopy( value );
   }

   public int hashCode( Object arg0 ) throws HibernateException {
      return arg0.hashCode();
   }

   public Object replace( Object original, Object target, SessionImplementor session, Object owner ) throws HibernateException {
      return null;
   }

   public void setPropertyValue( Object component, int property, Object value ) throws HibernateException {
      throw new UnsupportedOperationException( "TimePoint is immutable!" );
   }
}

@@ -1113,31 +1113,8 @@
 le;%0A
-import java.util.Date;%0A
 impo
@@ -1228,41 +1228,32 @@
 es;%0A
-%0A
 import 
-org.hibernate.Hibern
+java.util.D
 ate;%0A
+%0A
 impo
@@ -1337,16 +1337,62 @@
 mentor;%0A
+import org.hibernate.type.StandardBasicTypes;%0A
 import o
@@ -2399,25 +2399,34 @@
  (Date) 
-Hibernate
+StandardBasicTypes
 .DATE.nu
@@ -2775,25 +2775,34 @@
         
-Hibernate
+StandardBasicTypes
 .DATE.nu
@@ -3033,25 +3033,34 @@
 ype%5B%5D %7B 
-Hibernate
+StandardBasicTypes
 .DATE %7D;

Eliminate the depricated use of HIBERNATE.