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.mysql.com/products/database/maxdb/">MySQL MaxDB</a>. 035 * @author Paul Ferraro 036 * @since 1.1 037 */ 038@SuppressWarnings("nls") 039public class MaxDBDialect extends StandardDialect 040{ 041 /** 042 * @see net.sf.hajdbc.dialect.StandardDialect#dummyTable() 043 */ 044 @Override 045 protected String dummyTable() 046 { 047 return "DUAL"; 048 } 049 050 /** 051 * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampFunction() 052 */ 053 @Override 054 protected String currentTimestampFunction() 055 { 056 return "SYSDATE"; 057 } 058 059 /** 060 * @see net.sf.hajdbc.dialect.StandardDialect#getSequences(java.sql.DatabaseMetaData) 061 */ 062 @Override 063 public Collection<QualifiedName> getSequences(DatabaseMetaData metaData) throws SQLException 064 { 065 List<QualifiedName> sequenceList = new LinkedList<QualifiedName>(); 066 067 Statement statement = metaData.getConnection().createStatement(); 068 069 ResultSet resultSet = statement.executeQuery("SELECT SEQUENCE_NAME FROM USER_SEQUENCES"); 070 071 while (resultSet.next()) 072 { 073 sequenceList.add(new QualifiedName(resultSet.getString(1))); 074 } 075 076 statement.close(); 077 078 return sequenceList; 079 } 080 081 /** 082 * @see net.sf.hajdbc.dialect.StandardDialect#parseInsertTable(java.lang.String) 083 */ 084 @Override 085 public String parseInsertTable(String sql) 086 { 087 return null; 088 } 089 090 /** 091 * @see net.sf.hajdbc.dialect.StandardDialect#truncateTableFormat() 092 */ 093 @Override 094 protected String truncateTableFormat() 095 { 096 return "TRUNCATE TABLE {0}"; 097 } 098 099 /** 100 * ON UPDATE and deferrability clauses are not supported. 101 * @see net.sf.hajdbc.dialect.StandardDialect#createForeignKeyConstraintFormat() 102 */ 103 @Override 104 protected String createForeignKeyConstraintFormat() 105 { 106 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}"; 107 } 108 109 /** 110 * @see net.sf.hajdbc.dialect.StandardDialect#sequencePattern() 111 */ 112 @Override 113 protected String sequencePattern() 114 { 115 return "'?(\\w+)'?\\.(?:CURR|NEXT)VAL"; 116 } 117 118 /** 119 * @see net.sf.hajdbc.dialect.StandardDialect#nextSequenceValueFormat() 120 */ 121 @Override 122 protected String nextSequenceValueFormat() 123 { 124 return "{0}.NEXTVAL"; 125 } 126}