r4114 - branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate
Author: echatellier Date: 2014-09-26 15:46:18 +0200 (Fri, 26 Sep 2014) New Revision: 4114 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4114 Log: Replace ImmutableType by non deprecated UserType Modified: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/MatrixType.java branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/MonthType.java branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/RangeOfValuesType.java branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/TimeStepType.java branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/TimeUnitType.java Modified: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/MatrixType.java =================================================================== --- branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/MatrixType.java 2014-09-26 13:45:20 UTC (rev 4113) +++ branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/MatrixType.java 2014-09-26 13:46:18 UTC (rev 4114) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2002 - 2010 Ifremer, Code Lutin + * Copyright (C) 2002 - 2014 Ifremer, Code Lutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -320,10 +320,12 @@ return cub; } + @Override public Class returnedClass() { return MatrixND.class; } + @Override public boolean equals(Object x, Object y) throws HibernateException { if (x == y) { return true; @@ -334,10 +336,12 @@ } } + @Override public int hashCode(Object x) throws HibernateException { return x.hashCode(); } + @Override public Object deepCopy(Object value) throws HibernateException { if (value == null) { return null; @@ -345,14 +349,17 @@ return MatrixFactory.getInstance().create((MatrixND)value); } + @Override public String[] getPropertyNames() { return propertyNames; } + @Override public Type[] getPropertyTypes() { return hibernateTypes; } + @Override public Object getPropertyValue(Object component, int property) throws HibernateException { MatrixND matrix = (MatrixND)component; switch (property) { @@ -365,6 +372,7 @@ } } + @Override public void setPropertyValue(Object component, int property, Object value) throws HibernateException { MatrixND matrix = (MatrixND)component; switch (property) { @@ -383,6 +391,7 @@ } } + @Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { MatrixND matrix = null; @@ -413,6 +422,7 @@ return matrix; } + @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { if (value == null) { st.setString(index, null); @@ -431,6 +441,7 @@ } } + @Override public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException { MatrixND matrix = (MatrixND)value; return new Serializable[] { @@ -442,6 +453,7 @@ }; } + @Override public Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException { Serializable[] o = (Serializable[])cached; String name = (String)o[0]; @@ -458,6 +470,7 @@ return matrix; } + @Override public Object replace(Object original, Object target, SessionImplementor session, Object owner) throws HibernateException { return assemble( disassemble(original, session), session, owner); } Modified: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/MonthType.java =================================================================== --- branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/MonthType.java 2014-09-26 13:45:20 UTC (rev 4113) +++ branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/MonthType.java 2014-09-26 13:46:18 UTC (rev 4114) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2002 - 2010 Ifremer, Code Lutin + * Copyright (C) 2002 - 2014 Ifremer, Code Lutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,13 +25,15 @@ package fr.ifremer.isisfish.types.hibernate; +import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import org.hibernate.HibernateException; -import org.hibernate.type.ImmutableType; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.usertype.UserType; import fr.ifremer.isisfish.types.Month; @@ -46,65 +48,74 @@ * Mise a jour: $Date$ * par : $Author$ */ -public class MonthType extends ImmutableType { +public class MonthType implements UserType { - /** serialVersionUID. */ - private static final long serialVersionUID = 6151047526309798890L; + @Override + public int[] sqlTypes() { + return new int[] {Types.INTEGER}; + } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#get(java.sql.ResultSet, java.lang.String) - */ @Override - public Object get(ResultSet rs, String name) throws HibernateException, - SQLException { - return Month.MONTH[rs.getInt(name)]; + public Class returnedClass() { + return Month.class; } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#set(java.sql.PreparedStatement, java.lang.Object, int) - */ @Override - public void set(PreparedStatement st, Object value, int index) - throws HibernateException, SQLException { - st.setInt(index, ((Month) value).getMonthNumber()); + public boolean equals(Object x, Object y) throws HibernateException { + if (x == y) { + return true; + } + if (null == x || null == y) { + return false; + } + return x.equals(y); } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#sqlType() - */ @Override - public int sqlType() { - return Types.INTEGER; + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#toString(java.lang.Object) - */ @Override - public String toString(Object value) throws HibernateException { - return ((Month)value).toString(); + public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { + Object result = null; + if (!rs.wasNull()) { + result = Month.MONTH[rs.getInt(names[0])]; + } + return result; } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#fromStringValue(java.lang.String) - */ @Override - public Object fromStringValue(String xml) throws HibernateException { - return Month.MONTH[Integer.parseInt(xml)]; + public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + if (value == null) { + st.setNull(index, sqlTypes()[0]); + } else { + st.setInt(index, ((Month) value).getMonthNumber()); + } } - /* (non-Javadoc) - * @see org.hibernate.type.Type#getReturnedClass() - */ - public Class getReturnedClass() { - return Month.class; + @Override + public Object deepCopy(Object value) throws HibernateException { + return value; } - /* (non-Javadoc) - * @see org.hibernate.type.Type#getName() - */ - public String getName() { - return MonthType.class.getName(); + @Override + public boolean isMutable() { + return false; } + @Override + public Serializable disassemble(Object value) throws HibernateException { + return (Month)value; + } + + @Override + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } + + @Override + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } } Modified: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/RangeOfValuesType.java =================================================================== --- branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/RangeOfValuesType.java 2014-09-26 13:45:20 UTC (rev 4113) +++ branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/RangeOfValuesType.java 2014-09-26 13:46:18 UTC (rev 4114) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2002 - 2010 Ifremer, Code Lutin + * Copyright (C) 2002 - 2014 Ifremer, Code Lutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,13 +25,15 @@ package fr.ifremer.isisfish.types.hibernate; +import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import org.hibernate.HibernateException; -import org.hibernate.type.ImmutableType; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.usertype.UserType; import fr.ifremer.isisfish.types.RangeOfValues; @@ -46,65 +48,74 @@ * Mise a jour: $Date$ * par : $Author$ */ -public class RangeOfValuesType extends ImmutableType { +public class RangeOfValuesType implements UserType { - /** serialVersionUID. */ - private static final long serialVersionUID = -5295147041590169149L; + @Override + public int[] sqlTypes() { + return new int[] {Types.VARCHAR}; + } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#get(java.sql.ResultSet, java.lang.String) - */ @Override - public Object get(ResultSet rs, String name) throws HibernateException, - SQLException { - return new RangeOfValues(rs.getString(name)); + public Class returnedClass() { + return RangeOfValues.class; } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#set(java.sql.PreparedStatement, java.lang.Object, int) - */ @Override - public void set(PreparedStatement st, Object value, int index) - throws HibernateException, SQLException { - st.setString(index, ((RangeOfValues) value).getAsString()); + public boolean equals(Object x, Object y) throws HibernateException { + if (x == y) { + return true; + } + if (null == x || null == y) { + return false; + } + return x.equals(y); } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#sqlType() - */ @Override - public int sqlType() { - return Types.VARCHAR; + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#toString(java.lang.Object) - */ @Override - public String toString(Object value) throws HibernateException { - return ((RangeOfValues)value).getAsString(); + public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { + Object result = null; + if (!rs.wasNull()) { + result = new RangeOfValues(rs.getString(names[0])); + } + return result; } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#fromStringValue(java.lang.String) - */ @Override - public Object fromStringValue(String xml) throws HibernateException { - return new RangeOfValues(xml); + public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + if (value == null) { + st.setNull(index, sqlTypes()[0]); + } else { + st.setString(index, ((RangeOfValues) value).getAsString()); + } } - /* (non-Javadoc) - * @see org.hibernate.type.Type#getReturnedClass() - */ - public Class getReturnedClass() { - return RangeOfValues.class; + @Override + public Object deepCopy(Object value) throws HibernateException { + return value; } - /* (non-Javadoc) - * @see org.hibernate.type.Type#getName() - */ - public String getName() { - return RangeOfValuesType.class.getName(); + @Override + public boolean isMutable() { + return false; } + @Override + public Serializable disassemble(Object value) throws HibernateException { + return (RangeOfValues)value; + } + + @Override + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } + + @Override + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } } Modified: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/TimeStepType.java =================================================================== --- branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/TimeStepType.java 2014-09-26 13:45:20 UTC (rev 4113) +++ branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/TimeStepType.java 2014-09-26 13:46:18 UTC (rev 4114) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2002 - 2011 Ifremer, Code Lutin, Chatellier Eric + * Copyright (C) 2002 - 2014 Ifremer, Code Lutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,13 +25,15 @@ package fr.ifremer.isisfish.types.hibernate; +import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import org.hibernate.HibernateException; -import org.hibernate.type.ImmutableType; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.usertype.UserType; import fr.ifremer.isisfish.types.TimeStep; @@ -46,65 +48,74 @@ * Mise a jour: $Date$ * par : $Author$ */ -public class TimeStepType extends ImmutableType { +public class TimeStepType implements UserType { - /** serialVersionUID. */ - private static final long serialVersionUID = -5295147041590169149L; + @Override + public int[] sqlTypes() { + return new int[] {Types.INTEGER}; + } - /* - * @see org.hibernate.type.NullableType#get(java.sql.ResultSet, java.lang.String) - */ @Override - public Object get(ResultSet rs, String name) throws HibernateException, - SQLException { - return new TimeStep(rs.getInt(name)); + public Class returnedClass() { + return TimeStep.class; } - /* - * @see org.hibernate.type.NullableType#set(java.sql.PreparedStatement, java.lang.Object, int) - */ @Override - public void set(PreparedStatement st, Object value, int index) - throws HibernateException, SQLException { - st.setInt(index, ((TimeStep) value).getStep()); + public boolean equals(Object x, Object y) throws HibernateException { + if (x == y) { + return true; + } + if (null == x || null == y) { + return false; + } + return x.equals(y); } - /* - * @see org.hibernate.type.NullableType#sqlType() - */ @Override - public int sqlType() { - return Types.INTEGER; + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); } - /* - * @see org.hibernate.type.NullableType#toString(java.lang.Object) - */ @Override - public String toString(Object value) throws HibernateException { - return ((TimeStep)value).toString(); + public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { + Object result = null; + if (!rs.wasNull()) { + result = new TimeStep(rs.getInt(names[0])); + } + return result; } - /* - * @see org.hibernate.type.NullableType#fromStringValue(java.lang.String) - */ @Override - public Object fromStringValue(String xml) throws HibernateException { - return new TimeStep(Integer.parseInt(xml)); + public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + if (value == null) { + st.setNull(index, sqlTypes()[0]); + } else { + st.setInt(index, ((TimeStep) value).getStep()); + } } - /* - * @see org.hibernate.type.Type#getReturnedClass() - */ - public Class getReturnedClass() { - return TimeStep.class; + @Override + public Object deepCopy(Object value) throws HibernateException { + return value; } - /* - * @see org.hibernate.type.Type#getName() - */ - public String getName() { - return TimeStepType.class.getName(); + @Override + public boolean isMutable() { + return false; } + @Override + public Serializable disassemble(Object value) throws HibernateException { + return (TimeStep)value; + } + + @Override + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } + + @Override + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } } Modified: branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/TimeUnitType.java =================================================================== --- branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/TimeUnitType.java 2014-09-26 13:45:20 UTC (rev 4113) +++ branches/4.3.0-log4j2/src/main/java/fr/ifremer/isisfish/types/hibernate/TimeUnitType.java 2014-09-26 13:46:18 UTC (rev 4114) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2002 - 2010 Ifremer, Code Lutin + * Copyright (C) 2002 - 2014 Ifremer, Code Lutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,13 +25,15 @@ package fr.ifremer.isisfish.types.hibernate; +import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import org.hibernate.HibernateException; -import org.hibernate.type.ImmutableType; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.usertype.UserType; import fr.ifremer.isisfish.types.TimeUnit; @@ -46,65 +48,74 @@ * Mise a jour: $Date$ * par : $Author$ */ -public class TimeUnitType extends ImmutableType { +public class TimeUnitType implements UserType { - /** serialVersionUID. */ - private static final long serialVersionUID = -5295147041590169149L; + @Override + public int[] sqlTypes() { + return new int[] {Types.DOUBLE}; + } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#get(java.sql.ResultSet, java.lang.String) - */ @Override - public Object get(ResultSet rs, String name) throws HibernateException, - SQLException { - return new TimeUnit(rs.getDouble(name)); + public Class returnedClass() { + return TimeUnit.class; } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#set(java.sql.PreparedStatement, java.lang.Object, int) - */ @Override - public void set(PreparedStatement st, Object value, int index) - throws HibernateException, SQLException { - st.setDouble(index, ((TimeUnit) value).getTime()); + public boolean equals(Object x, Object y) throws HibernateException { + if (x == y) { + return true; + } + if (null == x || null == y) { + return false; + } + return x.equals(y); } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#sqlType() - */ @Override - public int sqlType() { - return Types.DOUBLE; + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#toString(java.lang.Object) - */ @Override - public String toString(Object value) throws HibernateException { - return ((TimeUnit)value).toString(); + public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { + Object result = null; + if (!rs.wasNull()) { + result = new TimeUnit(rs.getDouble(names[0])); + } + return result; } - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#fromStringValue(java.lang.String) - */ @Override - public Object fromStringValue(String xml) throws HibernateException { - return new TimeUnit(Double.parseDouble(xml)); + public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + if (value == null) { + st.setNull(index, sqlTypes()[0]); + } else { + st.setDouble(index, ((TimeUnit) value).getTime()); + } } - /* (non-Javadoc) - * @see org.hibernate.type.Type#getReturnedClass() - */ - public Class getReturnedClass() { - return TimeUnit.class; + @Override + public Object deepCopy(Object value) throws HibernateException { + return value; } - /* (non-Javadoc) - * @see org.hibernate.type.Type#getName() - */ - public String getName() { - return TimeUnitType.class.getName(); + @Override + public boolean isMutable() { + return false; } + @Override + public Serializable disassemble(Object value) throws HibernateException { + return (TimeUnit)value; + } + + @Override + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } + + @Override + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } }
participants (1)
-
echatellier@users.forge.codelutin.com