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: import java.util.regex.Pattern;
031:
032: import net.sf.hajdbc.QualifiedName;
033:
034: /**
035: * Dialect for <a href="http://opensource.ingres.com/projects/ingres/">Ingres</a>.
036: *
037: * @author Paul Ferraro
038: */
039: @SuppressWarnings("nls")
040: public class IngresDialect extends StandardDialect {
041: private Pattern legacySequencePattern = Pattern.compile(
042: "'?(\\w+)'?\\.(?:(?:CURR)|(?:NEXT))VAL",
043: Pattern.CASE_INSENSITIVE);
044:
045: /**
046: * @see net.sf.hajdbc.dialect.StandardDialect#parseInsertTable(java.lang.String)
047: */
048: @Override
049: public String parseInsertTable(String sql) {
050: return null;
051: }
052:
053: /**
054: * @see net.sf.hajdbc.dialect.StandardDialect#getSequences(java.sql.DatabaseMetaData)
055: */
056: @Override
057: public Collection<QualifiedName> getSequences(
058: DatabaseMetaData metaData) throws SQLException {
059: List<QualifiedName> sequenceList = new LinkedList<QualifiedName>();
060:
061: Statement statement = metaData.getConnection()
062: .createStatement();
063:
064: ResultSet resultSet = statement
065: .executeQuery("SELECT seq_name FROM iisequence");
066:
067: while (resultSet.next()) {
068: sequenceList.add(new QualifiedName(resultSet.getString(1)));
069: }
070:
071: statement.close();
072:
073: return sequenceList;
074: }
075:
076: /**
077: * @see net.sf.hajdbc.dialect.StandardDialect#parseSequence(java.lang.String)
078: */
079: @Override
080: public String parseSequence(String sql) {
081: String sequence = super .parseSequence(sql);
082:
083: return (sequence != null) ? sequence : this .parse(
084: this .legacySequencePattern, sql);
085: }
086:
087: /**
088: * @see net.sf.hajdbc.dialect.StandardDialect#sequencePattern()
089: */
090: @Override
091: protected String sequencePattern() {
092: return "(?:NEXT|CURRENT)\\s+VALUE\\s+FOR\\s+'?([^',\\s\\(\\)]+)";
093: }
094:
095: /**
096: * @see net.sf.hajdbc.dialect.StandardDialect#currentDatePattern()
097: */
098: @Override
099: protected String currentDatePattern() {
100: return "(?<=\\W)CURRENT_DATE(?=\\W)|(?<=\\W)DATE\\s*\\(\\s*'TODAY'\\s*\\)";
101: }
102:
103: /**
104: * @see net.sf.hajdbc.dialect.StandardDialect#currentTimePattern()
105: */
106: @Override
107: protected String currentTimePattern() {
108: return "(?<=\\W)CURRENT_TIME(?=\\W)|(?<=\\W)LOCAL_TIME(?=\\W)";
109: }
110:
111: /**
112: * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampPattern()
113: */
114: @Override
115: protected String currentTimestampPattern() {
116: return "(?<=\\W)CURRENT_TIMESTAMP(?=\\W)|(?<=\\W)LOCAL_TIMESTAMP(?=\\W)|(?<=\\W)DATE\\s*\\(\\s*'NOW'\\s*\\)";
117: }
118:
119: /**
120: * @see net.sf.hajdbc.dialect.StandardDialect#randomPattern()
121: */
122: @Override
123: protected String randomPattern() {
124: return "(?<=\\W)RANDOMF\\s*\\(\\s*\\)";
125: }
126: }
|