RegionsType.java :  » ERP-CRM-Financial » OpenXava-3.0 » org » openxava » test » types » Java Open Source

Java Open Source » ERP CRM Financial » OpenXava 3.0 
OpenXava 3.0 » org » openxava » test » types » RegionsType.java
package org.openxava.test.types;

import java.io.*;
import java.sql.*;

import org.apache.commons.logging.*;
import org.hibernate.*;
import org.hibernate.usertype.*;
import org.openxava.util.*;

/** 
 * 
 * @author Javier Paniza
 */

public class RegionsType implements UserType {

  public int[] sqlTypes() {    
    return new int[] { Types.VARCHAR };
  }

  public Class returnedClass() {
    return String[].class;
  }

  public boolean equals(Object obj1, Object obj2) throws HibernateException {
    return Is.equal(obj1, obj2);
  }

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

  public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
    Object o = resultSet.getObject(names[0]);
       if (o == null) return new String[0];
       String dbValue = (String) o; 
       String [] javaValue = new String [dbValue.length()];
       for (int i = 0; i < javaValue.length; i++) {
         javaValue[i] = String.valueOf(dbValue.charAt(i));      
       }
       return javaValue;
  }

  public void nullSafeSet(PreparedStatement ps, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
      ps.setString(index, "");
      return;
    }
    String [] javaValue = (String []) value;
    StringBuffer dbValue = new StringBuffer();
    for (int i = 0; i < javaValue.length; i++) {
      dbValue.append(javaValue[i]);
    }
    ps.setString(index, dbValue.toString());    
  }

  public Object deepCopy(Object obj) throws HibernateException {    
    return obj == null?null:((String []) obj).clone();
  }

  public boolean isMutable() {
    return true;
  }

  public Serializable disassemble(Object obj) throws HibernateException {
    return (Serializable) obj;
  }

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

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

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.