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 */
021package net.sf.hajdbc.dialect;
022
023import java.sql.DatabaseMetaData;
024import java.sql.SQLException;
025import java.util.Collection;
026import java.util.Collections;
027
028import net.sf.hajdbc.QualifiedName;
029
030/**
031 * Dialect for Sybase (commercial).
032 * @author Paul Ferraro
033 */
034@SuppressWarnings("nls")
035public class SybaseDialect extends StandardDialect
036{
037        /**
038         * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampFunction()
039         */
040        @Override
041        protected String currentTimestampFunction()
042        {
043                return "GETDATE()";
044        }
045
046        /**
047         * @see net.sf.hajdbc.dialect.StandardDialect#truncateTableFormat()
048         */
049        @Override
050        protected String truncateTableFormat()
051        {
052                return "TRUNCATE TABLE {0}";
053        }
054        
055        /**
056         * Deferrability clause is not supported.
057         * @see net.sf.hajdbc.dialect.StandardDialect#createForeignKeyConstraintFormat()
058         */
059        @Override
060        protected String createForeignKeyConstraintFormat()
061        {
062                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}";
063        }
064
065        /**
066         * Sybase does not support sequences.
067         * @see net.sf.hajdbc.dialect.StandardDialect#parseSequence(java.lang.String)
068         */
069        @Override
070        public String parseSequence(String sql)
071        {
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(DatabaseMetaData metaData) throws SQLException
080        {
081                return Collections.emptyList();
082        }
083
084        /**
085         * @see net.sf.hajdbc.dialect.StandardDialect#currentDatePattern()
086         */
087        @Override
088        protected String currentDatePattern()
089        {
090                return "(?<=\\W)CURRENT\\s+DATE(?=\\W)|(?<=\\W)TODAY\\s*\\(\\s*\\*\\s*\\)";
091        }
092
093        /**
094         * @see net.sf.hajdbc.dialect.StandardDialect#currentTimePattern()
095         */
096        @Override
097        protected String currentTimePattern()
098        {
099                return "(?<=\\W)CURRENT\\s+TIME(?=\\W)";
100        }
101
102        /**
103         * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampPattern()
104         */
105        @Override
106        protected String currentTimestampPattern()
107        {
108                return "(?<=\\W)CURRENT\\s+TIMESTAMP(?=\\W)|(?<=\\W)GETDATE\\s*\\(\\s*\\)|(?<=\\W)NOW\\s*\\(\\s*\\*\\s*\\)";
109        }
110
111        /**
112         * @see net.sf.hajdbc.dialect.StandardDialect#dateLiteralFormat()
113         */
114        @Override
115        protected String dateLiteralFormat()
116        {
117                return this.timestampLiteralFormat();
118        }
119
120        /**
121         * @see net.sf.hajdbc.dialect.StandardDialect#timeLiteralFormat()
122         */
123        @Override
124        protected String timeLiteralFormat()
125        {
126                return this.timestampLiteralFormat();
127        }
128
129        /**
130         * @see net.sf.hajdbc.dialect.StandardDialect#timestampLiteralFormat()
131         */
132        @Override
133        protected String timestampLiteralFormat()
134        {
135                return "''{0}''";
136        }
137        
138        /**
139         * @see net.sf.hajdbc.dialect.StandardDialect#randomPattern()
140         */
141        @Override
142        protected String randomPattern()
143        {
144                return "(?<=\\W)RAND\\s*\\(\\s*\\d*\\s*\\)";
145        }       
146}