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; 030import java.util.regex.Pattern; 031 032import 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") 040public class IngresDialect extends StandardDialect 041{ 042 private Pattern legacySequencePattern = Pattern.compile("'?(\\w+)'?\\.(?:(?:CURR)|(?:NEXT))VAL", Pattern.CASE_INSENSITIVE); 043 044 /** 045 * @see net.sf.hajdbc.dialect.StandardDialect#parseInsertTable(java.lang.String) 046 */ 047 @Override 048 public String parseInsertTable(String sql) 049 { 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(DatabaseMetaData metaData) throws SQLException 058 { 059 List<QualifiedName> sequenceList = new LinkedList<QualifiedName>(); 060 061 Statement statement = metaData.getConnection().createStatement(); 062 063 ResultSet resultSet = statement.executeQuery("SELECT seq_name FROM iisequence"); 064 065 while (resultSet.next()) 066 { 067 sequenceList.add(new QualifiedName(resultSet.getString(1))); 068 } 069 070 statement.close(); 071 072 return sequenceList; 073 } 074 075 /** 076 * @see net.sf.hajdbc.dialect.StandardDialect#parseSequence(java.lang.String) 077 */ 078 @Override 079 public String parseSequence(String sql) 080 { 081 String sequence = super.parseSequence(sql); 082 083 return (sequence != null) ? sequence : this.parse(this.legacySequencePattern, sql); 084 } 085 086 /** 087 * @see net.sf.hajdbc.dialect.StandardDialect#sequencePattern() 088 */ 089 @Override 090 protected String sequencePattern() 091 { 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 { 101 return "(?<=\\W)CURRENT_DATE(?=\\W)|(?<=\\W)DATE\\s*\\(\\s*'TODAY'\\s*\\)"; 102 } 103 104 /** 105 * @see net.sf.hajdbc.dialect.StandardDialect#currentTimePattern() 106 */ 107 @Override 108 protected String currentTimePattern() 109 { 110 return "(?<=\\W)CURRENT_TIME(?=\\W)|(?<=\\W)LOCAL_TIME(?=\\W)"; 111 } 112 113 /** 114 * @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampPattern() 115 */ 116 @Override 117 protected String currentTimestampPattern() 118 { 119 return "(?<=\\W)CURRENT_TIMESTAMP(?=\\W)|(?<=\\W)LOCAL_TIMESTAMP(?=\\W)|(?<=\\W)DATE\\s*\\(\\s*'NOW'\\s*\\)"; 120 } 121 122 /** 123 * @see net.sf.hajdbc.dialect.StandardDialect#randomPattern() 124 */ 125 @Override 126 protected String randomPattern() 127 { 128 return "(?<=\\W)RANDOMF\\s*\\(\\s*\\)"; 129 } 130}