[Csvtosql-cvs] csvtosql_jdk50/src/net/sf/csv2sql/grammars/mysql GrammarFactory.java,NONE,1.1 MysqlFi
Brought to you by:
davideconsonni
|
From: consonni d. <dav...@us...> - 2005-04-25 10:53:27
|
Update of /cvsroot/csvtosql/csvtosql_jdk50/src/net/sf/csv2sql/grammars/mysql In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15138/net/sf/csv2sql/grammars/mysql Added Files: GrammarFactory.java MysqlFieldBigint.java MysqlFieldBit.java MysqlFieldChar.java MysqlFieldDate.java MysqlFieldDouble.java MysqlFieldFloat.java MysqlFieldInt.java MysqlFieldMediumint.java MysqlFieldSmallint.java MysqlFieldTinyint.java Log Message: no message --- NEW FILE: MysqlFieldSmallint.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldSmallint extends AbstractField { public static final int MIN_VALUE = -32768; public static final int MAX_VALUE = 65535; public MysqlFieldSmallint(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value); int result = Integer.parseInt(strValue.trim()); //check integrity if (result < MIN_VALUE || result > MAX_VALUE) { throw new FieldRenderException(this, value, "small int value out of range ("+strValue+")", null); } //render return String.valueOf(strValue); } catch (NumberFormatException e) { throw new FieldRenderException(this, value, "not an number", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: MysqlFieldTinyint.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldTinyint extends AbstractField { public static final int MIN_VALUE = -128; public static final int MAX_VALUE = 255; public MysqlFieldTinyint(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value); int result = Integer.parseInt(strValue.trim()); //check integrity if (result < MIN_VALUE || result > MAX_VALUE) { throw new FieldRenderException(this, value, "tiny int value out of range ("+strValue+")", null); } //render return String.valueOf(strValue); } catch (NumberFormatException e) { throw new FieldRenderException(this, value, "not an number", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: MysqlFieldInt.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldInt extends AbstractField { public static final long MIN_VALUE = Long.parseLong("-2147483648"); public static final long MAX_VALUE = Long.parseLong("4294967295"); public MysqlFieldInt(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value); long result = Long.parseLong(strValue.trim()); //check integrity if (result < MIN_VALUE || result > MAX_VALUE) { throw new FieldRenderException(this, value, "int value out of range ("+strValue+")", null); } //render return String.valueOf(strValue); } catch (NumberFormatException e) { throw new FieldRenderException(this, value, "not an number", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: MysqlFieldMediumint.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldMediumint extends AbstractField { public static final int MIN_VALUE = -8388608; public static final int MAX_VALUE = 16777215; public MysqlFieldMediumint(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value); int result = Integer.parseInt(strValue.trim()); //check integrity if (result < MIN_VALUE || result > MAX_VALUE) { throw new FieldRenderException(this, value, "medium Int value out of range ("+strValue+")", null); } //render return String.valueOf(strValue); } catch (NumberFormatException e) { throw new FieldRenderException(this, value, "not an number", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: MysqlFieldDate.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldDate extends AbstractField { public MysqlFieldDate(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { String result = null; try { if ( (value == null) || ("".equals((String)value)) ) { result = getDefaulNullValue(); } else { String inputFormat = this.getFieldProperties().getProperty("inputformat"); if (inputFormat == null) { inputFormat = "dd/MM/yy"; } String outputFormat = this.getFieldProperties().getProperty("outputformat"); if (outputFormat == null) { outputFormat = "dd/MM/yy"; } //check if Date is valid SimpleDateFormat df = new SimpleDateFormat(inputFormat); Date date = df.parse( (String)value ); //custom format df = new SimpleDateFormat(outputFormat); //format Date result = "\'"+df.format(date)+"\'"; } } catch (ParseException e) { throw new FieldRenderException(this, value, "not a date", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } return result; } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { HashMap<String, String> hm = new HashMap<String, String>(); hm.put("inputformat","format of date in input."); hm.put("outputformat","format of date in output."); return hm; } } --- NEW FILE: MysqlFieldBigint.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldBigint extends AbstractField { public static final float MIN_VALUE = Float.parseFloat("-9223372036854775808"); public static final float MAX_VALUE = Float.parseFloat("18446744073709551615"); public MysqlFieldBigint(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value); float result = Float.parseFloat(strValue.trim()); //check integrity if (result < MIN_VALUE || result > MAX_VALUE) { throw new FieldRenderException(this, value, "big Int value out of range ("+strValue+")", null); } //render return String.valueOf(strValue); } catch (NumberFormatException e) { throw new FieldRenderException(this, value, "not an number", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: MysqlFieldDouble.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldDouble extends AbstractField { public static final float MIN_VALUE = Float.parseFloat("-1.7976931348623157E+308"); public static final float MAX_VALUE = Float.parseFloat("1.7976931348623157E+308"); public MysqlFieldDouble(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value).replaceAll(",", "."); float result = Float.parseFloat(strValue.trim()); //check integrity if (result < MIN_VALUE || result > MAX_VALUE) { throw new FieldRenderException(this, value, "float value out of range ("+strValue+")", null); } //render return String.valueOf(strValue); } catch (NumberFormatException e) { throw new FieldRenderException(this, value, "not an number", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: MysqlFieldBit.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldBit extends AbstractField { public static final byte MIN_VALUE = 0; public static final byte MAX_VALUE = 1; public MysqlFieldBit(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value); byte result = Byte.parseByte(strValue.trim()); //check integrity if (result < MIN_VALUE || result > MAX_VALUE) { throw new FieldRenderException(this, value, "bit value out of range ("+strValue+")", null); } //render return String.valueOf(strValue); } catch (NumberFormatException e) { throw new FieldRenderException(this, value, "not an number", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: MysqlFieldFloat.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldFloat extends AbstractField { public static final float MIN_VALUE = Float.parseFloat("-3.402823466E+38"); public static final float MAX_VALUE = Float.parseFloat("3.402823466E+38"); public MysqlFieldFloat(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value).replaceAll(",", "."); long result = Long.parseLong(strValue.trim()); //check integrity if (result < MIN_VALUE || result > MAX_VALUE) { throw new FieldRenderException(this, value, "float value out of range ("+strValue+")", null); } //render return String.valueOf(strValue); } catch (NumberFormatException e) { throw new FieldRenderException(this, value, "not an number", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: MysqlFieldChar.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.util.HashMap; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.exceptions.FieldRenderException; import net.sf.csv2sql.grammars.exceptions.MissingRequiredParameterException; /** * @see AbstractField * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class MysqlFieldChar extends AbstractField { public static final String PRE = "\'"; public static final String POST = "\'"; public MysqlFieldChar(String fieldName, Properties properties) throws MissingRequiredParameterException { super(fieldName, properties); } /** * @see AbstractField#render */ protected String doRender(Object value) throws FieldRenderException { if ((value == null) || ("".equals(value))) {return getDefaulNullValue();} try { //get value String strValue = ((String)value); //render return PRE + ((String)value).replaceAll("\"", "\\\\\"").replaceAll("'", "\\\\'") + POST; } catch (ClassCastException e) { throw new FieldRenderException(this, value, "not an string", e); } catch (Exception e) { throw new FieldRenderException(this, value, "generic error", e); } } protected HashMap<String, String> requiredParameterList() { return null; } protected HashMap<String, String> optionalParameterList() { return null; } } --- NEW FILE: GrammarFactory.java --- /* Copyright (C) 2004 Davide Consonni <dco...@en...> 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 */ package net.sf.csv2sql.grammars.mysql; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Hashtable; import java.util.Properties; import net.sf.csv2sql.grammars.AbstractField; import net.sf.csv2sql.grammars.AbstractGrammarFactory; import net.sf.csv2sql.grammars.exceptions.GrammarFactoryException; /** * @see net.sf.csv2sql.grammars.AbstractGrammarFactory AbstractGrammarFactory * @author <a href="mailto:dco...@en...">Davide Consonni</a> */ public final class GrammarFactory extends AbstractGrammarFactory { public static final Hashtable<String, String> mapping = new Hashtable<String, String>(); static { //strings mapping.put("VARCHAR", "net.sf.csv2sql.grammars.mysql.MysqlFieldChar"); mapping.put("CHAR", "net.sf.csv2sql.grammars.mysql.MysqlFieldChar"); //numbers mapping.put("BIT", "net.sf.csv2sql.grammars.mysql.MysqlFieldBit"); mapping.put("TINYINT", "net.sf.csv2sql.grammars.mysql.MysqlFieldTinyint"); mapping.put("BOOL", "net.sf.csv2sql.grammars.mysql.MysqlFieldBit"); mapping.put("BOOLEAN", "net.sf.csv2sql.grammars.mysql.MysqlFieldBit"); mapping.put("SMALLINT", "net.sf.csv2sql.grammars.mysql.MysqlFieldSmallint"); mapping.put("MEDIUMINT", "net.sf.csv2sql.grammars.mysql.MysqlFieldMediumint"); mapping.put("INT", "net.sf.csv2sql.grammars.mysql.MysqlFieldInt"); mapping.put("INTEGER", "net.sf.csv2sql.grammars.mysql.MysqlFieldInt"); mapping.put("BIGINT", "net.sf.csv2sql.grammars.mysql.MysqlFieldBigint"); mapping.put("FLOAT", "net.sf.csv2sql.grammars.mysql.MysqlFieldFloat"); mapping.put("DOUBLE", "net.sf.csv2sql.grammars.mysql.MysqlFieldDouble"); mapping.put("REAL", "net.sf.csv2sql.grammars.mysql.MysqlFieldDouble"); mapping.put("DECIMAL", "net.sf.csv2sql.grammars.mysql.MysqlFieldDouble"); mapping.put("DEC", "net.sf.csv2sql.grammars.mysql.MysqlFieldDouble"); mapping.put("NUMERIC", "net.sf.csv2sql.grammars.mysql.MysqlFieldDouble"); mapping.put("FIXED", "net.sf.csv2sql.grammars.mysql.MysqlFieldDouble"); //datetime mapping.put("DATE", "net.sf.csv2sql.grammars.mysql.MysqlFieldDate"); } public AbstractField createField(String type, String name, Properties prop) throws GrammarFactoryException { AbstractField field = null; try { String className = (String)mapping.get(type.toUpperCase()); if (className==null || "".equals(className)) { throw new ClassNotFoundException("datatype not found in mapping"); } Constructor c = Class.forName(className). getConstructor(new Class[] { String.class, Properties.class }); Object o = c.newInstance(new Object[] {name, prop }); field = (AbstractField)o; } catch (ClassNotFoundException e) { throw new GrammarFactoryException("cannot create field. type: "+type+", name: "+name+")", e.getException()); } catch (NoSuchMethodException e) { throw new GrammarFactoryException("cannot create field. type: "+type+", name: "+name+")", e.getCause()); } catch (InstantiationException e) { throw new GrammarFactoryException("cannot create field. type: "+type+", name: "+name+")", e.getCause()); } catch (IllegalAccessException e) { throw new GrammarFactoryException("cannot create field. type: "+type+", name: "+name+")", e.getCause()); } catch (InvocationTargetException e) { throw new GrammarFactoryException("cannot create field. type: "+type+", name: "+name+")", e.getCause()); } if (field==null) { throw new GrammarFactoryException("field type ["+type+"] doesn't exist. (field name: "+name+")", null); } else { return field; } } } |