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.ResultSet; 025import java.sql.SQLException; 026import java.sql.Statement; 027import java.util.Collection; 028import java.util.LinkedList; 029import java.util.List; 030 031import net.sf.hajdbc.QualifiedName; 032 033/** 034 * Dialect for <a href="http://www.hsqldb.org">HSQLDB</a>. 035 * 036 * @author Paul Ferraro 037 * @since 1.1 038 */ 039@SuppressWarnings("nls") 040public class HSQLDBDialect extends StandardDialect 041{ 042 /** 043 * @see net.sf.hajdbc.dialect.StandardDialect#executeFunctionFormat() 044 */ 045 @Override 046 protected String executeFunctionFormat() 047 { 048 return "CALL {0}"; 049 } 050 051 /** 052 * @see net.sf.hajdbc.dialect.StandardDialect#getSequences(java.sql.DatabaseMetaData) 053 */ 054 @Override 055 public Collection<QualifiedName> getSequences(DatabaseMetaData metaData) throws SQLException 056 { 057 List<QualifiedName> sequenceList = new LinkedList<QualifiedName>(); 058 059 Statement statement = metaData.getConnection().createStatement(); 060 061 ResultSet resultSet = statement.executeQuery("SELECT SEQUENCE_SCHEMA, SEQUENCE_NAME FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES"); 062 063 while (resultSet.next()) 064 { 065 sequenceList.add(new QualifiedName(resultSet.getString(1), resultSet.getString(2))); 066 } 067 068 statement.close(); 069 070 return sequenceList; 071 } 072 073 /** 074 * Deferrability clause is not supported. 075 * @see net.sf.hajdbc.dialect.StandardDialect#createForeignKeyConstraintFormat() 076 */ 077 @Override 078 protected String createForeignKeyConstraintFormat() 079 { 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 { 089 return "(?<=\\W)CURRENT_DATE(?=\\W)|(?<=\\W)CURDATE\\s*\\(\\s*\\)"; 090 } 091 092 /** 093 * @see net.sf.hajdbc.dialect.StandardDialect#currentTimePattern() 094 */ 095 @Override 096 protected String currentTimePattern() 097 { 098 return "(?<=\\W)CURRENT_TIME(?=\\W)|(?<=\\W)CURTIME\\s*\\(\\s*\\)"; 099 } 100 101 /** 102 * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampPattern() 103 */ 104 @Override 105 protected String currentTimestampPattern() 106 { 107 return "(?<=\\W)CURRENT_TIMESTAMP(?=\\W)|(?<=\\W)NOW\\s*\\(\\s*\\)"; 108 } 109}