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