01: package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
02:
03: import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
04: import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
05:
06: /*
07: * Copyright (C) 2005 Rob Manning, Gerd Wagner
08: * manningr@users.sourceforge.net
09: *
10: * This library is free software; you can redistribute it and/or
11: * modify it under the terms of the GNU Lesser General Public
12: * License as published by the Free Software Foundation; either
13: * version 2.1 of the License, or (at your option) any later version.
14: *
15: * This library is distributed in the hope that it will be useful,
16: * but WITHOUT ANY WARRANTY; without even the implied warranty of
17: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18: * Lesser General Public License for more details.
19: *
20: * You should have received a copy of the GNU Lesser General Public
21: * License along with this library; if not, write to the Free Software
22: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: */
24:
25: public class DatabaseSpecificBooleanValue {
26:
27: private static final IBooleanValue[] _booleans = new IBooleanValue[] {
28: new SybaseBoolean(), new MSSQLServerBoolean() };
29:
30: public static String getBooleanValue(String orig,
31: ISQLDatabaseMetaData md) {
32: for (int i = 0; i < _booleans.length; i++) {
33: if (_booleans[i].productMatches(md)) {
34: return _booleans[i].getBooleanValue(orig);
35: }
36: }
37: return orig;
38: }
39:
40: private static interface IBooleanValue {
41: public boolean productMatches(ISQLDatabaseMetaData md);
42:
43: public String getBooleanValue(String originalValue);
44: }
45:
46: private static class SybaseBoolean implements IBooleanValue {
47:
48: public boolean productMatches(ISQLDatabaseMetaData md) {
49: return DialectFactory.isSyBase(md);
50: }
51:
52: public String getBooleanValue(String orig) {
53: String result = orig;
54: if ("false".equalsIgnoreCase(orig)) {
55: result = "0";
56: }
57: if ("true".equalsIgnoreCase(orig)) {
58: result = "1";
59: }
60: return result;
61: }
62: }
63:
64: private static class MSSQLServerBoolean extends SybaseBoolean {
65:
66: public boolean productMatches(ISQLDatabaseMetaData md) {
67: return DialectFactory.isMSSQLServer(md);
68: }
69:
70: }
71:
72: }
|