Source Code Cross Referenced for tinySQLGlobals.java in  » Database-DBMS » TinySQL » com » sqlmagic » tinysql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » TinySQL » com.sqlmagic.tinysql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * tinySQLGlobals
003:         * 
004:         * $Author: $
005:         * $Date:  $
006:         * $Revision:  $
007:         *
008:         * Static class to hold global values.
009:         *
010:         * This library is free software; you can redistribute it and/or
011:         * modify it under the terms of the GNU Lesser General Public
012:         * License as published by the Free Software Foundation; either
013:         * version 2.1 of the License, or (at your option) any later version.
014:         *
015:         * This library is distributed in the hope that it will be useful,
016:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
017:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
018:         * Lesser General Public License for more details.
019:         *
020:         * You should have received a copy of the GNU Lesser General Public
021:         * License along with this library; if not, write to the Free Software
022:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
023:         *
024:         * Revision History;
025:         *
026:         * Written by Davis Swan in October, 2006.
027:         */
028:
029:        package com.sqlmagic.tinysql;
030:
031:        import java.io.*;
032:        import java.util.*;
033:        import java.text.*;
034:
035:        public class tinySQLGlobals {
036:            static String dataDir = (String) null;
037:            static Vector longColumnNames;
038:            static String fileSep = System.getProperty("file.separator");
039:            static String newLine = System.getProperty("line.separator");
040:            static Hashtable DB_INDEX = new Hashtable();
041:            static String VERSION = "2.26h";
042:            static boolean DEBUG = false;
043:            static boolean PARSER_DEBUG = false;
044:            static boolean WHERE_DEBUG = false;
045:            static boolean EX_DEBUG = false;
046:            static int longNamesInFileCount;
047:            static boolean debug = false;
048:
049:            public static void readLongNames(String inputDataDir) {
050:                String fullPath, longNameRecord;
051:                String[] fields;
052:                FieldTokenizer ft;
053:                File longColumnNameFile;
054:                dataDir = inputDataDir;
055:                BufferedReader longNameReader = (BufferedReader) null;
056:                fullPath = dataDir + fileSep + "TINYSQL_LONG_COLUMN_NAMES.dat";
057:                longColumnNames = new Vector();
058:                longColumnNameFile = new File(fullPath);
059:                if (longColumnNameFile.exists()) {
060:                    try {
061:                        longNameReader = new BufferedReader(new FileReader(
062:                                fullPath));
063:                        while ((longNameRecord = longNameReader.readLine()) != null) {
064:                            ft = new FieldTokenizer(longNameRecord, '|', false);
065:                            fields = ft.getFields();
066:                            longColumnNames.addElement(fields[0]);
067:                            longColumnNames.addElement(fields[1]);
068:                        }
069:                        longNameReader.close();
070:                        longNamesInFileCount = longColumnNames.size() / 2;
071:                        if (debug)
072:                            System.out.println("Long Names read: "
073:                                    + longNamesInFileCount);
074:                    } catch (Exception readEx) {
075:                        System.out.println("Reader exception "
076:                                + readEx.getMessage());
077:                        longNamesInFileCount = 0;
078:                    }
079:                }
080:            }
081:
082:            /*
083:             * Method to add a long column name to the global Vector.  Note that
084:             * the entries are keyed by the short column name so that there is always
085:             * one and only one short name for any long name.
086:             */
087:            public static String addLongName(String inputColumnName) {
088:                String shortColumnName, countString;
089:                countString = "0000"
090:                        + Integer.toString(longColumnNames.size() / 2);
091:                shortColumnName = "COL"
092:                        + countString.substring(countString.length() - 5);
093:                if (debug)
094:                    System.out.println("Add " + shortColumnName + "|"
095:                            + inputColumnName);
096:                longColumnNames.addElement(shortColumnName);
097:                longColumnNames.addElement(inputColumnName);
098:                return shortColumnName;
099:            }
100:
101:            /*
102:             * This method checks for the existence of a short column name for the
103:             * input name.  If one does not exist it is created.
104:             */
105:            public static String getShortName(String inputColumnName) {
106:                String shortColumnName = (String) null, longColumnName;
107:                int i;
108:                if (inputColumnName.length() < 12)
109:                    return inputColumnName;
110:                for (i = 0; i < longColumnNames.size(); i += 2) {
111:                    longColumnName = (String) longColumnNames.elementAt(i + 1);
112:                    if (longColumnName.equalsIgnoreCase(inputColumnName)) {
113:                        shortColumnName = (String) longColumnNames.elementAt(i);
114:                        if (debug)
115:                            System.out.println("Return " + shortColumnName);
116:                        return shortColumnName;
117:                    }
118:                }
119:                if (shortColumnName == (String) null) {
120:                    /*
121:                     *       A short name has not been set up for this long name yet. 
122:                     */
123:                    if (debug)
124:                        System.out.println("Generate short name for "
125:                                + inputColumnName);
126:                    return addLongName(inputColumnName);
127:                }
128:                return inputColumnName;
129:            }
130:
131:            /*
132:             * Get the long column name for the input short name.  
133:             */
134:            public static String getLongName(String inputColumnName) {
135:                String longColumnName, shortColumnName;
136:                int i;
137:                for (i = 0; i < longColumnNames.size(); i += 2) {
138:                    shortColumnName = (String) longColumnNames.elementAt(i);
139:                    if (shortColumnName.equalsIgnoreCase(inputColumnName)) {
140:                        longColumnName = (String) longColumnNames
141:                                .elementAt(i + 1);
142:                        if (debug)
143:                            System.out.println("Return " + longColumnName);
144:                        return longColumnName;
145:                    }
146:                }
147:                return inputColumnName;
148:            }
149:
150:            public static void writeLongNames() {
151:                FileWriter longNameWriter = (FileWriter) null;
152:                String fullPath, longColumnName, shortColumnName;
153:                int i;
154:                if (longColumnNames.size() > longNamesInFileCount * 2) {
155:                    /*
156:                     *       The file needs to be updated.
157:                     */
158:                    fullPath = dataDir + fileSep
159:                            + "TINYSQL_LONG_COLUMN_NAMES.dat";
160:                    try {
161:                        longNameWriter = new FileWriter(fullPath);
162:                        if (longNameWriter != (FileWriter) null) {
163:                            for (i = 0; i < longColumnNames.size(); i += 2) {
164:                                shortColumnName = (String) longColumnNames
165:                                        .elementAt(i);
166:                                longColumnName = (String) longColumnNames
167:                                        .elementAt(i + 1);
168:                                longNameWriter.write(shortColumnName + "|"
169:                                        + longColumnName + newLine);
170:                            }
171:                            longNameWriter.close();
172:                            longNamesInFileCount = longColumnNames.size() / 2;
173:                        } else {
174:                            System.out
175:                                    .println("Unable to update long column names.");
176:                        }
177:                    } catch (Exception writeEx) {
178:                        System.out.println("Write exception "
179:                                + writeEx.getMessage());
180:                    }
181:                }
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.