Thread: [Squirrel-sql-commits] sql12/fw/src/net/sourceforge/squirrel_sql/fw/dialects GenericDialectExt.jav
A Java SQL client for any JDBC compliant database
Brought to you by:
colbell,
gerdwagner
From: Rob M. <man...@us...> - 2008-06-19 22:58:36
|
Update of /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/dialects In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv16571/fw/src/net/sourceforge/squirrel_sql/fw/dialects Modified Files: DialectFactory.java Added Files: GenericDialectExt.java Removed Files: UnknownDialectException.java Log Message: Added support for SQLite by introducing a GenericDialect, which is a minimal bare-bones dialect that should be usable for databases that we don't yet have full-featured dialects for. Also, since SQLite JDBC (as well as SQLite itself) doesn't support column type information like most database drivers, a new backup mechanism that keys off of Types.NULL to reverse map to the code using the column type name was added. So, if a ResultSetMetaData reports a column type to be Types.NULL, but the column type name is, say, integer, then the type will be converted to Types.INTEGER. If the type name doesn't correspond to a Type by name, then the type will be converted to Types.VARCHAR. In this fashion, SQLite table data can be edited using both the contents tab as well as SQL results tab. Index: DialectFactory.java =================================================================== RCS file: /cvsroot/squirrel-sql/sql12/fw/src/net/sourceforge/squirrel_sql/fw/dialects/DialectFactory.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DialectFactory.java 9 Mar 2008 23:57:53 -0000 1.12 --- DialectFactory.java 19 Jun 2008 22:58:29 -0000 1.13 *************** *** 21,25 **** import java.io.PrintWriter; import java.io.StringWriter; - import java.sql.SQLException; import java.util.Arrays; import java.util.Collection; --- 21,24 ---- *************** *** 70,73 **** --- 69,74 ---- private static final FrontBaseDialectExt frontbaseDialect = new FrontBaseDialectExt(); + private static final GenericDialectExt genericDialect = new GenericDialectExt(); + private static final HADBDialectExt hadbDialect = new HADBDialectExt(); *************** *** 254,273 **** */ public static DialectType getDialectType(ISQLDatabaseMetaData md) { ! HibernateDialect dialect = null; ! try { ! dialect = getDialect(md); ! } catch (UnknownDialectException e) { ! try { ! s_log.error("getDialectType: Unknown dialect for product=" ! + md.getDatabaseProductName() + " version=" ! + md.getDatabaseProductVersion()+" - "+e.getMessage(), e); ! } catch (SQLException ex) { ! s_log.error("getDialectType: unable to get database " ! + "product/version: " + ex.getMessage(), ex); ! } ! } ! if (dialect == null) { ! return DialectType.GENERIC; ! } return dialect.getDialectType(); } --- 255,259 ---- */ public static DialectType getDialectType(ISQLDatabaseMetaData md) { ! HibernateDialect dialect = getDialect(md); return dialect.getDialectType(); } *************** *** 327,405 **** */ public static HibernateDialect getDialect(ISQLDatabaseMetaData md) - throws UnknownDialectException { ! if (isAxion(md)) { ! return axionDialect; ! } ! if (isDaffodil(md)) { ! return daffodilDialect; ! } ! if (isDB2(md)) { ! return db2Dialect; ! } ! if (isDerby(md)) { ! return derbyDialect; ! } ! if (isFirebird(md)) { ! return firebirdDialect; ! } ! if (isFrontBase(md)) { ! return frontbaseDialect; ! } ! if (isHADB(md)) { ! return hadbDialect; ! } ! if (isH2(md)) { ! return h2Dialect; ! } ! if (isHSQL(md)) { ! return hsqlDialect; ! } ! if (isInformix(md)) { ! return informixDialect; ! } ! if (isIngres(md)) { ! return ingresDialect; ! } ! if (isInterbase(md)) { ! return ingresDialect; ! } ! if (isMaxDB(md)) { ! return maxDbDialect; ! } ! if (isMcKoi(md)) { ! return mckoiDialect; ! } ! if (isMySQL(md)) { ! return mysqlDialect; ! } ! if (isMySQL5(md)) { ! return mysql5Dialect; ! } ! if (isMSSQLServer(md)) { ! return sqlserverDialect; ! } ! if (isOracle(md)) { ! return oracle9iDialect; ! } ! if (isPointbase(md)) { ! return pointbaseDialect; ! } ! if (isPostgreSQL(md)) { ! return postgreSQLDialect; ! } ! if (isProgress(md)) { ! return progressDialect; ! } ! if (isSyBase(md)) { ! return sybaseDialect; ! } ! if (isTimesTen(md)) { ! return timestenDialect; ! } ! if (isIntersystemsCacheDialectExt(md)) { ! return intersystemsCacheDialectExt; ! } ! throw new UnknownDialectException(); } --- 313,344 ---- */ public static HibernateDialect getDialect(ISQLDatabaseMetaData md) { ! if (isAxion(md)) { return axionDialect; } ! if (isDaffodil(md)) { return daffodilDialect; } ! if (isDB2(md)) { return db2Dialect; } ! if (isDerby(md)) { return derbyDialect; } ! if (isFirebird(md)) { return firebirdDialect; } ! if (isFrontBase(md)) { return frontbaseDialect; } ! if (isHADB(md)) { return hadbDialect; } ! if (isH2(md)) { return h2Dialect; } ! if (isHSQL(md)) { return hsqlDialect; } ! if (isInformix(md)) { return informixDialect; } ! if (isIngres(md)) { return ingresDialect; } ! if (isInterbase(md)) { return ingresDialect; } ! if (isMaxDB(md)) { return maxDbDialect; } ! if (isMcKoi(md)) { return mckoiDialect; } ! if (isMySQL(md)) { return mysqlDialect; } ! if (isMySQL5(md)) { return mysql5Dialect; } ! if (isMSSQLServer(md)) { return sqlserverDialect; } ! if (isOracle(md)) { return oracle9iDialect; } ! if (isPointbase(md)) { return pointbaseDialect; } ! if (isPostgreSQL(md)) { return postgreSQLDialect; } ! if (isProgress(md)) { return progressDialect; } ! if (isSyBase(md)) { return sybaseDialect; } ! if (isTimesTen(md)) { return timestenDialect; } ! if (isIntersystemsCacheDialectExt(md)) { return intersystemsCacheDialectExt; } ! // GenericDialect must be last, since it will claim that it supports any product/version. That is also ! // why there is no isGenericDialect - it would always return true if there was one, making it useless. ! return genericDialect; } *************** *** 415,424 **** result = showDialectDialog(parent, sessionType); } else { ! try { ! result = getDialect(md); ! } catch (UnknownDialectException e) { ! // Failed to detect the dialect that should be used. Ask the user. ! result = showDialectDialog(parent, sessionType); ! } } return result; --- 354,358 ---- result = showDialectDialog(parent, sessionType); } else { ! result = getDialect(md); } return result; --- NEW FILE: GenericDialectExt.java --- /* * Copyright (C) 2008 Rob Manning * man...@us... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.sourceforge.squirrel_sql.fw.dialects; import java.sql.Types; import org.hibernate.HibernateException; import org.hibernate.dialect.Dialect; public class GenericDialectExt extends CommonHibernateDialect { private class GenericDialectHelper extends Dialect { public GenericDialectHelper() { registerColumnType(Types.BIGINT, "integer"); registerColumnType(Types.CHAR, "char($l)"); registerColumnType(Types.DATE, "date"); registerColumnType(Types.INTEGER, "integer"); registerColumnType(Types.LONGVARCHAR, "varchar($l)"); registerColumnType(Types.SMALLINT, "integer"); registerColumnType(Types.TIME, "time"); registerColumnType(Types.TIMESTAMP, "timestamp"); registerColumnType(Types.TINYINT, "integer"); registerColumnType(Types.VARCHAR, "varchar($l)"); } } /** extended hibernate dialect used in this wrapper */ private GenericDialectHelper _dialect = new GenericDialectHelper(); /** * @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getTypeName(int, int, int, int) */ @Override public String getTypeName(int code, int length, int precision, int scale) throws HibernateException { return _dialect.getTypeName(code, length, precision, scale); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getDisplayName() */ @Override public String getDisplayName() { return "Generic"; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getDialectType() */ @Override public DialectType getDialectType() { return DialectType.GENERIC; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#supportsProduct(java.lang.String, java.lang.String) */ @Override public boolean supportsProduct(String databaseProductName, String databaseProductVersion) { return true; } } --- UnknownDialectException.java DELETED --- |