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 <a href="http://db.apache.org/derby">Apache Derby</a>.
032 * 
033 * @author  Paul Ferraro
034 * @since   1.1
035 */
036@SuppressWarnings("nls")
037public class DerbyDialect extends StandardDialect
038{
039        /**
040         * @see net.sf.hajdbc.dialect.StandardDialect#executeFunctionFormat()
041         */
042        @Override
043        protected String executeFunctionFormat()
044        {
045                return "VALUES {0}";
046        }
047
048        /**
049         * @see net.sf.hajdbc.dialect.StandardDialect#parseSequence(java.lang.String)
050         */
051        @Override
052        public String parseSequence(String sql)
053        {
054                return null;
055        }
056        
057        /**
058         * @see net.sf.hajdbc.dialect.StandardDialect#getSequences(java.sql.DatabaseMetaData)
059         */
060        @Override
061        public Collection<QualifiedName> getSequences(DatabaseMetaData metaData) throws SQLException
062        {
063                return Collections.emptyList();
064        }
065
066        /**
067         * Deferrability clause is not supported.
068         * @see net.sf.hajdbc.dialect.StandardDialect#createForeignKeyConstraintFormat()
069         */
070        @Override
071        protected String createForeignKeyConstraintFormat()
072        {
073                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}";
074        }
075
076        /**
077         * @see net.sf.hajdbc.dialect.StandardDialect#currentDatePattern()
078         */
079        @Override
080        protected String currentDatePattern()
081        {
082                return super.currentDatePattern() + "|(?<=\\W)CURRENT\\s+DATE(?=\\W)";
083        }
084
085        /**
086         * @see net.sf.hajdbc.dialect.StandardDialect#currentTimePattern()
087         */
088        @Override
089        protected String currentTimePattern()
090        {
091                return super.currentTimePattern() + "|(?<=\\W)CURRENT\\s+TIME(?=\\W)";
092        }
093
094        /**
095         * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampPattern()
096         */
097        @Override
098        protected String currentTimestampPattern()
099        {
100                return super.currentTimestampPattern() + "|(?<=\\W)CURRENT\\s+TIMESTAMP(?=\\W)";
101        }
102
103        /**
104         * @see net.sf.hajdbc.dialect.StandardDialect#dateLiteralFormat()
105         */
106        @Override
107        protected String dateLiteralFormat()
108        {
109                return "DATE(''{0}'')";
110        }
111
112        /**
113         * @see net.sf.hajdbc.dialect.StandardDialect#timeLiteralFormat()
114         */
115        @Override
116        protected String timeLiteralFormat()
117        {
118                return "TIME(''{0}'')";
119        }
120
121        /**
122         * @see net.sf.hajdbc.dialect.StandardDialect#timestampLiteralFormat()
123         */
124        @Override
125        protected String timestampLiteralFormat()
126        {
127                return "TIMESTAMP(''{0}'')";
128        }
129}