Author: tchemit Date: 2008-07-28 20:49:19 +0000 (Mon, 28 Jul 2008) New Revision: 1266 Added: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/types/ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/DateConverter.java branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/MonthConverter.java branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/StringConverter.java branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TimeUnitConverter.java branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java Removed: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/DateType.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/MatrixType.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/MonthType.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/RangeOfValuesType.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/TimeUnitType.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/ConverterUtil.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/DateConverter.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/MonthConverter.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/StringConverter.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TimeUnitConverter.java branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java Log: entities dependancies Copied: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/types (from rev 1254, branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types) Copied: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java (from rev 1254, branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/ConverterUtil.java) =================================================================== --- branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java (rev 0) +++ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -0,0 +1,72 @@ +/* *##% + * Copyright (C) 2006 + * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * ConverterUtil.java + * + * Created: 25 sept. 06 19:37:16 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package fr.ifremer.isisfish.util; + +import org.apache.commons.beanutils.BeanUtilsBean; +import org.apache.commons.beanutils.ConvertUtilsBean; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.persistence.TopiaEntity; + +import fr.ifremer.isisfish.types.Date; +import fr.ifremer.isisfish.types.Month; +import fr.ifremer.isisfish.types.RangeOfValues; +import fr.ifremer.isisfish.types.TimeUnit; + + +/** + * @author poussin + * + */ + +public class ConverterUtil { + + static public ConvertUtilsBean getConverter(TopiaContext context) { + BeanUtilsBean result = BeanUtilsBean.getInstance(); + ConvertUtilsBean cub = result.getConvertUtils(); + + cub.register(new TopiaEntityConverter(context), TopiaEntity.class); + + // FIXME see if register done in IsisFish.init() method permit to remove next line + // mise en place de converter de string vers des objet ... + cub.register(new DateConverter(), Date.class); + cub.register(new MonthConverter(), Month.class); + cub.register(new TimeUnitConverter(), TimeUnit.class); + cub.register(new RangeOfValuesConverter(), RangeOfValues.class); + // ... et inversement + cub.register(new StringConverter(), String.class); + + return cub; + } + +} + + Property changes on: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/DateConverter.java (from rev 1254, branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/DateConverter.java) =================================================================== --- branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/DateConverter.java (rev 0) +++ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/DateConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -0,0 +1,68 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * DateConverter.java + * + * Created: 13 janv. 2006 01:13:41 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package fr.ifremer.isisfish.util; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.beanutils.Converter; + +import fr.ifremer.isisfish.types.Date; + + +/** + * Classe utilise pour convertir une chaine en un objet Date. + * Utilisé pour la conversion et le stockage en propriete des parametres + * @author poussin + * + */ +public class DateConverter implements Converter { + + /* (non-Javadoc) + * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) + */ + public Object convert(Class type, Object value) { + Object result; + if (value instanceof Date) { + result = value; + } else if (value instanceof String) { + int d = Integer.parseInt(value.toString()); + result = new Date(d); + } else if (value == null) { + result = new Date(0); + } else { + throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); + } + return result; + } + +} + + Property changes on: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/DateConverter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/MonthConverter.java (from rev 1254, branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/MonthConverter.java) =================================================================== --- branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/MonthConverter.java (rev 0) +++ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/MonthConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -0,0 +1,70 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * MonthConverter.java + * + * Created: 12 janv. 2006 20:23:35 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package fr.ifremer.isisfish.util; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.beanutils.Converter; + +import fr.ifremer.isisfish.types.Month; + + +/** + * Classe utilise pour convertir une chaine en un objet Month. + * Utilisé pour la conversion et le stockage en propriete des parametres + * @author poussin + * + */ + +public class MonthConverter implements Converter { + + /* (non-Javadoc) + * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) + */ + public Object convert(Class type, Object value) { + Object result = null; + if (value instanceof Month) { + result = value; + } else if (value instanceof String) { + int m = Integer.parseInt(value.toString()); + result = Month.MONTH[m]; + } else if (value instanceof Integer) { + int m = ((Integer)value).intValue(); + result = Month.MONTH[m]; + } else { + throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); + } + return result; + } + +} + + Property changes on: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/MonthConverter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java (from rev 1254, branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java) =================================================================== --- branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java (rev 0) +++ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -0,0 +1,65 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * DateConverter.java + * + * Created: 13 janv. 2006 01:13:41 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package fr.ifremer.isisfish.util; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.beanutils.Converter; + +import fr.ifremer.isisfish.types.RangeOfValues; + + +/** + * Classe utilise pour convertir une chaine en un objet RangeOfValues. + * Utilisé pour la conversion et le stockage en propriete des parametres + * @author poussin + * + */ +public class RangeOfValuesConverter implements Converter { + + /* (non-Javadoc) + * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) + */ + public Object convert(Class type, Object value) { + Object result; + if (value instanceof RangeOfValues) { + result = value; + } else if (value instanceof String) { + result = new RangeOfValues(value.toString()); + } else { + throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); + } + return result; + } + +} + + Property changes on: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/StringConverter.java (from rev 1254, branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/StringConverter.java) =================================================================== --- branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/StringConverter.java (rev 0) +++ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/StringConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -0,0 +1,77 @@ +/* + * *##% Copyright (C) 2006 Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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 2 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, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. ##% + */ + +/******************************************************************************* + * StringConverter.java + * + * Created: 12 janv. 2006 20:38:26 + * + * @author poussin + * + * @version $Revision$ + * + * Last update: $Date$ by : $Author$ + */ + +package fr.ifremer.isisfish.util; + +import org.apache.commons.beanutils.Converter; +import org.codelutin.topia.persistence.TopiaEntity; + +import fr.ifremer.isisfish.types.Date; +import fr.ifremer.isisfish.types.Month; +import fr.ifremer.isisfish.types.TimeUnit; + +/** + * Classe utilise pour convertir en chaine un objet Date, Month ou TopiaEntity + * Utilisé pour la conversion et le stockage en propriete des parametres + * @author poussin + * + */ +public class StringConverter implements Converter { + + private Converter defaultStringConverter = + new org.apache.commons.beanutils.converters.StringConverter(); + + + /* + * (non-Javadoc) + * + * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, + * java.lang.Object) + */ + public Object convert(Class type, Object o) { + Object result = null; + if (o != null) { + if (o instanceof TopiaEntity) { + result = ((TopiaEntity) o).getTopiaId(); + } else if (o instanceof Date) { + result = String.valueOf(((Date) o).getDate()); + } else if (o instanceof Month) { + result = String.valueOf(((Month) o).getMonthNumber()); + } else if (o instanceof TimeUnit) { + result = String.valueOf(((TimeUnit) o).getTime()); + } else { + // dans tous les autres cas, on appelle le converter par defaut + result = defaultStringConverter.convert(type, o); + } + } + return result; + } + +} Property changes on: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/StringConverter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TimeUnitConverter.java (from rev 1254, branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TimeUnitConverter.java) =================================================================== --- branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TimeUnitConverter.java (rev 0) +++ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TimeUnitConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -0,0 +1,68 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * DateConverter.java + * + * Created: 13 janv. 2006 01:13:41 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package fr.ifremer.isisfish.util; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.beanutils.Converter; + +import fr.ifremer.isisfish.types.TimeUnit; + + +/** + * Classe utilise pour convertir une chaine en un objet TimeUnit. + * Utilisé pour la conversion et le stockage en propriete des parametres + * @author poussin + * + */ +public class TimeUnitConverter implements Converter { + + /* (non-Javadoc) + * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) + */ + public Object convert(Class type, Object value) { + Object result; + if (value instanceof TimeUnit) { + result = value; + } else if (value instanceof Number) { + result = new TimeUnit(((Number)value).doubleValue()); + } else if (value instanceof String) { + double d = Double.parseDouble(value.toString()); + result = new TimeUnit(d); + } else { + throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); + } + return result; + } + +} + + Property changes on: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TimeUnitConverter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java (from rev 1254, branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java) =================================================================== --- branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java (rev 0) +++ branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -0,0 +1,129 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * TopiaEntityConverter.java + * + * Created: 12 janv. 2006 20:42:32 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package fr.ifremer.isisfish.util; + +import java.util.List; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.beanutils.Converter; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.persistence.TopiaEntity; +import org.codelutin.topia.persistence.TopiaId; +import org.hibernate.Hibernate; +import org.hibernate.HibernateException; +import org.hibernate.engine.QueryParameters; +import org.hibernate.engine.SessionImplementor; + + +/** + * Classe utilise pour convertir une chaine en un objet TopiaEntity. + * Utilisé pour la conversion et le stockage en propriete des parametres + * @author poussin + * + */ +public class TopiaEntityConverter implements Converter { + + /** + * Logger for this class + */ + private static final Log log = LogFactory + .getLog(TopiaEntityConverter.class); + + protected TopiaContext context = null; + protected SessionImplementor session = null; + + public TopiaEntityConverter(TopiaContext context) { + this.context = context; + } + + public TopiaEntityConverter(SessionImplementor session) { + this.session = session; + } + + /* (non-Javadoc) + * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) + */ + public Object convert(Class type, Object value) { + Object result = null; + if (value instanceof TopiaEntity) { + result = value; + } else if (value instanceof String){ + result = getTopiaEntity((String)value); + } else { + throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); + } + return result; + } + + private TopiaEntity getTopiaEntity(String topiaId) { + TopiaEntity result = null; + if (context != null) { + try { + TopiaContext tx = context.beginTransaction(); + result = tx.findByTopiaId(topiaId); + // FIXME when after tx.closeContext we can continu to load object, call it here + tx.commitTransaction(); + } catch (TopiaException eee) { + if (log.isWarnEnabled()) { + log.warn("Can't find Entity from TopiaId " + topiaId, eee); + } + } + } else if (session != null) { + QueryParameters params = new QueryParameters(Hibernate.STRING, topiaId); + String entityClass = TopiaId.getClassNameAsString(topiaId); + + try { + boolean mustCommit = false; + if (!session.getJDBCContext().getTransaction().isActive()) { + mustCommit = true; + session.getJDBCContext().getTransaction().begin(); + } + String hql = "from " + entityClass + " where topiaId=?"; + List results = session.list(hql, params); + if (mustCommit) { + session.getJDBCContext().getTransaction().commit(); + } + result = (TopiaEntity)results.get(0); + } catch (HibernateException eee) { + if (log.isDebugEnabled()) { + log.debug("Can't find TopiaEntity: " + topiaId, eee); + } + throw eee; + } + } + return result; + } + +} Property changes on: branches/maven2_multimodule/isis-fish/isis-fish-entities/src/main/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/DateType.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/DateType.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/DateType.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,107 +0,0 @@ -/* *##% - * Copyright (C) 2002, 2003 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 published by the Free Software Foundation; either version 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * DateType.java - * - * Created: 19 janv. 2006 - * - * @author Arnaud Thimel <thimel at codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -/** - * - */ -package fr.ifremer.isisfish.types.hibernate; - -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 fr.ifremer.isisfish.types.Date; - -public class DateType extends ImmutableType { - - /** */ - private static final long serialVersionUID = -5295147041590169149L; - - /* (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 Date(rs.getInt(name)); - } - - /* (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, ((Date) value).getDate()); - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#sqlType() - */ - @Override - public int sqlType() { - return Types.INTEGER; - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#toString(java.lang.Object) - */ - @Override - public String toString(Object value) throws HibernateException { - return ((Date)value).toString(); - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#fromStringValue(java.lang.String) - */ - @Override - public Object fromStringValue(String xml) throws HibernateException { - return new Date(Integer.parseInt(xml)); - } - - /* (non-Javadoc) - * @see org.hibernate.type.Type#getReturnedClass() - */ - public Class getReturnedClass() { - return Date.class; - } - - /* (non-Javadoc) - * @see org.hibernate.type.Type#getName() - */ - public String getName() { - return DateType.class.getName(); - } - -} Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/MatrixType.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/MatrixType.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/MatrixType.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,467 +0,0 @@ -/* *##% - * Copyright (C) 2002, 2003 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 published by the Free Software Foundation; either version 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * MatrixType.java - * - * Created: 23 janv. 2006 - * - * @author Arnaud Thimel <thimel at codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -package fr.ifremer.isisfish.types.hibernate; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.ConvertUtilsBean; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.math.matrix.MatrixFactory; -import org.codelutin.math.matrix.MatrixHelper; -import org.codelutin.math.matrix.MatrixND; -import org.codelutin.topia.persistence.TopiaEntity; -import org.codelutin.util.StringUtil; -import org.hibernate.Hibernate; -import org.hibernate.HibernateException; -import org.hibernate.engine.SessionImplementor; -import org.hibernate.lob.ClobImpl; -import org.hibernate.type.Type; -import org.hibernate.usertype.CompositeUserType; - -import fr.ifremer.isisfish.types.Date; -import fr.ifremer.isisfish.types.Month; -import fr.ifremer.isisfish.util.ConverterUtil; -import fr.ifremer.isisfish.util.DateConverter; -import fr.ifremer.isisfish.util.MonthConverter; -import fr.ifremer.isisfish.util.StringConverter; -import fr.ifremer.isisfish.util.TopiaEntityConverter; - -public class MatrixType implements CompositeUserType { - - /** - * Logger for this class - */ - private static final Log log = LogFactory.getLog(MatrixType.class); - - public MatrixType() { - } - - public boolean isMutable() { - return true; - } - - private String getDimToString(int[] dimArray) { - String result = "["; - String sep = ""; - for (int i=0; i<dimArray.length; i++) { - result += sep + dimArray[i]; - sep = ", "; - } - result += "]"; - return result; - } - - private int[] getDimFromString(String str) { - str = str.trim(); - if(str.startsWith("[") && str.endsWith("]")) { - str = str.substring(1, str.length()-1); // remove [ and ] - } - String [] dimAsString = StringUtil.split(str, ","); - int[] result = new int[dimAsString.length]; - int i = 0; - for (String dim : dimAsString) { - int val = Integer.parseInt(dim.trim()); - result[i++] = val; - } - return result; - } - - private String getDimNamesToString(String[] dimNamesArray) { - String result = "["; - String sep = ""; - for (int i=0; i<dimNamesArray.length; i++) { - result += sep + '"' + dimNamesArray[i] + '"'; - sep = ", "; - } - result += "]"; - return result; - } - - private String[] getDimNamesFromString(String str) { - str = str.trim(); - if(str.startsWith("[") && str.endsWith("]")) { - str = str.substring(1, str.length()-1); // remove [ and ] - } - String [] result = StringUtil.split(str, ","); - for (int i=0; i<result.length; i++) { - result[i] = result[i].trim(); - if(result[i].startsWith("\"") && result[i].endsWith("\"")) { - result[i] = result[i].substring(1, result[i].length()-1); // remove " and " - } - } - return result; - } - - private String getSemanticsToString(List[] semanticsArray) { - StringBuffer result = new StringBuffer("["); - for (int i=0; i<semanticsArray.length; i++) { - result.append("["); - List semantics = semanticsArray[i]; - for (Iterator it = semantics.iterator(); it.hasNext(); ) { - appendString(result, it.next()); - if (it.hasNext()) { - result.append(", "); - } - } - result.append("]"); - if ((i+1) < semanticsArray.length) { - result.append(", "); - } - } - return result.append("]").toString(); - } - - /** - * - * @param name nom de la matrice - * @param str la chaine representant la semantique - * @param session la session dans lequel on lit la matrice de la base - * @return - */ - private List[] getSemanticsFromString(String name, String str, SessionImplementor session) { - str = str.trim(); - if(str.startsWith("[") && str.endsWith("]")) { - str = str.substring(1, str.length()-1); // remove [ and ] - } - String [] sems = StringUtil.split(str, ","); - - List[] result = new List[sems.length]; - - for (int i=0; i<sems.length; i++) { - result[i] = splitObjects(name, sems[i], session); - } - - return result; - } - -// /** -// * Sépare la chaine de caractères en une List de List représentant le List[] -// * de semantics -// */ -// private List<List> splitLists(String str, SessionImplementor session) { -// int openBrackets = 0; -// int index = 1; -// int openIndex = 0; -// boolean inString = false; -// List<List> result = new LinkedList<List>(); -// while (index < (str.length()-1)) { -// char c = str.charAt(index); -// if (!inString && c == '[') { -// openIndex = index; -// openBrackets++; -// } else if (!inString && c == ']') { -// openBrackets--; -// if (openBrackets == 0) { -// result.add(splitObjects(str.substring(openIndex, index), session)); -// } -// } else if (c == '"' && str.charAt(index-1) != '\\') { -// inString = !inString; -// } -// index++; -// } -// return result; -// } - - /** - * Recréé chaque object de la chaine de caractere et l'ajoute dans une liste - * la chaine est de la forme - * - * [null(), java.lang.String("toto"), ...] - * @param name le nom de la matrice - * @param str la chaine representant - */ - private List splitObjects(String name, String str, SessionImplementor session) { - List<Object> result = new LinkedList<Object>(); - str = str.trim(); - if (str.startsWith("[") && str.endsWith("]")) { - str = str.substring(1, str.length() - 1); - } - String [] elems = StringUtil.split(str, ","); - for (String elem : elems) { - elem = elem.trim(); - int openbrace = elem.indexOf('('); - String objectType = elem.substring(0, openbrace); - String objectString = elem.substring(openbrace + 1, elem.length() - 1); - - if ("null".equals(objectType)) { - result.add(null); - } else { - ConvertUtilsBean converter = getConverter(session); - Object o; - try { - o = converter.convert(objectString, Class.forName(objectType)); - } catch (Exception eee) { - // if can't create objet, put String representation as semantics - o = objectType + "(" + objectString + ")"; - if (log.isWarnEnabled()) { - log.warn("Continuing but can't convert object in matrix " + name + " from String: '" + o + "'"); - } - if (log.isDebugEnabled()) { - log.debug("Continuing can't convert object in matrix " + name + " from String: '" + o + "'", eee); - } - } - result.add(o); - } - } - -// int index = 1; -// int openIndex = 0; -// while ((openIndex = str.indexOf('(', index+1)) != -1) { -// String qualifiedName = str.substring(index, openIndex); -// if (qualifiedName.startsWith(",")) { -// qualifiedName = qualifiedName.substring(1); -// } -// qualifiedName = qualifiedName.trim(); -// boolean inString = false; -// index = openIndex+1; -// while (index < (str.length())) { -// -// char c = str.charAt(index); -// if (!inString && c == ')') { -// try { -// if ("null".equals(qualifiedName)) { -// result.add(null); -// } else { -// String substr = str.substring(openIndex+1, index); -// ConvertUtilsBean cub = getConverter(session); -// Object o = cub.convert(substr, Class.forName(qualifiedName)); -// result.add(o); -// } -// break; -// } catch (ClassNotFoundException eee) { -// log.warn("Can't convert object from String"); -// if (log.isDebugEnabled()) { -// log.warn("Can't convert object from String" , eee); -// } -// e.printStackTrace(); -// } -// } else if (c == '"' && str.charAt(index-1) != '\\') { -// inString = !inString; -// } -// index++; -// } -// index++; -// } - - return result; - } - - private static final Type[] hibernateTypes = { - Hibernate.STRING, //name (String) - Hibernate.STRING, //dim (int[]) - Hibernate.CLOB, //dimNames (String[]) - Hibernate.CLOB, //semantics (List[]) - Hibernate.CLOB //data (List<List<...>>) - }; - - private static final String[] propertyNames = { - "name", - "dim", - "dimNames", - "semantics", - "data" - }; - - private StringBuffer appendString(StringBuffer buffer, Object o) { - if (o == null) { - buffer.append("null()"); - } else { - String qualifiedName = o.getClass().getName(); - if (o instanceof TopiaEntity) { - qualifiedName = TopiaEntity.class.getName(); - } - buffer.append(qualifiedName).append("("); - ConvertUtilsBean converter = getConverter(null); - buffer.append(converter.convert(o)); - buffer.append(")"); - } - return buffer; - } - - private ConvertUtilsBean getConverter(SessionImplementor session) { - ConvertUtilsBean cub = ConverterUtil.getConverter(null); - if (session != null) { - // others type is already registered during application init - cub.register(new TopiaEntityConverter(session), TopiaEntity.class); - } - return cub; - } - - public Class returnedClass() { - return MatrixND.class; - } - - public boolean equals(Object x, Object y) throws HibernateException { - if (x == y) { - return true; - } else if (x != null && y != null) { - return x.equals(y); - } else { - return false; - } - } - - public int hashCode(Object x) throws HibernateException { - return x.hashCode(); - } - - public Object deepCopy(Object value) throws HibernateException { - if (value == null) { - return null; - } - return MatrixFactory.getInstance().create((MatrixND)value); - } - - public String[] getPropertyNames() { - return propertyNames; - } - - public Type[] getPropertyTypes() { - return hibernateTypes; - } - - public Object getPropertyValue(Object component, int property) throws HibernateException { - MatrixND matrix = (MatrixND)component; - switch (property) { - case 0 : return matrix.getName(); - case 1 : return matrix.getDim(); - case 2 : return matrix.getDimensionName(); - case 3 : return matrix.getSemantics(); - case 4 : return matrix.toList(); - default : throw new HibernateException("Property index invalid : " + property); - } - } - - public void setPropertyValue(Object component, int property, Object value) throws HibernateException { - MatrixND matrix = (MatrixND)component; - switch (property) { - case 0 : matrix.setName((String)value); break; - case 1 : throw new HibernateException("Modification of the dimension forbidden"); - case 2 : matrix.setDimensionName((String[])value); break; - case 3 : - int index = 0; - for (List semantics : (List[])value) { - matrix.setSemantics(index, semantics); - index++; - } - break; - case 4 : matrix.fromList((List)value); break; - default : throw new HibernateException("Property index invalid : " + property); - } - } - - public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { - MatrixND matrix = null; - - String nameAsString = rs.getString(names[0]); - String dimAsString = rs.getString(names[1]); - String dimNamesAsString = rs.getString(names[2]); - String semanticsAsString = rs.getString(names[3]); - String datasAsString = rs.getString(names[4]); - - if (nameAsString == null && dimAsString == null && dimNamesAsString == null - && semanticsAsString == null) { // no now we have "" for that && datasAsString == null) { - matrix = null; - } else { - String name = nameAsString; - int[] dim = getDimFromString(dimAsString); - String[] dimNames = getDimNamesFromString(dimNamesAsString); - List[] semantics = getSemanticsFromString(name, semanticsAsString, session); - List datas = MatrixHelper.convertStringToList(datasAsString); - - matrix = MatrixFactory.getInstance().create(name, dim); - matrix.setDimensionName(dimNames); - for (int i=0; i<semantics.length; i++) { - matrix.setSemantics(i, semantics[i]); - } - matrix.fromList(datas); - session.getPersistenceContext(); - } - return matrix; - } - - public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { - if (value == null) { - st.setString(index, null); - st.setString(index + 1, null); - st.setString(index + 2, null); - st.setString(index + 3, null); - st.setClob(index + 4, new ClobImpl("")); - } else { - MatrixND matrix = MatrixFactory.getInstance().create((MatrixND)value); - st.setString(index, matrix.getName()); - st.setString(index + 1, getDimToString(matrix.getDim())); - st.setString(index + 2, getDimNamesToString(matrix.getDimensionName())); - st.setString(index + 3, getSemanticsToString(matrix.getSemantics())); - st.setClob(index + 4, new ClobImpl(matrix.toList().toString())); - } - } - - public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException { - MatrixND matrix = (MatrixND)value; - return new Serializable[] { - matrix.getName(), - getDimToString(matrix.getDim()), - getDimNamesToString(matrix.getDimensionName()), - getSemanticsToString(matrix.getSemantics()), - matrix.toList().toString() - }; - } - - public Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException { - Serializable[] o = (Serializable[])cached; - String name = (String)o[0]; - int[] dim = getDimFromString((String)o[1]); - String[] dimNames = getDimNamesFromString((String)o[2]); - List[] semantics = getSemanticsFromString(name, (String)o[3], session); - List datas = MatrixHelper.convertStringToList((String)o[4]); - MatrixND matrix = MatrixFactory.getInstance().create(name, dim); - matrix.setDimensionName(dimNames); - for (int i=0; i<semantics.length; i++) { - matrix.setSemantics(i, semantics[i]); - } - matrix.fromList(datas); - return matrix; - } - - public Object replace(Object original, Object target, SessionImplementor session, Object owner) throws HibernateException { - return assemble( disassemble(original, session), session, owner); - } - -} //MatrixType Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/MonthType.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/MonthType.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/MonthType.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,104 +0,0 @@ -/* *##% - * Copyright (C) 2002, 2003 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 published by the Free Software Foundation; either version 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * DateType.java - * - * Created: 19 janv. 2006 - * - * @author Arnaud Thimel <thimel at codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -/** - * - */ -package fr.ifremer.isisfish.types.hibernate; - -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 fr.ifremer.isisfish.types.Month; - -public class MonthType extends ImmutableType { - - /* (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)]; - } - - /* (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()); - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#sqlType() - */ - @Override - public int sqlType() { - return Types.INTEGER; - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#toString(java.lang.Object) - */ - @Override - public String toString(Object value) throws HibernateException { - return ((Month)value).toString(); - } - - /* (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)]; - } - - /* (non-Javadoc) - * @see org.hibernate.type.Type#getReturnedClass() - */ - public Class getReturnedClass() { - return Month.class; - } - - /* (non-Javadoc) - * @see org.hibernate.type.Type#getName() - */ - public String getName() { - return MonthType.class.getName(); - } - -} Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/RangeOfValuesType.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/RangeOfValuesType.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/RangeOfValuesType.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,107 +0,0 @@ -/* *##% - * Copyright (C) 2002, 2003 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 published by the Free Software Foundation; either version 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * DateType.java - * - * Created: 19 janv. 2006 - * - * @author Arnaud Thimel <thimel at codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -/** - * - */ -package fr.ifremer.isisfish.types.hibernate; - -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 fr.ifremer.isisfish.types.RangeOfValues; - -public class RangeOfValuesType extends ImmutableType { - - /** */ - private static final long serialVersionUID = -5295147041590169149L; - - /* (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)); - } - - /* (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()); - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#sqlType() - */ - @Override - public int sqlType() { - return Types.VARCHAR; - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#toString(java.lang.Object) - */ - @Override - public String toString(Object value) throws HibernateException { - return ((RangeOfValues)value).getAsString(); - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#fromStringValue(java.lang.String) - */ - @Override - public Object fromStringValue(String xml) throws HibernateException { - return new RangeOfValues(xml); - } - - /* (non-Javadoc) - * @see org.hibernate.type.Type#getReturnedClass() - */ - public Class getReturnedClass() { - return RangeOfValues.class; - } - - /* (non-Javadoc) - * @see org.hibernate.type.Type#getName() - */ - public String getName() { - return RangeOfValuesType.class.getName(); - } - -} Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/TimeUnitType.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/TimeUnitType.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/types/hibernate/TimeUnitType.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,107 +0,0 @@ -/* *##% - * Copyright (C) 2002, 2003 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 published by the Free Software Foundation; either version 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * DateType.java - * - * Created: 19 janv. 2006 - * - * @author Arnaud Thimel <thimel at codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -/** - * - */ -package fr.ifremer.isisfish.types.hibernate; - -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 fr.ifremer.isisfish.types.TimeUnit; - -public class TimeUnitType extends ImmutableType { - - /** */ - private static final long serialVersionUID = -5295147041590169149L; - - /* (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)); - } - - /* (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()); - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#sqlType() - */ - @Override - public int sqlType() { - return Types.DOUBLE; - } - - /* (non-Javadoc) - * @see org.hibernate.type.NullableType#toString(java.lang.Object) - */ - @Override - public String toString(Object value) throws HibernateException { - return ((TimeUnit)value).toString(); - } - - /* (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)); - } - - /* (non-Javadoc) - * @see org.hibernate.type.Type#getReturnedClass() - */ - public Class getReturnedClass() { - return TimeUnit.class; - } - - /* (non-Javadoc) - * @see org.hibernate.type.Type#getName() - */ - public String getName() { - return TimeUnitType.class.getName(); - } - -} Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/ConverterUtil.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/ConverterUtil.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/ConverterUtil.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,72 +0,0 @@ -/* *##% - * Copyright (C) 2006 - * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * ConverterUtil.java - * - * Created: 25 sept. 06 19:37:16 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package fr.ifremer.isisfish.util; - -import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.ConvertUtilsBean; -import org.codelutin.topia.TopiaContext; -import org.codelutin.topia.persistence.TopiaEntity; - -import fr.ifremer.isisfish.types.Date; -import fr.ifremer.isisfish.types.Month; -import fr.ifremer.isisfish.types.RangeOfValues; -import fr.ifremer.isisfish.types.TimeUnit; - - -/** - * @author poussin - * - */ - -public class ConverterUtil { - - static public ConvertUtilsBean getConverter(TopiaContext context) { - BeanUtilsBean result = BeanUtilsBean.getInstance(); - ConvertUtilsBean cub = result.getConvertUtils(); - - cub.register(new TopiaEntityConverter(context), TopiaEntity.class); - - // FIXME see if register done in IsisFish.init() method permit to remove next line - // mise en place de converter de string vers des objet ... - cub.register(new DateConverter(), Date.class); - cub.register(new MonthConverter(), Month.class); - cub.register(new TimeUnitConverter(), TimeUnit.class); - cub.register(new RangeOfValuesConverter(), RangeOfValues.class); - // ... et inversement - cub.register(new StringConverter(), String.class); - - return cub; - } - -} - - Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/DateConverter.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/DateConverter.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/DateConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,68 +0,0 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * DateConverter.java - * - * Created: 13 janv. 2006 01:13:41 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package fr.ifremer.isisfish.util; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; - -import fr.ifremer.isisfish.types.Date; - - -/** - * Classe utilise pour convertir une chaine en un objet Date. - * Utilisé pour la conversion et le stockage en propriete des parametres - * @author poussin - * - */ -public class DateConverter implements Converter { - - /* (non-Javadoc) - * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) - */ - public Object convert(Class type, Object value) { - Object result; - if (value instanceof Date) { - result = value; - } else if (value instanceof String) { - int d = Integer.parseInt(value.toString()); - result = new Date(d); - } else if (value == null) { - result = new Date(0); - } else { - throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); - } - return result; - } - -} - - Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/MonthConverter.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/MonthConverter.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/MonthConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,70 +0,0 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * MonthConverter.java - * - * Created: 12 janv. 2006 20:23:35 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package fr.ifremer.isisfish.util; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; - -import fr.ifremer.isisfish.types.Month; - - -/** - * Classe utilise pour convertir une chaine en un objet Month. - * Utilisé pour la conversion et le stockage en propriete des parametres - * @author poussin - * - */ - -public class MonthConverter implements Converter { - - /* (non-Javadoc) - * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) - */ - public Object convert(Class type, Object value) { - Object result = null; - if (value instanceof Month) { - result = value; - } else if (value instanceof String) { - int m = Integer.parseInt(value.toString()); - result = Month.MONTH[m]; - } else if (value instanceof Integer) { - int m = ((Integer)value).intValue(); - result = Month.MONTH[m]; - } else { - throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); - } - return result; - } - -} - - Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/RangeOfValuesConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,65 +0,0 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * DateConverter.java - * - * Created: 13 janv. 2006 01:13:41 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package fr.ifremer.isisfish.util; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; - -import fr.ifremer.isisfish.types.RangeOfValues; - - -/** - * Classe utilise pour convertir une chaine en un objet RangeOfValues. - * Utilisé pour la conversion et le stockage en propriete des parametres - * @author poussin - * - */ -public class RangeOfValuesConverter implements Converter { - - /* (non-Javadoc) - * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) - */ - public Object convert(Class type, Object value) { - Object result; - if (value instanceof RangeOfValues) { - result = value; - } else if (value instanceof String) { - result = new RangeOfValues(value.toString()); - } else { - throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); - } - return result; - } - -} - - Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/StringConverter.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/StringConverter.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/StringConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,77 +0,0 @@ -/* - * *##% Copyright (C) 2006 Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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 2 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, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307, USA. ##% - */ - -/******************************************************************************* - * StringConverter.java - * - * Created: 12 janv. 2006 20:38:26 - * - * @author poussin - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - -package fr.ifremer.isisfish.util; - -import org.apache.commons.beanutils.Converter; -import org.codelutin.topia.persistence.TopiaEntity; - -import fr.ifremer.isisfish.types.Date; -import fr.ifremer.isisfish.types.Month; -import fr.ifremer.isisfish.types.TimeUnit; - -/** - * Classe utilise pour convertir en chaine un objet Date, Month ou TopiaEntity - * Utilisé pour la conversion et le stockage en propriete des parametres - * @author poussin - * - */ -public class StringConverter implements Converter { - - private Converter defaultStringConverter = - new org.apache.commons.beanutils.converters.StringConverter(); - - - /* - * (non-Javadoc) - * - * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, - * java.lang.Object) - */ - public Object convert(Class type, Object o) { - Object result = null; - if (o != null) { - if (o instanceof TopiaEntity) { - result = ((TopiaEntity) o).getTopiaId(); - } else if (o instanceof Date) { - result = String.valueOf(((Date) o).getDate()); - } else if (o instanceof Month) { - result = String.valueOf(((Month) o).getMonthNumber()); - } else if (o instanceof TimeUnit) { - result = String.valueOf(((TimeUnit) o).getTime()); - } else { - // dans tous les autres cas, on appelle le converter par defaut - result = defaultStringConverter.convert(type, o); - } - } - return result; - } - -} Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TimeUnitConverter.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TimeUnitConverter.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TimeUnitConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,68 +0,0 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * DateConverter.java - * - * Created: 13 janv. 2006 01:13:41 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package fr.ifremer.isisfish.util; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; - -import fr.ifremer.isisfish.types.TimeUnit; - - -/** - * Classe utilise pour convertir une chaine en un objet TimeUnit. - * Utilisé pour la conversion et le stockage en propriete des parametres - * @author poussin - * - */ -public class TimeUnitConverter implements Converter { - - /* (non-Javadoc) - * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) - */ - public Object convert(Class type, Object value) { - Object result; - if (value instanceof TimeUnit) { - result = value; - } else if (value instanceof Number) { - result = new TimeUnit(((Number)value).doubleValue()); - } else if (value instanceof String) { - double d = Double.parseDouble(value.toString()); - result = new TimeUnit(d); - } else { - throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); - } - return result; - } - -} - - Deleted: branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java =================================================================== --- branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java 2008-07-28 20:42:24 UTC (rev 1265) +++ branches/maven2_multimodule/isis-fish/src/java/fr/ifremer/isisfish/util/TopiaEntityConverter.java 2008-07-28 20:49:19 UTC (rev 1266) @@ -1,129 +0,0 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * TopiaEntityConverter.java - * - * Created: 12 janv. 2006 20:42:32 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package fr.ifremer.isisfish.util; - -import java.util.List; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.topia.TopiaContext; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.persistence.TopiaEntity; -import org.codelutin.topia.persistence.TopiaId; -import org.hibernate.Hibernate; -import org.hibernate.HibernateException; -import org.hibernate.engine.QueryParameters; -import org.hibernate.engine.SessionImplementor; - - -/** - * Classe utilise pour convertir une chaine en un objet TopiaEntity. - * Utilisé pour la conversion et le stockage en propriete des parametres - * @author poussin - * - */ -public class TopiaEntityConverter implements Converter { - - /** - * Logger for this class - */ - private static final Log log = LogFactory - .getLog(TopiaEntityConverter.class); - - protected TopiaContext context = null; - protected SessionImplementor session = null; - - public TopiaEntityConverter(TopiaContext context) { - this.context = context; - } - - public TopiaEntityConverter(SessionImplementor session) { - this.session = session; - } - - /* (non-Javadoc) - * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) - */ - public Object convert(Class type, Object value) { - Object result = null; - if (value instanceof TopiaEntity) { - result = value; - } else if (value instanceof String){ - result = getTopiaEntity((String)value); - } else { - throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); - } - return result; - } - - private TopiaEntity getTopiaEntity(String topiaId) { - TopiaEntity result = null; - if (context != null) { - try { - TopiaContext tx = context.beginTransaction(); - result = tx.findByTopiaId(topiaId); - // FIXME when after tx.closeContext we can continu to load object, call it here - tx.commitTransaction(); - } catch (TopiaException eee) { - if (log.isWarnEnabled()) { - log.warn("Can't find Entity from TopiaId " + topiaId, eee); - } - } - } else if (session != null) { - QueryParameters params = new QueryParameters(Hibernate.STRING, topiaId); - String entityClass = TopiaId.getClassNameAsString(topiaId); - - try { - boolean mustCommit = false; - if (!session.getJDBCContext().getTransaction().isActive()) { - mustCommit = true; - session.getJDBCContext().getTransaction().begin(); - } - String hql = "from " + entityClass + " where topiaId=?"; - List results = session.list(hql, params); - if (mustCommit) { - session.getJDBCContext().getTransaction().commit(); - } - result = (TopiaEntity)results.get(0); - } catch (HibernateException eee) { - if (log.isDebugEnabled()) { - log.debug("Can't find TopiaEntity: " + topiaId, eee); - } - throw eee; - } - } - return result; - } - -}