Source Code Cross Referenced for DatabaseTestCase.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » test » 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 JDBC Connection Pool » jTDS » net.sourceforge.jtds.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jtds.test;
002:
003:        import java.sql.*;
004:        import java.util.Map;
005:        import java.math.BigDecimal;
006:
007:        public abstract class DatabaseTestCase extends TestBase {
008:            private static Map typemap = null;
009:
010:            public DatabaseTestCase(String name) {
011:                super (name);
012:            }
013:
014:            protected void dropTable(String tableName) throws SQLException {
015:                String sobName = "sysobjects";
016:                String tableLike = tableName;
017:
018:                if (tableName.startsWith("#")) {
019:                    sobName = "tempdb.dbo.sysobjects";
020:                    tableLike = tableName + "%";
021:                }
022:
023:                Statement stmt = con.createStatement();
024:                stmt.executeUpdate("if exists (select * from " + sobName
025:                        + " where name like '" + tableLike
026:                        + "' and type = 'U') " + "drop table " + tableName);
027:                stmt.close();
028:            }
029:
030:            protected void dropProcedure(String procname) throws SQLException {
031:                Statement stmt = con.createStatement();
032:                dropProcedure(stmt, procname);
033:                stmt.close();
034:            }
035:
036:            protected void dropProcedure(Statement stmt, String procname)
037:                    throws SQLException {
038:                String sobName = "sysobjects";
039:                if (procname.startsWith("#")) {
040:                    sobName = "tempdb.dbo.sysobjects";
041:                }
042:                stmt.executeUpdate("if exists (select * from " + sobName
043:                        + " where name like '" + procname
044:                        + "%' and type = 'P') " + "drop procedure " + procname);
045:            }
046:
047:            protected void dropFunction(String procname) throws SQLException {
048:                String sobName = "sysobjects";
049:                Statement stmt = con.createStatement();
050:                stmt.executeUpdate("if exists (select * from " + sobName
051:                        + " where name like '" + procname
052:                        + "%' and type = 'FN') " + "drop function " + procname);
053:                stmt.close();
054:            }
055:
056:            // return -1 if a1<a2, 0 if a1==a2, 1 if a1>a2
057:            static int compareBytes(byte a1[], byte a2[]) {
058:                if (a1 == a2) {
059:                    return 0;
060:                }
061:
062:                if (a1 == null) {
063:                    return -1;
064:                }
065:
066:                if (a2 == null) {
067:                    return 1;
068:                }
069:
070:                int length = (a1.length < a2.length ? a1.length : a2.length);
071:
072:                for (int i = 0; i < length; i++) {
073:                    if (a1[i] != a2[i]) {
074:                        return ((a1[i] & 0xff) > (a2[i] & 0xff) ? 1 : -1);
075:                    }
076:                }
077:
078:                if (a1.length == a2.length) {
079:                    return 0;
080:                }
081:
082:                if (a1.length < a2.length) {
083:                    return -1;
084:                }
085:
086:                return 1;
087:            }
088:
089:            protected static Map getTypemap() {
090:                if (typemap != null) {
091:                    return typemap;
092:                }
093:
094:                Map map = new java.util.HashMap(15);
095:                map.put(BigDecimal.class, new Integer(java.sql.Types.DECIMAL));
096:                map.put(Boolean.class, new Integer(java.sql.Types.BIT));
097:                map.put(Byte.class, new Integer(java.sql.Types.TINYINT));
098:                map.put(byte[].class, new Integer(java.sql.Types.VARBINARY));
099:                map.put(java.sql.Date.class, new Integer(java.sql.Types.DATE));
100:                map.put(double.class, new Integer(java.sql.Types.DOUBLE));
101:                map.put(Double.class, new Integer(java.sql.Types.DOUBLE));
102:                map.put(float.class, new Integer(java.sql.Types.REAL));
103:                map.put(Float.class, new Integer(java.sql.Types.REAL));
104:                map.put(Integer.class, new Integer(java.sql.Types.INTEGER));
105:                map.put(Long.class, new Integer(java.sql.Types.NUMERIC));
106:                map.put(Short.class, new Integer(java.sql.Types.SMALLINT));
107:                map.put(String.class, new Integer(java.sql.Types.VARCHAR));
108:                map.put(java.sql.Timestamp.class, new Integer(
109:                        java.sql.Types.TIMESTAMP));
110:
111:                typemap = map;
112:                return typemap;
113:            }
114:
115:            protected static int getType(Object o) throws SQLException {
116:                if (o == null) {
117:                    throw new SQLException(
118:                            "You must specify a type for a null parameter");
119:                }
120:
121:                Map map = getTypemap();
122:                Object ot = map.get(o.getClass());
123:
124:                if (ot == null) {
125:                    throw new SQLException(
126:                            "Support for this type is not implemented");
127:                }
128:
129:                return ((Integer) ot).intValue();
130:            }
131:
132:            protected String getLongString(int length) {
133:                StringBuffer result = new StringBuffer(length);
134:
135:                for (int i = 0; i < length; i++) {
136:                    result.append('a');
137:                }
138:
139:                return result.toString();
140:            }
141:
142:            protected String getLongString(char ch) {
143:                StringBuffer str255 = new StringBuffer(255);
144:
145:                for (int i = 0; i < 255; i++) {
146:                    str255.append(ch);
147:                }
148:
149:                return str255.toString();
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.