001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (C) 2012 Paul Ferraro 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package net.sf.hajdbc.dialect.derby; 019 020import net.sf.hajdbc.IdentityColumnSupport; 021import net.sf.hajdbc.SequenceSupport; 022import net.sf.hajdbc.dialect.StandardDialect; 023 024/** 025 * Dialect for <a href="http://db.apache.org/derby">Apache Derby</a>. 026 * 027 * @author Paul Ferraro 028 * @since 1.1 029 */ 030@SuppressWarnings("nls") 031public class DerbyDialect extends StandardDialect 032{ 033 /** 034 * {@inheritDoc} 035 * 036 * @see net.sf.hajdbc.dialect.StandardDialect#getIdentityColumnSupport() 037 */ 038 @Override 039 public IdentityColumnSupport getIdentityColumnSupport() 040 { 041 return this; 042 } 043 044 /** 045 * {@inheritDoc} 046 * 047 * @see net.sf.hajdbc.dialect.StandardDialect#getSequenceSupport() 048 */ 049 @Override 050 public SequenceSupport getSequenceSupport() 051 { 052 // Sequence support was added to 10.6.1.0 053 return this.meetsRequirement(10, 6) ? this : null; 054 } 055 056 /** 057 * {@inheritDoc} 058 * 059 * @see net.sf.hajdbc.dialect.StandardDialect#vendorPattern() 060 */ 061 @Override 062 protected String vendorPattern() 063 { 064 return "derby"; 065 } 066 067 /** 068 * @see net.sf.hajdbc.dialect.StandardDialect#executeFunctionFormat() 069 */ 070 @Override 071 protected String executeFunctionFormat() 072 { 073 return "VALUES {0}"; 074 } 075 076 /** 077 * Deferrability clause is not supported. 078 * 079 * @see net.sf.hajdbc.dialect.StandardDialect#createForeignKeyConstraintFormat() 080 */ 081 @Override 082 protected String createForeignKeyConstraintFormat() 083 { 084 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}"; 085 } 086 087 /** 088 * @see net.sf.hajdbc.dialect.StandardDialect#currentDatePattern() 089 */ 090 @Override 091 protected String currentDatePattern() 092 { 093 return super.currentDatePattern() + "|(?<=\\W)CURRENT\\s+DATE(?=\\W)"; 094 } 095 096 /** 097 * @see net.sf.hajdbc.dialect.StandardDialect#currentTimePattern() 098 */ 099 @Override 100 protected String currentTimePattern() 101 { 102 return super.currentTimePattern() + "|(?<=\\W)CURRENT\\s+TIME(?=\\W)"; 103 } 104 105 /** 106 * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampPattern() 107 */ 108 @Override 109 protected String currentTimestampPattern() 110 { 111 return super.currentTimestampPattern() + "|(?<=\\W)CURRENT\\s+TIMESTAMP(?=\\W)"; 112 } 113 114 /** 115 * @see net.sf.hajdbc.dialect.StandardDialect#dateLiteralFormat() 116 */ 117 @Override 118 protected String dateLiteralFormat() 119 { 120 return "DATE(''{0}'')"; 121 } 122 123 /** 124 * @see net.sf.hajdbc.dialect.StandardDialect#timeLiteralFormat() 125 */ 126 @Override 127 protected String timeLiteralFormat() 128 { 129 return "TIME(''{0}'')"; 130 } 131 132 /** 133 * @see net.sf.hajdbc.dialect.StandardDialect#timestampLiteralFormat() 134 */ 135 @Override 136 protected String timestampLiteralFormat() 137 { 138 return "TIMESTAMP(''{0}'')"; 139 } 140}