001: /*
002: * HA-JDBC: High-Availability JDBC
003: * Copyright (c) 2004-2007 Paul Ferraro
004: *
005: * This library is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as published by the
007: * Free Software Foundation; either version 2.1 of the License, or (at your
008: * option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
013: * for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software Foundation,
017: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Contact: ferraro@users.sourceforge.net
020: */
021: package net.sf.hajdbc.dialect;
022:
023: import java.sql.DatabaseMetaData;
024: import java.sql.SQLException;
025: import java.util.Collection;
026: import java.util.Collections;
027:
028: import net.sf.hajdbc.ColumnProperties;
029: import net.sf.hajdbc.QualifiedName;
030:
031: /**
032: * Dialect for Sybase (commercial).
033: * @author Paul Ferraro
034: */
035: @SuppressWarnings("nls")
036: public class SybaseDialect extends StandardDialect {
037: /**
038: * @see net.sf.hajdbc.dialect.StandardDialect#truncateTableFormat()
039: */
040: @Override
041: protected String truncateTableFormat() {
042: return "TRUNCATE TABLE {0}";
043: }
044:
045: /**
046: * Deferrability clause is not supported.
047: * @see net.sf.hajdbc.dialect.StandardDialect#createForeignKeyConstraintFormat()
048: */
049: @Override
050: protected String createForeignKeyConstraintFormat() {
051: return "ALTER TABLE {1} ADD CONSTRAINT {0} FOREIGN KEY ({2}) REFERENCES {3} ({4}) ON DELETE {5,choice,0#CASCADE|1#RESTRICT|2#SET NULL|3#NO ACTION|4#SET DEFAULT} ON UPDATE {6,choice,0#CASCADE|1#RESTRICT|2#SET NULL|3#NO ACTION|4#SET DEFAULT}";
052: }
053:
054: /**
055: * @see net.sf.hajdbc.dialect.StandardDialect#isIdentity(net.sf.hajdbc.ColumnProperties)
056: */
057: @Override
058: public boolean isIdentity(ColumnProperties properties) {
059: String defaultValue = properties.getDefaultValue();
060:
061: return (defaultValue != null)
062: && (defaultValue.equalsIgnoreCase("AUTOINCREMENT") || defaultValue
063: .equalsIgnoreCase("IDENTITY"));
064: }
065:
066: /**
067: * Sybase does not support sequences.
068: * @see net.sf.hajdbc.dialect.StandardDialect#parseSequence(java.lang.String)
069: */
070: @Override
071: public String parseSequence(String sql) {
072: return null;
073: }
074:
075: /**
076: * @see net.sf.hajdbc.dialect.StandardDialect#getSequences(java.sql.DatabaseMetaData)
077: */
078: @Override
079: public Collection<QualifiedName> getSequences(
080: DatabaseMetaData metaData) throws SQLException {
081: return Collections.emptyList();
082: }
083:
084: /**
085: * @see net.sf.hajdbc.dialect.StandardDialect#currentDatePattern()
086: */
087: @Override
088: protected String currentDatePattern() {
089: return "(?<=\\W)CURRENT\\s+DATE(?=\\W)|(?<=\\W)TODAY\\s*\\(\\s*\\*\\s*\\)";
090: }
091:
092: /**
093: * @see net.sf.hajdbc.dialect.StandardDialect#currentTimePattern()
094: */
095: @Override
096: protected String currentTimePattern() {
097: return "(?<=\\W)CURRENT\\s+TIME(?=\\W)";
098: }
099:
100: /**
101: * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampPattern()
102: */
103: @Override
104: protected String currentTimestampPattern() {
105: return "(?<=\\W)CURRENT\\s+TIMESTAMP(?=\\W)|(?<=\\W)GETDATE\\s*\\(\\s*\\)|(?<=\\W)NOW\\s*\\(\\s*\\*\\s*\\)";
106: }
107:
108: /**
109: * @see net.sf.hajdbc.dialect.StandardDialect#dateLiteralFormat()
110: */
111: @Override
112: protected String dateLiteralFormat() {
113: return this .timestampLiteralFormat();
114: }
115:
116: /**
117: * @see net.sf.hajdbc.dialect.StandardDialect#timeLiteralFormat()
118: */
119: @Override
120: protected String timeLiteralFormat() {
121: return this .timestampLiteralFormat();
122: }
123:
124: /**
125: * @see net.sf.hajdbc.dialect.StandardDialect#timestampLiteralFormat()
126: */
127: @Override
128: protected String timestampLiteralFormat() {
129: return "''{0}''";
130: }
131:
132: /**
133: * @see net.sf.hajdbc.dialect.StandardDialect#randomPattern()
134: */
135: @Override
136: protected String randomPattern() {
137: return "(?<=\\W)RAND\\s*\\(\\s*\\d*\\s*\\)";
138: }
139: }
|