Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/BooleanJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/BooleanJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:50 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/BooleanJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,72 @@ +/* *##% +* Copyright (C) 2005 +* 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. +*##%*/ + +/* * +* BooleanJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class BooleanJDBCTransformer implements JDBCTransformer { // BooleanJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(BooleanJDBCTransformer.class); + + public Class getJavaType(){ + return Boolean.class; + } + + public String getJDBCType(){ + return "Boolean"; + } + + public Object getJDBCValue(Boolean value){ + return value; + } + + public Boolean getJavaValue(Object value){ + return (Boolean)value; + } + + public void setValue(PreparedStatement sta, int indice, Boolean value) throws SQLException { + Boolean b = (Boolean)getJDBCValue(value); + sta.setBoolean(indice, b.booleanValue()); + } + + public Boolean getValue(ResultSet rs, String columnName) throws SQLException { + boolean b = rs.getBoolean(columnName); + return getJavaValue(b?Boolean.TRUE:Boolean.FALSE); + } + +} // BooleanJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ByteJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ByteJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ByteJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,72 @@ +/* *##% +* Copyright (C) 2005 +* 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. +*##%*/ + +/* * +* ByteJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ByteJDBCTransformer implements JDBCTransformer { // ByteJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ByteJDBCTransformer.class); + + public Class getJavaType(){ + return Byte.class; + } + + public String getJDBCType(){ + return "Byte"; + } + + public Object getJDBCValue(Byte value){ + return value; + } + + public Byte getJavaValue(Object value){ + return (Byte)value; + } + + public void setValue(PreparedStatement sta, int indice, Byte value) throws SQLException { + Byte b = (Byte)getJDBCValue(value); + sta.setByte(indice, b.byteValue()); + } + + public Byte getValue(ResultSet rs, String columnName) throws SQLException { + byte b = rs.getByte(columnName); + return getJavaValue(Byte.valueOf(b)); + } + +} // ByteJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/BytesJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/BytesJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/BytesJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,72 @@ +/* *##% +* Copyright (C) 2005 +* 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. +*##%*/ + +/* * +* BytesJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class BytesJDBCTransformer implements JDBCTransformer { // BytesJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(BytesJDBCTransformer.class); + + public Class getJavaType(){ + return (new byte[0]).getClass(); + } + + public String getJDBCType(){ + return "Bytes"; + } + + public Object getJDBCValue(byte[] value){ + return value; + } + + public byte[] getJavaValue(Object value){ + return (byte[])value; + } + + public void setValue(PreparedStatement sta, int indice, byte[] value) throws SQLException { + byte[] b = (byte[])getJDBCValue(value); + sta.setBytes(indice, b); + } + + public byte[] getValue(ResultSet rs, String columnName) throws SQLException { + byte[] b = rs.getBytes(columnName); + return getJavaValue(b); + } + +} // BytesJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/DateJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/DateJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/DateJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,73 @@ +/* *##% +* Copyright (C) 2005 +* 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 +* aDate with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* DateJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class DateJDBCTransformer implements JDBCTransformer { // DateJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(DateJDBCTransformer.class); + + public Class getJavaType(){ + return Date.class; + } + + public String getJDBCType(){ + return "Date"; + } + + public Object getJDBCValue(Date value){ + return value; + } + + public Date getJavaValue(Object value){ + return (Date)value; + } + + public void setValue(PreparedStatement sta, int indice, Date value) throws SQLException { + Date b = (Date)getJDBCValue(value); + sta.setDate(indice, b); + } + + public Date getValue(ResultSet rs, String columnName) throws SQLException { + Date b = rs.getDate(columnName); + return getJavaValue(b); + } + +} // DateJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/DoubleJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/DoubleJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/DoubleJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,72 @@ +/* *##% +* Copyright (C) 2005 +* 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. +*##%*/ + +/* * +* DoubleJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class DoubleJDBCTransformer implements JDBCTransformer { // DoubleJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(DoubleJDBCTransformer.class); + + public Class getJavaType(){ + return Double.class; + } + + public String getJDBCType(){ + return "Double"; + } + + public Object getJDBCValue(Double value){ + return value; + } + + public Double getJavaValue(Object value){ + return (Double)value; + } + + public void setValue(PreparedStatement sta, int indice, Double value) throws SQLException { + Double b = (Double)getJDBCValue(value); + sta.setDouble(indice, b.doubleValue()); + } + + public Double getValue(ResultSet rs, String columnName) throws SQLException { + double b = rs.getDouble(columnName); + return getJavaValue(Double.valueOf(b)); + } + +} // DoubleJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/FloatJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/FloatJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/FloatJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,72 @@ +/* *##% +* Copyright (C) 2005 +* 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. +*##%*/ + +/* * +* FloatJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class FloatJDBCTransformer implements JDBCTransformer { // FloatJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(FloatJDBCTransformer.class); + + public Class getJavaType(){ + return Float.class; + } + + public String getJDBCType(){ + return "Float"; + } + + public Object getJDBCValue(Float value){ + return value; + } + + public Float getJavaValue(Object value){ + return (Float)value; + } + + public void setValue(PreparedStatement sta, int indice, Float value) throws SQLException { + Float b = (Float)getJDBCValue(value); + sta.setFloat(indice, b.floatValue()); + } + + public Float getValue(ResultSet rs, String columnName) throws SQLException { + float b = rs.getFloat(columnName); + return getJavaValue(Float.valueOf(b)); + } + +} // FloatJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/IntegerJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/IntegerJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/IntegerJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,72 @@ +/* *##% +* Copyright (C) 2005 +* 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 +* ainteger with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* IntegerJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class IntegerJDBCTransformer implements JDBCTransformer { // IntegerJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(IntegerJDBCTransformer.class); + + public Class getJavaType(){ + return Integer.class; + } + + public String getJDBCType(){ + return "Integer"; + } + + public Object getJDBCValue(Integer value){ + return value; + } + + public Integer getJavaValue(Object value){ + return (Integer)value; + } + + public void setValue(PreparedStatement sta, int indice, Integer value) throws SQLException { + Integer b = (Integer)getJDBCValue(value); + sta.setInt(indice, b.intValue()); + } + + public Integer getValue(ResultSet rs, String columnName) throws SQLException { + int b = rs.getInt(columnName); + return getJavaValue(Integer.valueOf(b)); + } + +} // IntegerJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/JDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/JDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/JDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,92 @@ +/* *##% + * Copyright (C) 2005 + * 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. + *##%*/ + +/* * + * JDBCTransformer.java + * + * Created: 23 août 2005 12:12:25 CEST + * + * @author Benjamin POUSSIN + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2005/08/24 15:03:45 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** +* Permet de transformer un objet Java en une representation utilisable +* pour le stockage dans une base de donnée. +* T est le type d'objet Java géré +*/ +public interface JDBCTransformer { // JDBCTransformer + + /** + * Retourne la classe Java géré par cet objet + * @return la classe géré par cet objet + */ + public Class getJavaType(); + + /** + * Retourne le type JDBC à utiliser pour la classe Java géré par + * par cette objet. Le type doit être un des types gérés par les + * méthode des {@link java.sql.PreparedStatement} + * @return le type en JDBC + */ + public String getJDBCType(); + + /** + * Retourne la representation JDBC de l'objet passé en paramètre + * @param la valeur en Java + * @return la valeur en JDBC + */ + public Object getJDBCValue(T value); + + /** + * Retourne la representation Java de l'objet passé en paramètre + * @param la valeur en JDBC + * @return la valeur en Java + */ + public T getJavaValue(Object value); + + /** + * Permet de mettre la valeur directement dans le PreparedStatement + * @param sta le PreparedStatement dans lequel on souhaite mettre la valeur + * @param indice la position on la valeur doit etre mise + * @param value la valeur Java a mettre dans le PreparedStatement + */ + public void setValue(PreparedStatement sta, int indice, T value) throws SQLException; + + /** + * Permet de récupérer la valeur Java depuis un ResultSet. + * @param rs le ResultSet dans lequel il faut prendre la valeur + * @param columnName le nom de la colone dans la base de données + * @return la valeur Java + */ + public T getValue(ResultSet rs, String columnName) throws SQLException; + +} // JDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/JDBCTransformerFactory.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/JDBCTransformerFactory.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/JDBCTransformerFactory.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,83 @@ +/* *##% + * Copyright (C) 2005 + * 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. + *##%*/ + +/* * + * JDBCTransformerFactory.java + * + * Created: 23 août 2005 12:37:17 CEST + * + * @author Benjamin POUSSIN + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2005/08/24 15:03:45 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class JDBCTransformerFactory { // JDBCTransformerFactory + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(JDBCTransformerFactory.class); + + static protected Map transformers = + new HashMap(); + + /** + * Permet d'ajout un nouvel objet pour géré un type de classe particulier + * @param clazz la classe Java géré par cette objet + * @param t le transformer a utiliser pour ce type + */ + static public void register(Class clazz, JDBCTransformer t){ + transformers.put(clazz, t); + } + + /** + * Retoure le transformer qui gere la classe passée en parametre + * @param clazz la classe pour lequel on souhaite le transformer + */ + static public JDBCTransformer getTransformer(Class clazz){ + JDBCTransformer result = transformers.get(clazz); + return result; + } + + static { + register(Boolean.class, new BooleanJDBCTransformer()); + register(Byte.class, new ByteJDBCTransformer()); + register((new byte[0]).getClass(), new BytesJDBCTransformer()); + register(Date.class, new DateJDBCTransformer()); + register(Double.class, new DoubleJDBCTransformer()); + register(Float.class, new FloatJDBCTransformer()); + register(Integer.class, new IntegerJDBCTransformer()); + register(Long.class, new LongJDBCTransformer()); + register(Object.class, new ObjectJDBCTransformer()); + register(Short.class, new ShortJDBCTransformer()); + register(String.class, new StringJDBCTransformer()); + } + +} // JDBCTransformerFactory + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/LongJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/LongJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/LongJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,72 @@ +/* *##% +* Copyright (C) 2005 +* 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. +*##%*/ + +/* * +* LongJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class LongJDBCTransformer implements JDBCTransformer { // LongJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(LongJDBCTransformer.class); + + public Class getJavaType(){ + return Long.class; + } + + public String getJDBCType(){ + return "Long"; + } + + public Object getJDBCValue(Long value){ + return value; + } + + public Long getJavaValue(Object value){ + return (Long)value; + } + + public void setValue(PreparedStatement sta, int indice, Long value) throws SQLException { + Long b = (Long)getJDBCValue(value); + sta.setLong(indice, b.longValue()); + } + + public Long getValue(ResultSet rs, String columnName) throws SQLException { + long b = rs.getLong(columnName); + return getJavaValue(Long.valueOf(b)); + } + +} // LongJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ObjectJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ObjectJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ObjectJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,102 @@ +/* *##% +* Copyright (C) 2005 +* 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. +*##%*/ + +/* * +* ObjectJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ObjectJDBCTransformer implements JDBCTransformer { // ObjectJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ObjectJDBCTransformer.class); + + public Class getJavaType(){ + return Object.class; + } + + public String getJDBCType(){ + return "Object"; + } + + public Object getJDBCValue(Object value){ + Object result = null; + if(value != null){ + try{ + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(value); + baos.close(); + result = baos.toByteArray(); + }catch(IOException eee){ + throw new RuntimeException("Error during transformation object type: " + value.getClass().getName(), eee); + } + } + return result; + } + + public Object getJavaValue(Object value){ + Object result = null; + if(value != null){ + try{ + ByteArrayInputStream bais = new ByteArrayInputStream((byte[])value); + ObjectInputStream ois = new ObjectInputStream(bais); + result = ois.readObject(); + bais.close(); + }catch(IOException eee){ + throw new RuntimeException("Error during transformation object type: " + value.getClass().getName(), eee); + }catch(ClassNotFoundException eee){ + throw new RuntimeException("Error during transformation object type: " + value.getClass().getName(), eee); + } + } + return result; + } + + public void setValue(PreparedStatement sta, int indice, Object value) throws SQLException { + byte[] b = (byte[])getJDBCValue(value); + sta.setBytes(indice, b); + } + + public Object getValue(ResultSet rs, String columnName) throws SQLException { + byte[] b = rs.getBytes(columnName); + return getJavaValue(b); + } + +} // ObjectJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ShortJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ShortJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/ShortJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,72 @@ +/* *##% +* Copyright (C) 2005 +* 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 +* ashort with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* ShortJDBCTransformer.java +* +* Created: 23 août 2005 12:57:39 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ShortJDBCTransformer implements JDBCTransformer { // ShortJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ShortJDBCTransformer.class); + + public Class getJavaType(){ + return Short.class; + } + + public String getJDBCType(){ + return "Short"; + } + + public Object getJDBCValue(Short value){ + return value; + } + + public Short getJavaValue(Object value){ + return (Short)value; + } + + public void setValue(PreparedStatement sta, int indice, Short value) throws SQLException { + Short b = (Short)getJDBCValue(value); + sta.setShort(indice, b.shortValue()); + } + + public Short getValue(ResultSet rs, String columnName) throws SQLException { + short b = rs.getShort(columnName); + return getJavaValue(Short.valueOf(b)); + } + +} // ShortJDBCTransformer + Index: topia/src/java/org/codelutin/topia/persistence/jdbctransformer/StringJDBCTransformer.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbctransformer/StringJDBCTransformer.java:1.1 --- /dev/null Wed Aug 24 15:03:51 2005 +++ topia/src/java/org/codelutin/topia/persistence/jdbctransformer/StringJDBCTransformer.java Wed Aug 24 15:03:45 2005 @@ -0,0 +1,71 @@ +/* *##% +* Copyright (C) 2005 +* 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. +*##%*/ + +/* * +* StringJDBCTransformer.java +* +* Created: 23 août 2005 12:56:14 CEST +* +* @author Benjamin POUSSIN +* @version $Revision: 1.1 $ +* +* Last update: $Date: 2005/08/24 15:03:45 $ +* by : $Author: bpoussin $ +*/ + +package org.codelutin.topia.persistence.jdbctransformer; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class StringJDBCTransformer implements JDBCTransformer { // StringJDBCTransformer + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(StringJDBCTransformer.class); + + public Class getJavaType(){ + return String.class; + } + + public String getJDBCType(){ + return "String"; + } + + public Object getJDBCValue(String value){ + return value; + } + + public String getJavaValue(Object value){ + return (String)value; + } + + public void setValue(PreparedStatement sta, int indice, String value) throws SQLException { + String b = (String)getJDBCValue(value); + sta.setString(indice, b); + } + + public String getValue(ResultSet rs, String columnName) throws SQLException { + return getJavaValue(rs.getString(columnName)); + } + +} // StringJDBCTransformer +