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