001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jdbc;
030:
031: import com.caucho.util.Log;
032:
033: import javax.sql.DataSource;
034: import java.sql.Types;
035: import java.util.logging.Logger;
036:
037: /**
038: * Metadata for the microsoft SQL server database.
039: */
040: public class SqlServerMetaData extends GenericMetaData {
041: private static final Logger log = Log.open(SqlServerMetaData.class);
042:
043: protected SqlServerMetaData(DataSource ds) {
044: super (ds);
045: }
046:
047: /**
048: * Returns true if identity is supported.
049: */
050: public boolean supportsIdentity() {
051: return true;
052: }
053:
054: /**
055: * Returns the identity property
056: */
057: public String createIdentitySQL(String sqlType) {
058: return " uniqueidentifier NOT NULL DEFAULT(NEWID())";
059: }
060:
061: public String getCreateColumnSQL(int sqlType, int length,
062: int precision, int scale) {
063: String type = null;
064:
065: switch (sqlType) {
066: case Types.BOOLEAN:
067: type = getCreateColumnSQLImpl(Types.BIT, length, precision,
068: scale);
069: break;
070:
071: case Types.TINYINT:
072: type = getCreateColumnSQLImpl(Types.TINYINT, length,
073: precision, scale);
074: break;
075:
076: case Types.DATE:
077: type = getCreateColumnSQLImpl(sqlType, length, precision,
078: scale);
079: if (type == null)
080: type = getCreateColumnSQLImpl(Types.TIMESTAMP, length,
081: precision, scale);
082: break;
083:
084: case Types.TIME:
085: type = getCreateColumnSQLImpl(sqlType, length, precision,
086: scale);
087: if (type == null)
088: type = getCreateColumnSQLImpl(Types.TIMESTAMP, length,
089: precision, scale);
090: break;
091:
092: case Types.DOUBLE:
093: type = getCreateColumnSQLImpl(Types.FLOAT, length,
094: precision, scale);
095: break;
096:
097: case Types.NUMERIC:
098: type = getCreateColumnSQLImpl(Types.NUMERIC, length,
099: precision, scale);
100: break;
101:
102: default:
103: type = getCreateColumnSQLImpl(sqlType, length, precision,
104: scale);
105: break;
106: }
107:
108: if (type == null)
109: type = getDefaultCreateTableSQL(sqlType, length, precision,
110: scale);
111:
112: return type;
113: }
114:
115: public String generateBoolean(String term) {
116: return term + "= 1";
117: }
118: }
|