KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jdbc > SqlServerMetaData


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jdbc;
30
31 import com.caucho.util.Log;
32
33 import javax.sql.DataSource JavaDoc;
34 import java.sql.Types JavaDoc;
35 import java.util.logging.Logger JavaDoc;
36
37 /**
38  * Metadata for the microsoft SQL server database.
39  */

40 public class SqlServerMetaData extends JdbcMetaData {
41   private static final Logger JavaDoc log = Log.open(SqlServerMetaData.class);
42
43   protected SqlServerMetaData(DataSource JavaDoc ds)
44   {
45     super(ds);
46   }
47
48   /**
49    * Returns true if identity is supported.
50    */

51   public boolean supportsIdentity()
52   {
53     return true;
54   }
55
56     /**
57    * New version to Return SQL for the table with the given
58    * SQL type. Takes, length, precision and scale.
59    */

60   public String JavaDoc getCreateColumnSQL(int sqlType, int length, int precision, int scale) {
61        String JavaDoc type = null;
62
63     switch (sqlType) {
64     case Types.BOOLEAN:
65         type = getCreateColumnSQLImpl(Types.BIT, length, precision, scale);
66       break;
67
68     case Types.TINYINT:
69         type = getCreateColumnSQLImpl(Types.TINYINT, length, precision, scale);
70       break;
71
72     case Types.DATE:
73       type = getCreateColumnSQLImpl(sqlType, length, precision, scale);
74       if (type == null)
75     type = getCreateColumnSQLImpl(Types.TIMESTAMP, length, precision, scale);
76       break;
77
78     case Types.TIME:
79       type = getCreateColumnSQLImpl(sqlType, length, precision, scale);
80       if (type == null)
81     type = getCreateColumnSQLImpl(Types.TIMESTAMP, length, precision, scale);
82       break;
83
84     case Types.DOUBLE:
85       type = getCreateColumnSQLImpl(Types.FLOAT, length, precision, scale);
86       break;
87
88     case Types.NUMERIC:
89         type = getCreateColumnSQLImpl(Types.NUMERIC, length, precision, scale);
90         break;
91
92     default:
93       type = getCreateColumnSQLImpl(sqlType, length, precision, scale);
94       break;
95     }
96
97     if (type == null)
98       type = getDefaultCreateTableSQL(sqlType, length, precision, scale);
99
100     return type;
101   }
102
103   /**
104    * Returns the identity property
105    */

106   public String JavaDoc createIdentitySQL(String JavaDoc sqlType)
107   {
108     return " uniqueidentifier NOT NULL DEFAULT(NEWID())";
109   }
110
111   public String JavaDoc generateBoolean(String JavaDoc term)
112   {
113     return term + "= 1";
114   }
115 }
116
Popular Tags