teiid SVN: r4631 - in branches/7.7.x: engine/src/main/java/org/teiid/common/buffer/impl and 1 other directories.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2014-04-16 14:26:12 -0400 (Wed, 16 Apr 2014)
New Revision: 4631
Modified:
branches/7.7.x/client/src/main/java/org/teiid/client/BatchSerializer.java
branches/7.7.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferFrontedFileStoreCache.java
branches/7.7.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
branches/7.7.x/engine/src/main/resources/org/teiid/query/i18n.properties
Log:
TEIID-2636: Stream corruption errors when doing big query, logging changes only
Modified: branches/7.7.x/client/src/main/java/org/teiid/client/BatchSerializer.java
===================================================================
--- branches/7.7.x/client/src/main/java/org/teiid/client/BatchSerializer.java 2014-04-16 15:26:45 UTC (rev 4630)
+++ branches/7.7.x/client/src/main/java/org/teiid/client/BatchSerializer.java 2014-04-16 18:26:12 UTC (rev 4631)
@@ -592,7 +592,7 @@
break objectSearch;
}
}
- throw new TeiidRuntimeException(JDBCPlugin.Util.getString("BatchSerializer.datatype_mismatch", new Object[] {types[i], new Integer(i), objectClass})); //$NON-NLS-1$
+ throw new TeiidRuntimeException(e, JDBCPlugin.Util.getString("BatchSerializer.datatype_mismatch", new Object[] {types[i], new Integer(i), objectClass})); //$NON-NLS-1$
}
}
}
Modified: branches/7.7.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferFrontedFileStoreCache.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferFrontedFileStoreCache.java 2014-04-16 15:26:45 UTC (rev 4630)
+++ branches/7.7.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferFrontedFileStoreCache.java 2014-04-16 18:26:12 UTC (rev 4631)
@@ -676,9 +676,9 @@
//entries are mutable after adding, the original should be removed shortly so just ignore
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Object "+ entry.getId() +" changed size since first persistence, keeping the original."); //$NON-NLS-1$ //$NON-NLS-2$
} else if (e == BlockOutputStream.exceededMax){
- LogManager.logError(LogConstants.CTX_BUFFER_MGR, "Max block number exceeded. Increase the maxStorageObjectSize to support larger storage objects. Alternatively you could make the processor batch size smaller."); //$NON-NLS-1$
+ LogManager.logError(LogConstants.CTX_BUFFER_MGR, "Max block number exceeded " + s.getId() + " " + entry.getId() + " Increase the maxStorageObjectSize to support larger storage objects. Alternatively you could make the processor batch size smaller."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
- LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error persisting, attempts to read "+ entry.getId() +" later will result in an exception."); //$NON-NLS-1$ //$NON-NLS-2$
+ LogManager.logError(LogConstants.CTX_BUFFER_MGR, e, "Error persisting, attempts to read " + s.getId() + " " + entry.getId() +" later will result in an exception."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
} finally {
if (hasPermit) {
@@ -789,9 +789,9 @@
CacheEntry ce = new CacheEntry(new CacheKey(oid, 1, 1), sizeEstimate, serializer.deserialize(dis), ref, true);
return ce;
} catch(IOException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", oid)); //$NON-NLS-1$
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", info.gid, oid)); //$NON-NLS-1$
} catch (ClassNotFoundException e) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", oid)); //$NON-NLS-1$
+ throw new TeiidComponentException(e, QueryPlugin.Util.getString("FileStoreageManager.error_reading", info.gid, oid)); //$NON-NLS-1$
} catch (InterruptedException e) {
throw new TeiidRuntimeException(e);
} finally {
Modified: branches/7.7.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2014-04-16 15:26:45 UTC (rev 4630)
+++ branches/7.7.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2014-04-16 18:26:12 UTC (rev 4631)
@@ -48,6 +48,7 @@
import org.teiid.client.BatchSerializer;
import org.teiid.client.ResizingArrayList;
+import org.teiid.client.util.ExceptionUtil;
import org.teiid.common.buffer.*;
import org.teiid.common.buffer.AutoCleanupUtil.Removable;
import org.teiid.common.buffer.LobManager.ReferenceMode;
@@ -205,7 +206,7 @@
CacheKey key = new CacheKey(oid, (int)readAttempts.get(), old!=null?old.getKey().getOrderingValue():0);
CacheEntry ce = new CacheEntry(key, sizeEstimate, batch, this.ref, false);
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", ce.getId(), "with size estimate", ce.getSizeEstimate()); //$NON-NLS-1$ //$NON-NLS-2$
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", this.id, ce.getId(), "with size estimate", ce.getSizeEstimate()); //$NON-NLS-1$ //$NON-NLS-2$
}
maxReserveBytes.addAndGet(-BATCH_OVERHEAD);
reserveBatchBytes.addAndGet(-BATCH_OVERHEAD);
@@ -236,7 +237,6 @@
@Override
public void serialize(List<? extends List<?>> obj,
ObjectOutput oos) throws IOException {
- int expectedModCount = 0;
ResizingArrayList<?> list = null;
if (obj instanceof ResizingArrayList<?>) {
list = (ResizingArrayList<?>)obj;
@@ -245,11 +245,15 @@
//it's expected that the containing structure has updated the lob manager
BatchSerializer.writeBatch(oos, types, obj);
} catch (RuntimeException e) {
+ if (ExceptionUtil.getExceptionOfType(e, ClassCastException.class) != null) {
+ throw e;
+ }
//there is a chance of a concurrent persist while modifying
//in which case we want to swallow this exception
- if (list == null || list.getModCount() == expectedModCount) {
+ if (list == null) {
throw e;
}
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, e, "Possible Concurrent Modification", id); //$NON-NLS-1$
}
}
@@ -756,7 +760,7 @@
if (persist) {
long count = writeCount.incrementAndGet();
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, ce.getId(), "writing batch to storage, total writes: ", count); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, s.getId(), ce.getId(), "writing batch to storage, total writes: ", count); //$NON-NLS-1$
}
}
boolean result = cache.add(ce, s);
@@ -837,7 +841,7 @@
CacheEntry remove(Long gid, Long batch, boolean prefersMemory) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
- LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Removing batch from BufferManager", batch); //$NON-NLS-1$
+ LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Removing batch from BufferManager", gid, batch); //$NON-NLS-1$
}
cleanSoftReferences();
CacheEntry ce = fastGet(batch, prefersMemory, false);
Modified: branches/7.7.x/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/7.7.x/engine/src/main/resources/org/teiid/query/i18n.properties 2014-04-16 15:26:45 UTC (rev 4630)
+++ branches/7.7.x/engine/src/main/resources/org/teiid/query/i18n.properties 2014-04-16 18:26:12 UTC (rev 4631)
@@ -804,7 +804,7 @@
ProcedurePlan.nonNullableParam=The procedure parameter {0} is not nullable, but is set to null.
FileStoreageManager.error_creating=Error creating {0}
-FileStoreageManager.error_reading=Error reading {0}
+FileStoreageManager.error_reading=Error reading {0} {1}
FileStoreageManager.no_directory=No directory specified for the file storage manager.
FileStoreageManager.not_a_directory={0} is not a valid storage manager directory.
FileStoreageManager.space_exhausted=Max buffer space of {2} bytes has been exceed with an allocation of {0} bytes for a total of {1}. The current operation will be aborted.
10 years, 9 months
teiid SVN: r4630 - in branches/7.7.x: connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc and 10 other directories.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2014-04-16 11:26:45 -0400 (Wed, 16 Apr 2014)
New Revision: 4630
Added:
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/Version.java
Modified:
branches/7.7.x/common-core/src/main/java/org/teiid/core/util/StringUtil.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/derby/DerbyExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/derby/TestDerbyCapabilities.java
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
Log:
TEIID-2477: Standardize and correct jdbc database version comparisons
Modified: branches/7.7.x/common-core/src/main/java/org/teiid/core/util/StringUtil.java
===================================================================
--- branches/7.7.x/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -179,6 +179,32 @@
}
/**
+ * Return a stringified version of the array.
+ * @param array the array
+ * @param delim the delimiter to use between array components
+ * @return the string form of the array
+ */
+ public static String toString( final Object[] array, final String delim, boolean includeBrackets) {
+ if ( array == null ) {
+ return ""; //$NON-NLS-1$
+ }
+ final StringBuffer sb = new StringBuffer();
+ if (includeBrackets) {
+ sb.append('[');
+ }
+ for (int i = 0; i < array.length; ++i) {
+ if ( i != 0 ) {
+ sb.append(delim);
+ }
+ sb.append(array[i]);
+ }
+ if (includeBrackets) {
+ sb.append(']');
+ }
+ return sb.toString();
+ }
+
+ /**
* Return a stringified version of the array, using a ',' as a delimiter
* @param array the array
* @return the string form of the array
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -125,7 +125,7 @@
private String databaseTimeZone;
private boolean trimStrings;
private boolean useCommentsInSourceQuery;
- private String version;
+ private Version version;
private int maxInsertBatchSize = 2048;
private DatbaseCalender databaseCalender;
@@ -149,12 +149,31 @@
@TranslatorProperty(display="Database Version", description= "Database Version")
public String getDatabaseVersion() {
- return this.version;
+ return this.version.toString();
}
- public void setDatabaseVersion(String version) {
- this.version = version;
- }
+ /**
+ * Sets the database version. See also {@link #getVersion()}
+ * @param version
+ */
+ public void setDatabaseVersion(String version) {
+ this.version = Version.getVersion(version);
+ }
+
+ public void setDatabaseVersion(Version version) {
+ this.version = version;
+ }
+
+ /**
+ * Get the database version as a comparable object
+ * @return
+ */
+ protected Version getVersion() {
+ if (version == null) {
+ return Version.DEFAULT_VERSION;
+ }
+ return this.version;
+ }
@TranslatorProperty(display="Use Bind Variables", description="Use prepared statements and bind variables",advanced=true)
public boolean useBindVariables() {
Added: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/Version.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/Version.java (rev 0)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/Version.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.translator.jdbc;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.teiid.core.util.StringUtil;
+
+/**
+ * Represents a comparable version
+ */
+public class Version implements Comparable<Version> {
+
+ public static Version DEFAULT_VERSION = new Version(new Integer[] {0});
+ private static final Pattern NUMBER_PATTERN = Pattern.compile("(\\d+)"); //$NON-NLS-1$
+
+ private Integer[] parts;
+
+ public static Version getVersion(String version) {
+ if (version == null) {
+ return null;
+ }
+ String[] parts = version.split("\\."); //$NON-NLS-1$
+ List<Integer> versionParts = new ArrayList<Integer>();
+ for (String part : parts) {
+ Integer val = null;
+ Matcher m = NUMBER_PATTERN.matcher(part);
+ if (!m.find()) {
+ continue;
+ }
+
+ String num = m.group(1);
+ try {
+ val = Integer.parseInt(num);
+ } catch (NumberFormatException e) {
+
+ }
+ versionParts.add(val == null ? 0 : val);
+ }
+ if (versionParts.isEmpty()) {
+ return DEFAULT_VERSION;
+ }
+ return new Version(versionParts.toArray(new Integer[versionParts.size()]));
+ }
+
+ Version(Integer[] parts) {
+ this.parts = parts;
+ }
+
+ @Override
+ public String toString() {
+ return StringUtil.toString(this.parts, ".", false); //$NON-NLS-1$
+ }
+
+ public int getMajorVersion() {
+ return parts[0];
+ }
+
+ @Override
+ public int compareTo(Version o) {
+ int length = Math.min(this.parts.length, o.parts.length);
+ for (int i = 0; i < length; i++) {
+ int comp = this.parts[i].compareTo(o.parts[i]);
+ if (comp != 0) {
+ return comp;
+ }
+ }
+ if (this.parts.length > length) {
+ return 1;
+ }
+ if (o.parts.length > length) {
+ return -1;
+ }
+ return 0;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof Version)) {
+ return false;
+ }
+ return this.compareTo((Version)obj) == 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(parts);
+ }
+
+}
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -1,153 +1,154 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
package org.teiid.translator.jdbc.db2;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.Literal;
-import org.teiid.translator.SourceSystemFunctions;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.jdbc.FunctionModifier;
-
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.language.Expression;
+import org.teiid.language.Function;
+import org.teiid.language.Literal;
+import org.teiid.translator.SourceSystemFunctions;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.jdbc.FunctionModifier;
+import org.teiid.translator.jdbc.Version;
+
@Translator(name="db2", description="A translator for IBM DB2 Database")
-public class DB2ExecutionFactory extends BaseDB2ExecutionFactory {
-
- public static final String EIGHT_0 = "8.0"; //$NON-NLS-1$
- public static final String NINE_1 = "9.1"; //$NON-NLS-1$
-
- public DB2ExecutionFactory() {
- setDatabaseVersion(EIGHT_0);
- }
-
- @Override
- public List<String> getSupportedFunctions() {
- List<String> supportedFunctions = new ArrayList<String>();
- supportedFunctions.addAll(super.getSupportedFunctions());
- supportedFunctions.add("ABS"); //$NON-NLS-1$
- supportedFunctions.add("ACOS"); //$NON-NLS-1$
- supportedFunctions.add("ASIN"); //$NON-NLS-1$
- supportedFunctions.add("ATAN"); //$NON-NLS-1$
- supportedFunctions.add("ATAN2"); //$NON-NLS-1$
- supportedFunctions.add("CEILING"); //$NON-NLS-1$
- supportedFunctions.add("COS"); //$NON-NLS-1$
- supportedFunctions.add("COT"); //$NON-NLS-1$
- supportedFunctions.add("DEGREES"); //$NON-NLS-1$
- supportedFunctions.add("EXP"); //$NON-NLS-1$
- supportedFunctions.add("FLOOR"); //$NON-NLS-1$
- supportedFunctions.add("LOG"); //$NON-NLS-1$
- supportedFunctions.add("LOG10"); //$NON-NLS-1$
- supportedFunctions.add("MOD"); //$NON-NLS-1$
- supportedFunctions.add("POWER"); //$NON-NLS-1$
- supportedFunctions.add("RADIANS"); //$NON-NLS-1$
- supportedFunctions.add("SIGN"); //$NON-NLS-1$
- supportedFunctions.add("SIN"); //$NON-NLS-1$
- supportedFunctions.add("SQRT"); //$NON-NLS-1$
- supportedFunctions.add("TAN"); //$NON-NLS-1$
- //supportedFunctions.add("ASCII"); //$NON-NLS-1$
- supportedFunctions.add("CHAR"); //$NON-NLS-1$
- supportedFunctions.add("CHR"); //$NON-NLS-1$
- supportedFunctions.add("CONCAT"); //$NON-NLS-1$
- supportedFunctions.add("||"); //$NON-NLS-1$
- //supportedFunctions.add("INITCAP"); //$NON-NLS-1$
- supportedFunctions.add("LCASE"); //$NON-NLS-1$
- supportedFunctions.add("LENGTH"); //$NON-NLS-1$
- supportedFunctions.add("LEFT"); //$NON-NLS-1$
- supportedFunctions.add("LOCATE"); //$NON-NLS-1$
- supportedFunctions.add("LOWER"); //$NON-NLS-1$
- //supportedFunctions.add("LPAD"); //$NON-NLS-1$
- supportedFunctions.add("LTRIM"); //$NON-NLS-1$
- supportedFunctions.add("RAND"); //$NON-NLS-1$
- supportedFunctions.add("REPLACE"); //$NON-NLS-1$
- //supportedFunctions.add("RPAD"); //$NON-NLS-1$
- supportedFunctions.add("RIGHT"); //$NON-NLS-1$
- supportedFunctions.add("RTRIM"); //$NON-NLS-1$
- supportedFunctions.add("SUBSTRING"); //$NON-NLS-1$
- supportedFunctions.add(SourceSystemFunctions.TRIM);
- //supportedFunctions.add("TRANSLATE"); //$NON-NLS-1$
- supportedFunctions.add("UCASE"); //$NON-NLS-1$
- supportedFunctions.add("UPPER"); //$NON-NLS-1$
- supportedFunctions.add("HOUR"); //$NON-NLS-1$
- supportedFunctions.add("MONTH"); //$NON-NLS-1$
- supportedFunctions.add("MONTHNAME"); //$NON-NLS-1$
- supportedFunctions.add("YEAR"); //$NON-NLS-1$
- supportedFunctions.add("DAY"); //$NON-NLS-1$
- supportedFunctions.add("DAYNAME"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFMONTH"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFWEEK"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFYEAR"); //$NON-NLS-1$
- supportedFunctions.add("QUARTER"); //$NON-NLS-1$
- supportedFunctions.add("MINUTE"); //$NON-NLS-1$
- supportedFunctions.add("SECOND"); //$NON-NLS-1$
- supportedFunctions.add("QUARTER"); //$NON-NLS-1$
- supportedFunctions.add("WEEK"); //$NON-NLS-1$
- supportedFunctions.add("CAST"); //$NON-NLS-1$
- supportedFunctions.add("CONVERT"); //$NON-NLS-1$
- supportedFunctions.add("IFNULL"); //$NON-NLS-1$
- supportedFunctions.add("NVL"); //$NON-NLS-1$
- supportedFunctions.add("COALESCE"); //$NON-NLS-1$
- return supportedFunctions;
- }
+public class DB2ExecutionFactory extends BaseDB2ExecutionFactory {
+
+ public static final Version EIGHT_0 = Version.getVersion("8.0"); //$NON-NLS-1$
+ public static final Version NINE_1 = Version.getVersion("9.1"); //$NON-NLS-1$
+
+ public DB2ExecutionFactory() {
+ setDatabaseVersion(EIGHT_0);
+ }
+
+ @Override
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
+ supportedFunctions.addAll(super.getSupportedFunctions());
+ supportedFunctions.add("ABS"); //$NON-NLS-1$
+ supportedFunctions.add("ACOS"); //$NON-NLS-1$
+ supportedFunctions.add("ASIN"); //$NON-NLS-1$
+ supportedFunctions.add("ATAN"); //$NON-NLS-1$
+ supportedFunctions.add("ATAN2"); //$NON-NLS-1$
+ supportedFunctions.add("CEILING"); //$NON-NLS-1$
+ supportedFunctions.add("COS"); //$NON-NLS-1$
+ supportedFunctions.add("COT"); //$NON-NLS-1$
+ supportedFunctions.add("DEGREES"); //$NON-NLS-1$
+ supportedFunctions.add("EXP"); //$NON-NLS-1$
+ supportedFunctions.add("FLOOR"); //$NON-NLS-1$
+ supportedFunctions.add("LOG"); //$NON-NLS-1$
+ supportedFunctions.add("LOG10"); //$NON-NLS-1$
+ supportedFunctions.add("MOD"); //$NON-NLS-1$
+ supportedFunctions.add("POWER"); //$NON-NLS-1$
+ supportedFunctions.add("RADIANS"); //$NON-NLS-1$
+ supportedFunctions.add("SIGN"); //$NON-NLS-1$
+ supportedFunctions.add("SIN"); //$NON-NLS-1$
+ supportedFunctions.add("SQRT"); //$NON-NLS-1$
+ supportedFunctions.add("TAN"); //$NON-NLS-1$
+ //supportedFunctions.add("ASCII"); //$NON-NLS-1$
+ supportedFunctions.add("CHAR"); //$NON-NLS-1$
+ supportedFunctions.add("CHR"); //$NON-NLS-1$
+ supportedFunctions.add("CONCAT"); //$NON-NLS-1$
+ supportedFunctions.add("||"); //$NON-NLS-1$
+ //supportedFunctions.add("INITCAP"); //$NON-NLS-1$
+ supportedFunctions.add("LCASE"); //$NON-NLS-1$
+ supportedFunctions.add("LENGTH"); //$NON-NLS-1$
+ supportedFunctions.add("LEFT"); //$NON-NLS-1$
+ supportedFunctions.add("LOCATE"); //$NON-NLS-1$
+ supportedFunctions.add("LOWER"); //$NON-NLS-1$
+ //supportedFunctions.add("LPAD"); //$NON-NLS-1$
+ supportedFunctions.add("LTRIM"); //$NON-NLS-1$
+ supportedFunctions.add("RAND"); //$NON-NLS-1$
+ supportedFunctions.add("REPLACE"); //$NON-NLS-1$
+ //supportedFunctions.add("RPAD"); //$NON-NLS-1$
+ supportedFunctions.add("RIGHT"); //$NON-NLS-1$
+ supportedFunctions.add("RTRIM"); //$NON-NLS-1$
+ supportedFunctions.add("SUBSTRING"); //$NON-NLS-1$
+ supportedFunctions.add(SourceSystemFunctions.TRIM);
+ //supportedFunctions.add("TRANSLATE"); //$NON-NLS-1$
+ supportedFunctions.add("UCASE"); //$NON-NLS-1$
+ supportedFunctions.add("UPPER"); //$NON-NLS-1$
+ supportedFunctions.add("HOUR"); //$NON-NLS-1$
+ supportedFunctions.add("MONTH"); //$NON-NLS-1$
+ supportedFunctions.add("MONTHNAME"); //$NON-NLS-1$
+ supportedFunctions.add("YEAR"); //$NON-NLS-1$
+ supportedFunctions.add("DAY"); //$NON-NLS-1$
+ supportedFunctions.add("DAYNAME"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFMONTH"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFWEEK"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFYEAR"); //$NON-NLS-1$
+ supportedFunctions.add("QUARTER"); //$NON-NLS-1$
+ supportedFunctions.add("MINUTE"); //$NON-NLS-1$
+ supportedFunctions.add("SECOND"); //$NON-NLS-1$
+ supportedFunctions.add("QUARTER"); //$NON-NLS-1$
+ supportedFunctions.add("WEEK"); //$NON-NLS-1$
+ supportedFunctions.add("CAST"); //$NON-NLS-1$
+ supportedFunctions.add("CONVERT"); //$NON-NLS-1$
+ supportedFunctions.add("IFNULL"); //$NON-NLS-1$
+ supportedFunctions.add("NVL"); //$NON-NLS-1$
+ supportedFunctions.add("COALESCE"); //$NON-NLS-1$
+ return supportedFunctions;
+ }
- @Override
- public boolean supportsFunctionsInGroupBy() {
- return true;
- }
-
- @Override
- public boolean supportsAggregatesEnhancedNumeric() {
- return true;
- }
-
- @Override
- public boolean supportsCommonTableExpressions() {
- return true;
- }
-
- @Override
- public boolean supportsRowLimit() {
- return true;
- }
-
- @Override
- public boolean supportsElementaryOlapOperations() {
- return getDatabaseVersion().compareTo(NINE_1) >= 0;
- }
-
- @Override
- public void start() throws TranslatorException {
- super.start();
- registerFunctionModifier(SourceSystemFunctions.TRIM, new FunctionModifier() {
-
- @Override
- public List<?> translate(Function function) {
- List<Expression> p = function.getParameters();
- return Arrays.asList("STRIP(", p.get(2), ", ", ((Literal)p.get(0)).getValue(), ", ", p.get(1), ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
- });
- }
+ @Override
+ public boolean supportsFunctionsInGroupBy() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsCommonTableExpressions() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsRowLimit() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsElementaryOlapOperations() {
+ return getVersion().compareTo(NINE_1) >= 0;
+ }
+
+ @Override
+ public void start() throws TranslatorException {
+ super.start();
+ registerFunctionModifier(SourceSystemFunctions.TRIM, new FunctionModifier() {
+
+ @Override
+ public List<?> translate(Function function) {
+ List<Expression> p = function.getParameters();
+ return Arrays.asList("STRIP(", p.get(2), ", ", ((Literal)p.get(0)).getValue(), ", ", p.get(1), ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+ });
+ }
}
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/derby/DerbyExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/derby/DerbyExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/derby/DerbyExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -20,8 +20,8 @@
* 02110-1301 USA.
*/
-package org.teiid.translator.jdbc.derby;
-
+package org.teiid.translator.jdbc.derby;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -34,20 +34,21 @@
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.EscapeSyntaxModifier;
+import org.teiid.translator.jdbc.Version;
import org.teiid.translator.jdbc.db2.BaseDB2ExecutionFactory;
import org.teiid.translator.jdbc.oracle.LeftOrRightFunctionModifier;
-/**
- * @since 4.3
+/**
+ * @since 4.3
*/
-@Translator(name="derby", description="A translator for Apache Derby Database")
+@Translator(name="derby", description="A translator for Apache Derby Database")
public class DerbyExecutionFactory extends BaseDB2ExecutionFactory {
- public static final String TEN_1 = "10.1"; //$NON-NLS-1$
- public static final String TEN_2 = "10.2"; //$NON-NLS-1$
- public static final String TEN_3 = "10.3"; //$NON-NLS-1$
- public static final String TEN_4 = "10.4"; //$NON-NLS-1$
- public static final String TEN_5 = "10.5"; //$NON-NLS-1$
+ public static final Version TEN_1 = Version.getVersion("10.1"); //$NON-NLS-1$
+ public static final Version TEN_2 = Version.getVersion("10.2"); //$NON-NLS-1$
+ public static final Version TEN_3 = Version.getVersion("10.3"); //$NON-NLS-1$
+ public static final Version TEN_4 = Version.getVersion("10.4"); //$NON-NLS-1$
+ public static final Version TEN_5 = Version.getVersion("10.5"); //$NON-NLS-1$
public DerbyExecutionFactory() {
setSupportsFullOuterJoins(false); //Derby supports only left and right outer joins.
@@ -58,22 +59,22 @@
public void start() throws TranslatorException {
super.start();
//additional derby functions
- registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.LEFT, new LeftOrRightFunctionModifier(getLanguageFactory()));
//overrides of db2 functions
registerFunctionModifier(SourceSystemFunctions.CONCAT, new EscapeSyntaxModifier());
- }
+ }
- @Override
+ @Override
public boolean addSourceComment() {
return false;
}
@Override
public boolean supportsOrderByNullOrdering() {
- return getDatabaseVersion().compareTo(TEN_4) >= 0;
+ return getVersion().compareTo(TEN_4) >= 0;
}
@Override
@@ -82,12 +83,12 @@
supportedFunctions.addAll(super.getDefaultSupportedFunctions());
supportedFunctions.add("ABS"); //$NON-NLS-1$
- if (getDatabaseVersion().compareTo(TEN_2) >= 0) {
+ if (getVersion().compareTo(TEN_2) >= 0) {
supportedFunctions.add("ACOS"); //$NON-NLS-1$
supportedFunctions.add("ASIN"); //$NON-NLS-1$
supportedFunctions.add("ATAN"); //$NON-NLS-1$
}
- if (getDatabaseVersion().compareTo(TEN_4) >= 0) {
+ if (getVersion().compareTo(TEN_4) >= 0) {
supportedFunctions.add("ATAN2"); //$NON-NLS-1$
}
// These are executed within the server and never pushed down
@@ -95,7 +96,7 @@
//supportedFunctions.add("BITNOT"); //$NON-NLS-1$
//supportedFunctions.add("BITOR"); //$NON-NLS-1$
//supportedFunctions.add("BITXOR"); //$NON-NLS-1$
- if (getDatabaseVersion().compareTo(TEN_2) >= 0) {
+ if (getVersion().compareTo(TEN_2) >= 0) {
supportedFunctions.add("CEILING"); //$NON-NLS-1$
supportedFunctions.add("COS"); //$NON-NLS-1$
supportedFunctions.add("COT"); //$NON-NLS-1$
@@ -106,12 +107,12 @@
supportedFunctions.add("LOG10"); //$NON-NLS-1$
}
supportedFunctions.add("MOD"); //$NON-NLS-1$
- if (getDatabaseVersion().compareTo(TEN_2) >= 0) {
+ if (getVersion().compareTo(TEN_2) >= 0) {
supportedFunctions.add("PI"); //$NON-NLS-1$
//supportedFunctions.add("POWER"); //$NON-NLS-1$
supportedFunctions.add("RADIANS"); //$NON-NLS-1$
//supportedFunctions.add("ROUND"); //$NON-NLS-1$
- if (getDatabaseVersion().compareTo(TEN_4) >= 0) {
+ if (getVersion().compareTo(TEN_4) >= 0) {
supportedFunctions.add("SIGN"); //$NON-NLS-1$
}
supportedFunctions.add("SIN"); //$NON-NLS-1$
@@ -136,7 +137,7 @@
//supportedFunctions.add("RPAD"); //$NON-NLS-1$
supportedFunctions.add("RTRIM"); //$NON-NLS-1$
supportedFunctions.add("SUBSTRING"); //$NON-NLS-1$
- if (getDatabaseVersion().compareTo(TEN_3) >= 0) {
+ if (getVersion().compareTo(TEN_3) >= 0) {
supportedFunctions.add(SourceSystemFunctions.TRIM);
}
supportedFunctions.add("UCASE"); //$NON-NLS-1$
@@ -187,7 +188,7 @@
@Override
public boolean supportsRowLimit() {
- return this.getDatabaseVersion().compareTo(TEN_5) >= 0;
+ return this.getVersion().compareTo(TEN_5) >= 0;
}
@Override
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -60,13 +60,14 @@
import org.teiid.translator.jdbc.LocateFunctionModifier;
import org.teiid.translator.jdbc.SQLConversionVisitor;
import org.teiid.translator.jdbc.TranslatedCommand;
+import org.teiid.translator.jdbc.Version;
@Translator(name="oracle", description="A translator for Oracle 9i Database or later")
public class OracleExecutionFactory extends JDBCExecutionFactory {
- public static final String NINE_0 = "9.0"; //$NON-NLS-1$
- public static final String NINE_2 = "9.2"; //$NON-NLS-1$
+ public static final Version NINE_0 = Version.getVersion("9.0"); //$NON-NLS-1$
+ public static final Version NINE_2 = Version.getVersion("9.2"); //$NON-NLS-1$
private static final String TIME_FORMAT = "HH24:MI:SS"; //$NON-NLS-1$
private static final String DATE_FORMAT = "YYYY-MM-DD"; //$NON-NLS-1$
@@ -761,7 +762,7 @@
@Override
public boolean supportsCommonTableExpressions() {
- return getDatabaseVersion().compareTo(NINE_2) >= 0;
+ return getVersion().compareTo(NINE_2) >= 0;
}
}
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -1,92 +1,92 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
package org.teiid.translator.jdbc.postgresql;
-import java.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.teiid.language.AggregateFunction;
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.LanguageObject;
-import org.teiid.language.Like;
-import org.teiid.language.Limit;
-import org.teiid.language.Literal;
-import org.teiid.language.Like.MatchMode;
-import org.teiid.language.SQLConstants.NonReserved;
-import org.teiid.translator.ExecutionContext;
-import org.teiid.translator.SourceSystemFunctions;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.TypeFacility;
-import org.teiid.translator.jdbc.AliasModifier;
-import org.teiid.translator.jdbc.ConvertModifier;
-import org.teiid.translator.jdbc.EscapeSyntaxModifier;
-import org.teiid.translator.jdbc.ExtractFunctionModifier;
-import org.teiid.translator.jdbc.FunctionModifier;
-import org.teiid.translator.jdbc.JDBCExecutionFactory;
-import org.teiid.translator.jdbc.ModFunctionModifier;
-import org.teiid.translator.jdbc.oracle.LeftOrRightFunctionModifier;
-import org.teiid.translator.jdbc.oracle.MonthOrDayNameFunctionModifier;
-import org.teiid.translator.jdbc.oracle.OracleFormatFunctionModifier;
-
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.teiid.language.AggregateFunction;
+import org.teiid.language.Expression;
+import org.teiid.language.Function;
+import org.teiid.language.LanguageObject;
+import org.teiid.language.Like;
+import org.teiid.language.Limit;
+import org.teiid.language.Literal;
+import org.teiid.language.Like.MatchMode;
+import org.teiid.language.SQLConstants.NonReserved;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.SourceSystemFunctions;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TypeFacility;
+import org.teiid.translator.jdbc.AliasModifier;
+import org.teiid.translator.jdbc.ConvertModifier;
+import org.teiid.translator.jdbc.EscapeSyntaxModifier;
+import org.teiid.translator.jdbc.ExtractFunctionModifier;
+import org.teiid.translator.jdbc.FunctionModifier;
+import org.teiid.translator.jdbc.JDBCExecutionFactory;
+import org.teiid.translator.jdbc.ModFunctionModifier;
+import org.teiid.translator.jdbc.Version;
+import org.teiid.translator.jdbc.oracle.LeftOrRightFunctionModifier;
+import org.teiid.translator.jdbc.oracle.MonthOrDayNameFunctionModifier;
+import org.teiid.translator.jdbc.oracle.OracleFormatFunctionModifier;
-/**
+
+
+/**
* Translator class for PostgreSQL. Updated to expect a 8.0+ jdbc client
* @since 4.3
- */
+ */
@Translator(name="postgresql", description="A translator for postgreSQL Database")
-public class PostgreSQLExecutionFactory extends JDBCExecutionFactory {
-
- public static final String EIGHT_0 = "8.0"; //$NON-NLS-1$
- public static final String EIGHT_1 = "8.1"; //$NON-NLS-1$
- public static final String EIGHT_2 = "8.2"; //$NON-NLS-1$
- public static final String EIGHT_3 = "8.3"; //$NON-NLS-1$
- public static final String EIGHT_4 = "8.4"; //$NON-NLS-1$
-
- public PostgreSQLExecutionFactory() {
- setDatabaseVersion(EIGHT_0);
- setMaxDependentInPredicates(1);
- setMaxInCriteriaSize(Short.MAX_VALUE - 50); //set a value that is safely smaller than the max in case there are other parameters
- }
-
+public class PostgreSQLExecutionFactory extends JDBCExecutionFactory {
+
+ public static final Version EIGHT_0 = Version.getVersion("8.0"); //$NON-NLS-1$
+ public static final Version EIGHT_1 = Version.getVersion("8.1"); //$NON-NLS-1$
+ public static final Version EIGHT_2 = Version.getVersion("8.2"); //$NON-NLS-1$
+ public static final Version EIGHT_3 = Version.getVersion("8.3"); //$NON-NLS-1$
+ public static final Version EIGHT_4 = Version.getVersion("8.4"); //$NON-NLS-1$
+
+ public PostgreSQLExecutionFactory() {
+ setMaxDependentInPredicates(1);
+ setMaxInCriteriaSize(Short.MAX_VALUE - 50); //set a value that is safely smaller than the max in case there are other parameters
+ }
+
public void start() throws TranslatorException {
//TODO: all of the functions (except for convert) can be handled through just the escape syntax
- super.start();
+ super.start();
registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("ln")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.LOG10, new AliasModifier("log")); //$NON-NLS-1$
-
- registerFunctionModifier(SourceSystemFunctions.BITAND, new AliasModifier("&")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.BITNOT, new AliasModifier("~")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.BITOR, new AliasModifier("|")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.BITXOR, new AliasModifier("#")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.LOG10, new AliasModifier("log")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.BITAND, new AliasModifier("&")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.BITNOT, new AliasModifier("~")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.BITOR, new AliasModifier("|")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.BITXOR, new AliasModifier("#")); //$NON-NLS-1$
+
registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CONCAT, new AliasModifier("||")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower")); //$NON-NLS-1$
@@ -107,439 +107,439 @@
registerFunctionModifier(SourceSystemFunctions.SECOND, new ExtractFunctionModifier());
registerFunctionModifier(SourceSystemFunctions.WEEK, new ExtractFunctionModifier());
registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier());
- registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));
- registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
-
- registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new OracleFormatFunctionModifier("TO_TIMESTAMP(")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new OracleFormatFunctionModifier("TO_CHAR(")); //$NON-NLS-1$
-
- registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("%", getLanguageFactory(), Arrays.asList(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, TypeFacility.RUNTIME_TYPES.BIG_DECIMAL))); //$NON-NLS-1$
-
- //specific to 8.2 client or later
- registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
-
- registerFunctionModifier(SourceSystemFunctions.ARRAY_GET, new FunctionModifier() {
-
- @Override
- public List<?> translate(Function function) {
- return Arrays.asList(function.getParameters().get(0), '[', function.getParameters().get(1), ']');
- }
- });
- registerFunctionModifier(SourceSystemFunctions.ARRAY_LENGTH, new FunctionModifier() {
-
- @Override
- public List<?> translate(Function function) {
- if (function.getParameters().size() == 1) {
- function.getParameters().add(new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER));
- }
- return null;
- }
- });
-
- //add in type conversion
- ConvertModifier convertModifier = new ConvertModifier();
- convertModifier.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
- convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT); //$NON-NLS-1$
- convertModifier.addTypeMapping("integer", FunctionModifier.INTEGER); //$NON-NLS-1$
- convertModifier.addTypeMapping("bigint", FunctionModifier.LONG); //$NON-NLS-1$
- convertModifier.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
- convertModifier.addTypeMapping("float8", FunctionModifier.DOUBLE); //$NON-NLS-1$
- convertModifier.addTypeMapping("numeric(38)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
- convertModifier.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
- convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
- convertModifier.addTypeMapping("varchar(4000)", FunctionModifier.STRING); //$NON-NLS-1$
- convertModifier.addTypeMapping("date", FunctionModifier.DATE); //$NON-NLS-1$
- convertModifier.addTypeMapping("time", FunctionModifier.TIME); //$NON-NLS-1$
- convertModifier.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
- convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- return Arrays.asList(function.getParameters().get(0), " + TIMESTAMP '1970-01-01'"); //$NON-NLS-1$
- }
- });
- convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- return Arrays.asList("cast(date_trunc('second', ", function.getParameters().get(0), ") AS time)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- });
- convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD")); //$NON-NLS-1$ //$NON-NLS-2$
- convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "HH24:MI:SS")); //$NON-NLS-1$ //$NON-NLS-2$
- convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD HH24:MI:SS.US")); //$NON-NLS-1$ //$NON-NLS-2$
- convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- Expression stringValue = function.getParameters().get(0);
- return Arrays.asList("CASE WHEN ", stringValue, " THEN 'true' WHEN not(", stringValue, ") THEN 'false' END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- });
- convertModifier.addSourceConversion(new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- ((Literal)function.getParameters().get(1)).setValue("integer"); //$NON-NLS-1$
- return null;
- }
- }, FunctionModifier.BOOLEAN);
- registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
+ registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce")); //$NON-NLS-1$
+
+ registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new OracleFormatFunctionModifier("TO_TIMESTAMP(")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new OracleFormatFunctionModifier("TO_CHAR(")); //$NON-NLS-1$
+
+ registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("%", getLanguageFactory(), Arrays.asList(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, TypeFacility.RUNTIME_TYPES.BIG_DECIMAL))); //$NON-NLS-1$
+
+ //specific to 8.2 client or later
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
+
+ registerFunctionModifier(SourceSystemFunctions.ARRAY_GET, new FunctionModifier() {
+
+ @Override
+ public List<?> translate(Function function) {
+ return Arrays.asList(function.getParameters().get(0), '[', function.getParameters().get(1), ']');
+ }
+ });
+ registerFunctionModifier(SourceSystemFunctions.ARRAY_LENGTH, new FunctionModifier() {
+
+ @Override
+ public List<?> translate(Function function) {
+ if (function.getParameters().size() == 1) {
+ function.getParameters().add(new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER));
+ }
+ return null;
+ }
+ });
+
+ //add in type conversion
+ ConvertModifier convertModifier = new ConvertModifier();
+ convertModifier.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
+ convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT); //$NON-NLS-1$
+ convertModifier.addTypeMapping("integer", FunctionModifier.INTEGER); //$NON-NLS-1$
+ convertModifier.addTypeMapping("bigint", FunctionModifier.LONG); //$NON-NLS-1$
+ convertModifier.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
+ convertModifier.addTypeMapping("float8", FunctionModifier.DOUBLE); //$NON-NLS-1$
+ convertModifier.addTypeMapping("numeric(38)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
+ convertModifier.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
+ convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
+ convertModifier.addTypeMapping("varchar(4000)", FunctionModifier.STRING); //$NON-NLS-1$
+ convertModifier.addTypeMapping("date", FunctionModifier.DATE); //$NON-NLS-1$
+ convertModifier.addTypeMapping("time", FunctionModifier.TIME); //$NON-NLS-1$
+ convertModifier.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
+ convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ return Arrays.asList(function.getParameters().get(0), " + TIMESTAMP '1970-01-01'"); //$NON-NLS-1$
+ }
+ });
+ convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ return Arrays.asList("cast(date_trunc('second', ", function.getParameters().get(0), ") AS time)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ });
+ convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD")); //$NON-NLS-1$ //$NON-NLS-2$
+ convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "HH24:MI:SS")); //$NON-NLS-1$ //$NON-NLS-2$
+ convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD HH24:MI:SS.US")); //$NON-NLS-1$ //$NON-NLS-2$
+ convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ Expression stringValue = function.getParameters().get(0);
+ return Arrays.asList("CASE WHEN ", stringValue, " THEN 'true' WHEN not(", stringValue, ") THEN 'false' END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ });
+ convertModifier.addSourceConversion(new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ ((Literal)function.getParameters().get(1)).setValue("integer"); //$NON-NLS-1$
+ return null;
+ }
+ }, FunctionModifier.BOOLEAN);
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
}
-
+
@Override
- public String translateLiteralBoolean(Boolean booleanValue) {
- if(booleanValue.booleanValue()) {
- return "TRUE"; //$NON-NLS-1$
- }
- return "FALSE"; //$NON-NLS-1$
- }
-
- @Override
- public String translateLiteralDate(Date dateValue) {
- return "DATE '" + formatDateValue(dateValue) + "'"; //$NON-NLS-1$//$NON-NLS-2$
- }
-
- @Override
- public String translateLiteralTime(Time timeValue) {
- return "TIME '" + formatDateValue(timeValue) + "'"; //$NON-NLS-1$//$NON-NLS-2$
- }
-
- @Override
- public String translateLiteralTimestamp(Timestamp timestampValue) {
- return "TIMESTAMP '" + formatDateValue(timestampValue) + "'"; //$NON-NLS-1$//$NON-NLS-2$
- }
-
- @Override
- public int getTimestampNanoPrecision() {
- return 6;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public List<?> translateLimit(Limit limit, ExecutionContext context) {
- if (limit.getRowOffset() > 0) {
- return Arrays.asList("LIMIT ", limit.getRowLimit(), " OFFSET ", limit.getRowOffset()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- return null;
- }
-
- /**
- * Postgres doesn't provide min/max(boolean), so this conversion writes a min(BooleanValue) as
- * bool_and(BooleanValue)
- * @see org.teiid.language.visitor.LanguageObjectVisitor#visit(org.teiid.language.AggregateFunction)
- * @since 4.3
- */
- @Override
- public List<?> translate(LanguageObject obj, ExecutionContext context) {
- if (obj instanceof AggregateFunction) {
- AggregateFunction agg = (AggregateFunction)obj;
- if (agg.getExpression() != null && TypeFacility.RUNTIME_TYPES.BOOLEAN.equals(agg.getExpression().getType())) {
- if (agg.getName().equalsIgnoreCase(NonReserved.MIN)) {
- agg.setName("bool_and"); //$NON-NLS-1$
- } else if (agg.getName().equalsIgnoreCase(NonReserved.MAX)) {
- agg.setName("bool_or"); //$NON-NLS-1$
- }
- }
- } else if (obj instanceof Like) {
- Like like = (Like)obj;
- if (like.getMode() == MatchMode.REGEX) {
- return Arrays.asList(like.getLeftExpression(), like.isNegated()?" !~ ":" ~ ", like.getRightExpression()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- return super.translate(obj, context);
- }
-
- @Override
- public NullOrder getDefaultNullOrder() {
- return NullOrder.HIGH;
- }
-
- @Override
- public boolean supportsOrderByNullOrdering() {
- return getDatabaseVersion().compareTo(EIGHT_4) >= 0;
- }
-
- @Override
- public List<String> getSupportedFunctions() {
- List<String> supportedFunctions = new ArrayList<String>();
- supportedFunctions.addAll(super.getSupportedFunctions());
-
- supportedFunctions.add("ABS"); //$NON-NLS-1$
- supportedFunctions.add("ACOS"); //$NON-NLS-1$
- supportedFunctions.add("ASIN"); //$NON-NLS-1$
- supportedFunctions.add("ATAN"); //$NON-NLS-1$
- supportedFunctions.add("ATAN2"); //$NON-NLS-1$
- supportedFunctions.add("BITAND"); //$NON-NLS-1$
- supportedFunctions.add("BITNOT"); //$NON-NLS-1$
- supportedFunctions.add("BITOR"); //$NON-NLS-1$
- supportedFunctions.add("BITXOR"); //$NON-NLS-1$
- supportedFunctions.add("CEILING"); //$NON-NLS-1$
- supportedFunctions.add("COS"); //$NON-NLS-1$
- supportedFunctions.add("COT"); //$NON-NLS-1$
- supportedFunctions.add("DEGREES"); //$NON-NLS-1$
- supportedFunctions.add("EXP"); //$NON-NLS-1$
- supportedFunctions.add("FLOOR"); //$NON-NLS-1$
- // These should not be pushed down since the grammar for string conversion is different
-// supportedFunctions.add("FORMATBIGDECIMAL"); //$NON-NLS-1$
-// supportedFunctions.add("FORMATBIGINTEGER"); //$NON-NLS-1$
-// supportedFunctions.add("FORMATDOUBLE"); //$NON-NLS-1$
-// supportedFunctions.add("FORMATFLOAT"); //$NON-NLS-1$
-// supportedFunctions.add("FORMATINTEGER"); //$NON-NLS-1$
-// supportedFunctions.add("FORMATLONG"); //$NON-NLS-1$
- supportedFunctions.add("LOG"); //$NON-NLS-1$
- supportedFunctions.add("LOG10"); //$NON-NLS-1$
- supportedFunctions.add("MOD"); //$NON-NLS-1$
- supportedFunctions.add("PI"); //$NON-NLS-1$
- supportedFunctions.add("POWER"); //$NON-NLS-1$
- supportedFunctions.add("RADIANS"); //$NON-NLS-1$
- supportedFunctions.add("ROUND"); //$NON-NLS-1$
- supportedFunctions.add("SIGN"); //$NON-NLS-1$
- supportedFunctions.add("SIN"); //$NON-NLS-1$
- supportedFunctions.add("SQRT"); //$NON-NLS-1$
- supportedFunctions.add("TAN"); //$NON-NLS-1$
-
- supportedFunctions.add("ASCII"); //$NON-NLS-1$
- supportedFunctions.add("CHR"); //$NON-NLS-1$
- supportedFunctions.add("CHAR"); //$NON-NLS-1$
- supportedFunctions.add("||"); //$NON-NLS-1$
- supportedFunctions.add("CONCAT"); //$NON-NLS-1$
- supportedFunctions.add("INITCAP"); //$NON-NLS-1$
- supportedFunctions.add("LCASE"); //$NON-NLS-1$
- supportedFunctions.add("LEFT"); //$NON-NLS-1$
- supportedFunctions.add("LENGTH"); //$NON-NLS-1$
- supportedFunctions.add("LOCATE"); //$NON-NLS-1$
- supportedFunctions.add("LOWER"); //$NON-NLS-1$
- supportedFunctions.add("LPAD"); //$NON-NLS-1$
- supportedFunctions.add("LTRIM"); //$NON-NLS-1$
- supportedFunctions.add("REPEAT"); //$NON-NLS-1$
- supportedFunctions.add("REPLACE"); //$NON-NLS-1$
- supportedFunctions.add("RIGHT"); //$NON-NLS-1$
- supportedFunctions.add("RPAD"); //$NON-NLS-1$
- supportedFunctions.add("RTRIM"); //$NON-NLS-1$
- supportedFunctions.add("SUBSTRING"); //$NON-NLS-1$
- supportedFunctions.add(SourceSystemFunctions.TRIM);
- supportedFunctions.add("UCASE"); //$NON-NLS-1$
- supportedFunctions.add("UPPER"); //$NON-NLS-1$
-
- // These are executed within the server and never pushed down
-// supportedFunctions.add("CURDATE"); //$NON-NLS-1$
-// supportedFunctions.add("CURTIME"); //$NON-NLS-1$
-// supportedFunctions.add("NOW"); //$NON-NLS-1$
- supportedFunctions.add("DAYNAME"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFMONTH"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFWEEK"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFYEAR"); //$NON-NLS-1$
- // These should not be pushed down since the grammar for string conversion is different
-// supportedFunctions.add("FORMATDATE"); //$NON-NLS-1$
-// supportedFunctions.add("FORMATTIME"); //$NON-NLS-1$
-// supportedFunctions.add("FORMATTIMESTAMP"); //$NON-NLS-1$
- supportedFunctions.add("HOUR"); //$NON-NLS-1$
- supportedFunctions.add("MINUTE"); //$NON-NLS-1$
- supportedFunctions.add("MONTH"); //$NON-NLS-1$
- supportedFunctions.add("MONTHNAME"); //$NON-NLS-1$
- // These should not be pushed down since the grammar for string conversion is different
-// supportedFunctions.add("PARSEDATE"); //$NON-NLS-1$
-// supportedFunctions.add("PARSETIME"); //$NON-NLS-1$
-// supportedFunctions.add("PARSETIMESTAMP"); //$NON-NLS-1$
- supportedFunctions.add("QUARTER"); //$NON-NLS-1$
- supportedFunctions.add("SECOND"); //$NON-NLS-1$
- if (this.getDatabaseVersion().compareTo(EIGHT_2) >= 0) {
- supportedFunctions.add("TIMESTAMPADD"); //$NON-NLS-1$
- supportedFunctions.add("TIMESTAMPDIFF"); //$NON-NLS-1$
- }
- supportedFunctions.add("WEEK"); //$NON-NLS-1$
- supportedFunctions.add("YEAR"); //$NON-NLS-1$
-
- supportedFunctions.add("CAST"); //$NON-NLS-1$
- supportedFunctions.add("CONVERT"); //$NON-NLS-1$
- supportedFunctions.add("IFNULL"); //$NON-NLS-1$
- supportedFunctions.add("NVL"); //$NON-NLS-1$
-
- // Additional functions
-// // Math
-// supportedFunctions.add("%"); //$NON-NLS-1$
-// supportedFunctions.add("^"); //$NON-NLS-1$
-// supportedFunctions.add("|/"); //$NON-NLS-1$
-// supportedFunctions.add("||/"); //$NON-NLS-1$
-// supportedFunctions.add("!"); //$NON-NLS-1$
-// supportedFunctions.add("!!"); //$NON-NLS-1$
-// supportedFunctions.add("@"); //$NON-NLS-1$
-// // Bit manipulation
-// supportedFunctions.add("&"); //$NON-NLS-1$
-// supportedFunctions.add("|"); //$NON-NLS-1$
-// supportedFunctions.add("#"); //$NON-NLS-1$
-// supportedFunctions.add("~"); //$NON-NLS-1$
-// supportedFunctions.add("<<"); //$NON-NLS-1$
-// supportedFunctions.add(">>"); //$NON-NLS-1$
-//
-// supportedFunctions.add("CBRT"); //$NON-NLS-1$
-// supportedFunctions.add("CEIL"); //$NON-NLS-1$
-// supportedFunctions.add("LN"); //$NON-NLS-1$
-// supportedFunctions.add("MOD"); //$NON-NLS-1$
-// supportedFunctions.add("RANDOM"); //$NON-NLS-1$
-// supportedFunctions.add("SETSEED"); //$NON-NLS-1$
-// supportedFunctions.add("TRUNC"); //$NON-NLS-1$
-// supportedFunctions.add("WIDTH_BUCKET"); //$NON-NLS-1$
-//
-// // String
-// supportedFunctions.add("BIT_LENGTH"); //$NON-NLS-1$
-// supportedFunctions.add("BTRIM"); //$NON-NLS-1$
-// supportedFunctions.add("CHAR_LENGTH"); //$NON-NLS-1$
-// supportedFunctions.add("CHARACTER_LENGTH"); //$NON-NLS-1$
-// supportedFunctions.add("DECODE"); //$NON-NLS-1$
-// supportedFunctions.add("ENCODE"); //$NON-NLS-1$
-// supportedFunctions.add("MD5"); //$NON-NLS-1$
-// supportedFunctions.add("OCTET_LENGTH"); //$NON-NLS-1$
-// supportedFunctions.add("PG_CLIENT_ENCODING"); //$NON-NLS-1$
-// supportedFunctions.add("QUOTE_IDENT"); //$NON-NLS-1$
-// supportedFunctions.add("QUOTE_LITERAL"); //$NON-NLS-1$
-// supportedFunctions.add("SPLIT_PART"); //$NON-NLS-1$
-// supportedFunctions.add("STRPOS"); //$NON-NLS-1$
-// supportedFunctions.add("SUBSTR"); //$NON-NLS-1$
-// supportedFunctions.add("TO_ASCII"); //$NON-NLS-1$
-// supportedFunctions.add("TO_HEX"); //$NON-NLS-1$
-// supportedFunctions.add("TRANSLATE"); //$NON-NLS-1$
-//
-// // Bit operations
-// supportedFunctions.add("GET_BIT"); //$NON-NLS-1$
-// supportedFunctions.add("GET_BYTE"); //$NON-NLS-1$
-// supportedFunctions.add("SET_BIT"); //$NON-NLS-1$
-// supportedFunctions.add("SET_BYTE"); //$NON-NLS-1$
-//
-// // Formatting
-// supportedFunctions.add("TO_CHAR"); //$NON-NLS-1$
-// supportedFunctions.add("TO_DATE"); //$NON-NLS-1$
-// supportedFunctions.add("TO_TIMESTAMP"); //$NON-NLS-1$
-// supportedFunctions.add("TO_NUMBER"); //$NON-NLS-1$
-//
-// // Date / Time
-// supportedFunctions.add("AGE"); //$NON-NLS-1$
-// supportedFunctions.add("CURRENT_DATE"); //$NON-NLS-1$ // no ()
-// supportedFunctions.add("CURRENT_TIME"); //$NON-NLS-1$ // no ()
-// supportedFunctions.add("CURRENT_TIMESTAMP"); //$NON-NLS-1$ // no ()
-// supportedFunctions.add("DATE_PART"); //$NON-NLS-1$
-// supportedFunctions.add("DATE_TRUNC"); //$NON-NLS-1$
-// supportedFunctions.add("ISFINITE"); //$NON-NLS-1$
-// supportedFunctions.add("JUSTIFY_HOURS"); //$NON-NLS-1$
-// supportedFunctions.add("JUSTIFY_DAYS"); //$NON-NLS-1$
-// supportedFunctions.add("LOCALTIME"); //$NON-NLS-1$ // no ()
-// supportedFunctions.add("LOCALTIMESTAMP"); //$NON-NLS-1$ // no ()
-// supportedFunctions.add("TIMEOFDAY"); //$NON-NLS-1$
-//
-// // Conditional
- supportedFunctions.add("COALESCE"); //$NON-NLS-1$
-// supportedFunctions.add("NULLIF"); //$NON-NLS-1$
-// supportedFunctions.add("GREATEST"); //$NON-NLS-1$
-// supportedFunctions.add("LEAST"); //$NON-NLS-1$
-//
-// // Network Addresses
-//// supportedFunctions.add("BROADCAST"); //$NON-NLS-1$
-//// supportedFunctions.add("HOST"); //$NON-NLS-1$
-//// supportedFunctions.add("MASKLEN"); //$NON-NLS-1$
-//// supportedFunctions.add("SET_MASKLEN"); //$NON-NLS-1$
-//// supportedFunctions.add("NETMASK"); //$NON-NLS-1$
-//// supportedFunctions.add("HOSTMASK"); //$NON-NLS-1$
-//// supportedFunctions.add("NETWORK"); //$NON-NLS-1$
-//// supportedFunctions.add("TEXT"); //$NON-NLS-1$
-//// supportedFunctions.add("ABBREV"); //$NON-NLS-1$
-//// supportedFunctions.add("FAMILY"); //$NON-NLS-1$
-//// supportedFunctions.add("TRUNC"); //$NON-NLS-1$
-//
-// // Set generator
-// supportedFunctions.add("GENERATE_SERIES"); //$NON-NLS-1$
-//
-// // Information
-// supportedFunctions.add("CURRENT_DATABASE"); //$NON-NLS-1$
-// supportedFunctions.add("CURRENT_SCHEMA"); //$NON-NLS-1$
-// supportedFunctions.add("CURRENT_SCHEMAS"); //$NON-NLS-1$
-// supportedFunctions.add("CURRENT_USER"); //$NON-NLS-1$ // no ()
-// supportedFunctions.add("INET_CLIENT_ADDR"); //$NON-NLS-1$
-// supportedFunctions.add("INET_CLIENT_PORT"); //$NON-NLS-1$
-// supportedFunctions.add("INET_SERVER_ADDR"); //$NON-NLS-1$
-// supportedFunctions.add("INET_SERVER_PORT"); //$NON-NLS-1$
-// supportedFunctions.add("SESSION_USER"); //$NON-NLS-1$ // no ()
-// supportedFunctions.add("USER"); //$NON-NLS-1$ // no ()
-// supportedFunctions.add("VERSION"); //$NON-NLS-1$
-//
- supportedFunctions.add(SourceSystemFunctions.ARRAY_GET);
- supportedFunctions.add(SourceSystemFunctions.ARRAY_LENGTH);
- supportedFunctions.add(SourceSystemFunctions.FORMATTIMESTAMP);
- supportedFunctions.add(SourceSystemFunctions.PARSETIMESTAMP);
- return supportedFunctions;
- }
-
- /**
- * This is true only after Postgre version 7.1
- * However, since version 7 was released in 2000 we'll assume a post 7 instance.
- */
- public boolean supportsInlineViews() {
- return true;
- }
-
- @Override
- public boolean supportsRowLimit() {
- return true;
- }
- @Override
- public boolean supportsRowOffset() {
- return true;
- }
-
- @Override
- public boolean supportsExcept() {
- return true;
- }
-
- @Override
- public boolean supportsIntersect() {
- return true;
- }
-
- @Override
- public boolean supportsAggregatesEnhancedNumeric() {
- return getDatabaseVersion().compareTo(EIGHT_2) >= 0;
- }
-
- @Override
- public boolean supportsCommonTableExpressions() {
- return getDatabaseVersion().compareTo(EIGHT_4) >= 0;
- }
-
- @Override
- public boolean supportsArrayAgg() {
- return getDatabaseVersion().compareTo(EIGHT_4) >= 0;
- }
-
- @Override
- public boolean supportsElementaryOlapOperations() {
- return getDatabaseVersion().compareTo(EIGHT_4) >= 0;
- }
-
- @Override
- public boolean supportsWindowDistinctAggregates() {
- return false;
- }
-
- @Override
- public boolean supportsSimilarTo() {
- return true;
- }
-
- @Override
- public boolean supportsLikeRegex() {
- return true;
- }
-
- @Override
- public boolean supportsOnlyFormatLiterals() {
- return true;
- }
-
- @Override
- public boolean supportsFormatLiteral(String literal,
- org.teiid.translator.ExecutionFactory.Format format) {
- if (format == Format.NUMBER) {
- return false;
- }
- return OracleFormatFunctionModifier.supportsLiteral(literal);
- }
-
+ public String translateLiteralBoolean(Boolean booleanValue) {
+ if(booleanValue.booleanValue()) {
+ return "TRUE"; //$NON-NLS-1$
+ }
+ return "FALSE"; //$NON-NLS-1$
+ }
+
+ @Override
+ public String translateLiteralDate(Date dateValue) {
+ return "DATE '" + formatDateValue(dateValue) + "'"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTime(Time timeValue) {
+ return "TIME '" + formatDateValue(timeValue) + "'"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTimestamp(Timestamp timestampValue) {
+ return "TIMESTAMP '" + formatDateValue(timestampValue) + "'"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public int getTimestampNanoPrecision() {
+ return 6;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<?> translateLimit(Limit limit, ExecutionContext context) {
+ if (limit.getRowOffset() > 0) {
+ return Arrays.asList("LIMIT ", limit.getRowLimit(), " OFFSET ", limit.getRowOffset()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
+ }
+
+ /**
+ * Postgres doesn't provide min/max(boolean), so this conversion writes a min(BooleanValue) as
+ * bool_and(BooleanValue)
+ * @see org.teiid.language.visitor.LanguageObjectVisitor#visit(org.teiid.language.AggregateFunction)
+ * @since 4.3
+ */
+ @Override
+ public List<?> translate(LanguageObject obj, ExecutionContext context) {
+ if (obj instanceof AggregateFunction) {
+ AggregateFunction agg = (AggregateFunction)obj;
+ if (agg.getExpression() != null && TypeFacility.RUNTIME_TYPES.BOOLEAN.equals(agg.getExpression().getType())) {
+ if (agg.getName().equalsIgnoreCase(NonReserved.MIN)) {
+ agg.setName("bool_and"); //$NON-NLS-1$
+ } else if (agg.getName().equalsIgnoreCase(NonReserved.MAX)) {
+ agg.setName("bool_or"); //$NON-NLS-1$
+ }
+ }
+ } else if (obj instanceof Like) {
+ Like like = (Like)obj;
+ if (like.getMode() == MatchMode.REGEX) {
+ return Arrays.asList(like.getLeftExpression(), like.isNegated()?" !~ ":" ~ ", like.getRightExpression()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ return super.translate(obj, context);
+ }
+
+ @Override
+ public NullOrder getDefaultNullOrder() {
+ return NullOrder.HIGH;
+ }
+
+ @Override
+ public boolean supportsOrderByNullOrdering() {
+ return getVersion().compareTo(EIGHT_4) >= 0;
+ }
+
+ @Override
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
+ supportedFunctions.addAll(super.getSupportedFunctions());
+
+ supportedFunctions.add("ABS"); //$NON-NLS-1$
+ supportedFunctions.add("ACOS"); //$NON-NLS-1$
+ supportedFunctions.add("ASIN"); //$NON-NLS-1$
+ supportedFunctions.add("ATAN"); //$NON-NLS-1$
+ supportedFunctions.add("ATAN2"); //$NON-NLS-1$
+ supportedFunctions.add("BITAND"); //$NON-NLS-1$
+ supportedFunctions.add("BITNOT"); //$NON-NLS-1$
+ supportedFunctions.add("BITOR"); //$NON-NLS-1$
+ supportedFunctions.add("BITXOR"); //$NON-NLS-1$
+ supportedFunctions.add("CEILING"); //$NON-NLS-1$
+ supportedFunctions.add("COS"); //$NON-NLS-1$
+ supportedFunctions.add("COT"); //$NON-NLS-1$
+ supportedFunctions.add("DEGREES"); //$NON-NLS-1$
+ supportedFunctions.add("EXP"); //$NON-NLS-1$
+ supportedFunctions.add("FLOOR"); //$NON-NLS-1$
+ // These should not be pushed down since the grammar for string conversion is different
+// supportedFunctions.add("FORMATBIGDECIMAL"); //$NON-NLS-1$
+// supportedFunctions.add("FORMATBIGINTEGER"); //$NON-NLS-1$
+// supportedFunctions.add("FORMATDOUBLE"); //$NON-NLS-1$
+// supportedFunctions.add("FORMATFLOAT"); //$NON-NLS-1$
+// supportedFunctions.add("FORMATINTEGER"); //$NON-NLS-1$
+// supportedFunctions.add("FORMATLONG"); //$NON-NLS-1$
+ supportedFunctions.add("LOG"); //$NON-NLS-1$
+ supportedFunctions.add("LOG10"); //$NON-NLS-1$
+ supportedFunctions.add("MOD"); //$NON-NLS-1$
+ supportedFunctions.add("PI"); //$NON-NLS-1$
+ supportedFunctions.add("POWER"); //$NON-NLS-1$
+ supportedFunctions.add("RADIANS"); //$NON-NLS-1$
+ supportedFunctions.add("ROUND"); //$NON-NLS-1$
+ supportedFunctions.add("SIGN"); //$NON-NLS-1$
+ supportedFunctions.add("SIN"); //$NON-NLS-1$
+ supportedFunctions.add("SQRT"); //$NON-NLS-1$
+ supportedFunctions.add("TAN"); //$NON-NLS-1$
+
+ supportedFunctions.add("ASCII"); //$NON-NLS-1$
+ supportedFunctions.add("CHR"); //$NON-NLS-1$
+ supportedFunctions.add("CHAR"); //$NON-NLS-1$
+ supportedFunctions.add("||"); //$NON-NLS-1$
+ supportedFunctions.add("CONCAT"); //$NON-NLS-1$
+ supportedFunctions.add("INITCAP"); //$NON-NLS-1$
+ supportedFunctions.add("LCASE"); //$NON-NLS-1$
+ supportedFunctions.add("LEFT"); //$NON-NLS-1$
+ supportedFunctions.add("LENGTH"); //$NON-NLS-1$
+ supportedFunctions.add("LOCATE"); //$NON-NLS-1$
+ supportedFunctions.add("LOWER"); //$NON-NLS-1$
+ supportedFunctions.add("LPAD"); //$NON-NLS-1$
+ supportedFunctions.add("LTRIM"); //$NON-NLS-1$
+ supportedFunctions.add("REPEAT"); //$NON-NLS-1$
+ supportedFunctions.add("REPLACE"); //$NON-NLS-1$
+ supportedFunctions.add("RIGHT"); //$NON-NLS-1$
+ supportedFunctions.add("RPAD"); //$NON-NLS-1$
+ supportedFunctions.add("RTRIM"); //$NON-NLS-1$
+ supportedFunctions.add("SUBSTRING"); //$NON-NLS-1$
+ supportedFunctions.add(SourceSystemFunctions.TRIM);
+ supportedFunctions.add("UCASE"); //$NON-NLS-1$
+ supportedFunctions.add("UPPER"); //$NON-NLS-1$
+
+ // These are executed within the server and never pushed down
+// supportedFunctions.add("CURDATE"); //$NON-NLS-1$
+// supportedFunctions.add("CURTIME"); //$NON-NLS-1$
+// supportedFunctions.add("NOW"); //$NON-NLS-1$
+ supportedFunctions.add("DAYNAME"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFMONTH"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFWEEK"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFYEAR"); //$NON-NLS-1$
+ // These should not be pushed down since the grammar for string conversion is different
+// supportedFunctions.add("FORMATDATE"); //$NON-NLS-1$
+// supportedFunctions.add("FORMATTIME"); //$NON-NLS-1$
+// supportedFunctions.add("FORMATTIMESTAMP"); //$NON-NLS-1$
+ supportedFunctions.add("HOUR"); //$NON-NLS-1$
+ supportedFunctions.add("MINUTE"); //$NON-NLS-1$
+ supportedFunctions.add("MONTH"); //$NON-NLS-1$
+ supportedFunctions.add("MONTHNAME"); //$NON-NLS-1$
+ // These should not be pushed down since the grammar for string conversion is different
+// supportedFunctions.add("PARSEDATE"); //$NON-NLS-1$
+// supportedFunctions.add("PARSETIME"); //$NON-NLS-1$
+// supportedFunctions.add("PARSETIMESTAMP"); //$NON-NLS-1$
+ supportedFunctions.add("QUARTER"); //$NON-NLS-1$
+ supportedFunctions.add("SECOND"); //$NON-NLS-1$
+ if (this.getVersion().compareTo(EIGHT_2) >= 0) {
+ supportedFunctions.add("TIMESTAMPADD"); //$NON-NLS-1$
+ supportedFunctions.add("TIMESTAMPDIFF"); //$NON-NLS-1$
+ }
+ supportedFunctions.add("WEEK"); //$NON-NLS-1$
+ supportedFunctions.add("YEAR"); //$NON-NLS-1$
+
+ supportedFunctions.add("CAST"); //$NON-NLS-1$
+ supportedFunctions.add("CONVERT"); //$NON-NLS-1$
+ supportedFunctions.add("IFNULL"); //$NON-NLS-1$
+ supportedFunctions.add("NVL"); //$NON-NLS-1$
+
+ // Additional functions
+// // Math
+// supportedFunctions.add("%"); //$NON-NLS-1$
+// supportedFunctions.add("^"); //$NON-NLS-1$
+// supportedFunctions.add("|/"); //$NON-NLS-1$
+// supportedFunctions.add("||/"); //$NON-NLS-1$
+// supportedFunctions.add("!"); //$NON-NLS-1$
+// supportedFunctions.add("!!"); //$NON-NLS-1$
+// supportedFunctions.add("@"); //$NON-NLS-1$
+// // Bit manipulation
+// supportedFunctions.add("&"); //$NON-NLS-1$
+// supportedFunctions.add("|"); //$NON-NLS-1$
+// supportedFunctions.add("#"); //$NON-NLS-1$
+// supportedFunctions.add("~"); //$NON-NLS-1$
+// supportedFunctions.add("<<"); //$NON-NLS-1$
+// supportedFunctions.add(">>"); //$NON-NLS-1$
+//
+// supportedFunctions.add("CBRT"); //$NON-NLS-1$
+// supportedFunctions.add("CEIL"); //$NON-NLS-1$
+// supportedFunctions.add("LN"); //$NON-NLS-1$
+// supportedFunctions.add("MOD"); //$NON-NLS-1$
+// supportedFunctions.add("RANDOM"); //$NON-NLS-1$
+// supportedFunctions.add("SETSEED"); //$NON-NLS-1$
+// supportedFunctions.add("TRUNC"); //$NON-NLS-1$
+// supportedFunctions.add("WIDTH_BUCKET"); //$NON-NLS-1$
+//
+// // String
+// supportedFunctions.add("BIT_LENGTH"); //$NON-NLS-1$
+// supportedFunctions.add("BTRIM"); //$NON-NLS-1$
+// supportedFunctions.add("CHAR_LENGTH"); //$NON-NLS-1$
+// supportedFunctions.add("CHARACTER_LENGTH"); //$NON-NLS-1$
+// supportedFunctions.add("DECODE"); //$NON-NLS-1$
+// supportedFunctions.add("ENCODE"); //$NON-NLS-1$
+// supportedFunctions.add("MD5"); //$NON-NLS-1$
+// supportedFunctions.add("OCTET_LENGTH"); //$NON-NLS-1$
+// supportedFunctions.add("PG_CLIENT_ENCODING"); //$NON-NLS-1$
+// supportedFunctions.add("QUOTE_IDENT"); //$NON-NLS-1$
+// supportedFunctions.add("QUOTE_LITERAL"); //$NON-NLS-1$
+// supportedFunctions.add("SPLIT_PART"); //$NON-NLS-1$
+// supportedFunctions.add("STRPOS"); //$NON-NLS-1$
+// supportedFunctions.add("SUBSTR"); //$NON-NLS-1$
+// supportedFunctions.add("TO_ASCII"); //$NON-NLS-1$
+// supportedFunctions.add("TO_HEX"); //$NON-NLS-1$
+// supportedFunctions.add("TRANSLATE"); //$NON-NLS-1$
+//
+// // Bit operations
+// supportedFunctions.add("GET_BIT"); //$NON-NLS-1$
+// supportedFunctions.add("GET_BYTE"); //$NON-NLS-1$
+// supportedFunctions.add("SET_BIT"); //$NON-NLS-1$
+// supportedFunctions.add("SET_BYTE"); //$NON-NLS-1$
+//
+// // Formatting
+// supportedFunctions.add("TO_CHAR"); //$NON-NLS-1$
+// supportedFunctions.add("TO_DATE"); //$NON-NLS-1$
+// supportedFunctions.add("TO_TIMESTAMP"); //$NON-NLS-1$
+// supportedFunctions.add("TO_NUMBER"); //$NON-NLS-1$
+//
+// // Date / Time
+// supportedFunctions.add("AGE"); //$NON-NLS-1$
+// supportedFunctions.add("CURRENT_DATE"); //$NON-NLS-1$ // no ()
+// supportedFunctions.add("CURRENT_TIME"); //$NON-NLS-1$ // no ()
+// supportedFunctions.add("CURRENT_TIMESTAMP"); //$NON-NLS-1$ // no ()
+// supportedFunctions.add("DATE_PART"); //$NON-NLS-1$
+// supportedFunctions.add("DATE_TRUNC"); //$NON-NLS-1$
+// supportedFunctions.add("ISFINITE"); //$NON-NLS-1$
+// supportedFunctions.add("JUSTIFY_HOURS"); //$NON-NLS-1$
+// supportedFunctions.add("JUSTIFY_DAYS"); //$NON-NLS-1$
+// supportedFunctions.add("LOCALTIME"); //$NON-NLS-1$ // no ()
+// supportedFunctions.add("LOCALTIMESTAMP"); //$NON-NLS-1$ // no ()
+// supportedFunctions.add("TIMEOFDAY"); //$NON-NLS-1$
+//
+// // Conditional
+ supportedFunctions.add("COALESCE"); //$NON-NLS-1$
+// supportedFunctions.add("NULLIF"); //$NON-NLS-1$
+// supportedFunctions.add("GREATEST"); //$NON-NLS-1$
+// supportedFunctions.add("LEAST"); //$NON-NLS-1$
+//
+// // Network Addresses
+//// supportedFunctions.add("BROADCAST"); //$NON-NLS-1$
+//// supportedFunctions.add("HOST"); //$NON-NLS-1$
+//// supportedFunctions.add("MASKLEN"); //$NON-NLS-1$
+//// supportedFunctions.add("SET_MASKLEN"); //$NON-NLS-1$
+//// supportedFunctions.add("NETMASK"); //$NON-NLS-1$
+//// supportedFunctions.add("HOSTMASK"); //$NON-NLS-1$
+//// supportedFunctions.add("NETWORK"); //$NON-NLS-1$
+//// supportedFunctions.add("TEXT"); //$NON-NLS-1$
+//// supportedFunctions.add("ABBREV"); //$NON-NLS-1$
+//// supportedFunctions.add("FAMILY"); //$NON-NLS-1$
+//// supportedFunctions.add("TRUNC"); //$NON-NLS-1$
+//
+// // Set generator
+// supportedFunctions.add("GENERATE_SERIES"); //$NON-NLS-1$
+//
+// // Information
+// supportedFunctions.add("CURRENT_DATABASE"); //$NON-NLS-1$
+// supportedFunctions.add("CURRENT_SCHEMA"); //$NON-NLS-1$
+// supportedFunctions.add("CURRENT_SCHEMAS"); //$NON-NLS-1$
+// supportedFunctions.add("CURRENT_USER"); //$NON-NLS-1$ // no ()
+// supportedFunctions.add("INET_CLIENT_ADDR"); //$NON-NLS-1$
+// supportedFunctions.add("INET_CLIENT_PORT"); //$NON-NLS-1$
+// supportedFunctions.add("INET_SERVER_ADDR"); //$NON-NLS-1$
+// supportedFunctions.add("INET_SERVER_PORT"); //$NON-NLS-1$
+// supportedFunctions.add("SESSION_USER"); //$NON-NLS-1$ // no ()
+// supportedFunctions.add("USER"); //$NON-NLS-1$ // no ()
+// supportedFunctions.add("VERSION"); //$NON-NLS-1$
+//
+ supportedFunctions.add(SourceSystemFunctions.ARRAY_GET);
+ supportedFunctions.add(SourceSystemFunctions.ARRAY_LENGTH);
+ supportedFunctions.add(SourceSystemFunctions.FORMATTIMESTAMP);
+ supportedFunctions.add(SourceSystemFunctions.PARSETIMESTAMP);
+ return supportedFunctions;
+ }
+
+ /**
+ * This is true only after Postgre version 7.1
+ * However, since version 7 was released in 2000 we'll assume a post 7 instance.
+ */
+ public boolean supportsInlineViews() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsRowLimit() {
+ return true;
+ }
+ @Override
+ public boolean supportsRowOffset() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsExcept() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsIntersect() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return getVersion().compareTo(EIGHT_2) >= 0;
+ }
+
+ @Override
+ public boolean supportsCommonTableExpressions() {
+ return getVersion().compareTo(EIGHT_4) >= 0;
+ }
+
+ @Override
+ public boolean supportsArrayAgg() {
+ return getVersion().compareTo(EIGHT_4) >= 0;
+ }
+
+ @Override
+ public boolean supportsElementaryOlapOperations() {
+ return getVersion().compareTo(EIGHT_4) >= 0;
+ }
+
+ @Override
+ public boolean supportsWindowDistinctAggregates() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSimilarTo() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsLikeRegex() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsOnlyFormatLiterals() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsFormatLiteral(String literal,
+ org.teiid.translator.ExecutionFactory.Format format) {
+ if (format == Format.NUMBER) {
+ return false;
+ }
+ return OracleFormatFunctionModifier.supportsLiteral(literal);
+ }
+
}
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -42,6 +42,7 @@
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
import org.teiid.translator.jdbc.sybase.SybaseExecutionFactory;
+import org.teiid.translator.jdbc.Version;
/**
* Updated to assume the use of the DataDirect, 2005 driver, or later.
@@ -49,8 +50,15 @@
@Translator(name="sqlserver", description="A translator for Microsoft SQL Server Database")
public class SQLServerExecutionFactory extends SybaseExecutionFactory {
- public static final String V_2005 = "2005"; //$NON-NLS-1$
- public static final String V_2008 = "2008"; //$NON-NLS-1$
+ public static final String V_2000 = "2000"; //$NON-NLS-1$
+ public static final String V_2005 = "2005"; //$NON-NLS-1$
+ public static final String V_2008 = "2008"; //$NON-NLS-1$
+ public static final String V_2012 = "2012"; //$NON-NLS-1$
+
+ public static final Version SEVEN_0 = Version.getVersion("7.0"); //$NON-NLS-1$
+ public static final Version NINE_0 = Version.getVersion("9.0"); //$NON-NLS-1$
+ public static final Version TEN_0 = Version.getVersion("10.0"); //$NON-NLS-1$
+ public static final Version ELEVEN_0 = Version.getVersion("11.0"); //$NON-NLS-1$
//TEIID-31 remove mod modifier for SQL Server 2008
public SQLServerExecutionFactory() {
@@ -235,9 +243,32 @@
return true;
}
+ /**
+ * Overriden to allow for year based versions
+ */
+ @Override
+ public void setDatabaseVersion(String version) {
+ if (version != null) {
+ if (version.equals(V_2000)) {
+ setDatabaseVersion(SEVEN_0);
+ return;
+ } else if (version.equals(V_2005)) {
+ setDatabaseVersion(NINE_0);
+ return;
+ } else if (version.equals(V_2008)) {
+ setDatabaseVersion(TEN_0);
+ return;
+ } else if (version.equals(V_2012)) {
+ setDatabaseVersion(ELEVEN_0);
+ return;
+ }
+ }
+ super.setDatabaseVersion(version);
+ }
+
@Override
public String translateLiteralDate(Date dateValue) {
- if (getDatabaseVersion().compareTo(V_2008) >= 0) {
+ if (getVersion().compareTo(TEN_0) >= 0) {
return super.translateLiteralDate(dateValue);
}
return super.translateLiteralTimestamp(new Timestamp(dateValue.getTime()));
@@ -245,7 +276,7 @@
@Override
public boolean hasTimeType() {
- return getDatabaseVersion().compareTo(V_2008) >= 0;
+ return getVersion().compareTo(TEN_0) >= 0;
}
@Override
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -1,370 +1,371 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
*/
+
+/*
+ */
package org.teiid.translator.jdbc.sybase;
-import java.sql.Date;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.Literal;
-import org.teiid.language.SQLConstants;
-import org.teiid.translator.SourceSystemFunctions;
-import org.teiid.translator.Translator;
-import org.teiid.translator.TranslatorException;
-import org.teiid.translator.jdbc.AliasModifier;
-import org.teiid.translator.jdbc.ConvertModifier;
-import org.teiid.translator.jdbc.EscapeSyntaxModifier;
-import org.teiid.translator.jdbc.FunctionModifier;
-import org.teiid.translator.jdbc.ModFunctionModifier;
-import org.teiid.translator.jdbc.ParseFormatFunctionModifier;
-import org.teiid.translator.jdbc.oracle.ConcatFunctionModifier;
-
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.teiid.language.Expression;
+import org.teiid.language.Function;
+import org.teiid.language.Literal;
+import org.teiid.language.SQLConstants;
+import org.teiid.translator.SourceSystemFunctions;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.jdbc.AliasModifier;
+import org.teiid.translator.jdbc.ConvertModifier;
+import org.teiid.translator.jdbc.EscapeSyntaxModifier;
+import org.teiid.translator.jdbc.FunctionModifier;
+import org.teiid.translator.jdbc.ModFunctionModifier;
+import org.teiid.translator.jdbc.ParseFormatFunctionModifier;
+import org.teiid.translator.jdbc.oracle.ConcatFunctionModifier;
+import org.teiid.translator.jdbc.Version;
+
+
@Translator(name="sybase", description="A translator for Sybase Database")
-public class SybaseExecutionFactory extends BaseSybaseExecutionFactory {
-
- public static final String TWELVE_5_3 = "12.5.3"; //$NON-NLS-1$
- public static final String TWELVE_5 = "12.5"; //$NON-NLS-1$
- public static final String FIFTEEN_0_2 = "15.0.2"; //$NON-NLS-1$
- public static final String FIFTEEN_5 = "15.5"; //$NON-NLS-1$
-
- protected Map<String, Integer> formatMap = new HashMap<String, Integer>();
-
- public SybaseExecutionFactory() {
- setDatabaseVersion(TWELVE_5);
- setSupportsFullOuterJoins(false);
- setMaxInCriteriaSize(250);
- setMaxDependentInPredicates(10);
- populateDateFormats();
- }
-
- protected void populateDateFormats() {
- formatMap.put("MM/dd/yy", 1); //$NON-NLS-1$
- formatMap.put("yy.MM.dd", 2); //$NON-NLS-1$
- formatMap.put("dd/MM/yy", 3); //$NON-NLS-1$
- formatMap.put("dd.MM.yy", 4); //$NON-NLS-1$
- formatMap.put("dd-MM-yy", 5); //$NON-NLS-1$
- formatMap.put("dd MMM yy", 6); //$NON-NLS-1$
- formatMap.put("MMM dd, yy", 7); //$NON-NLS-1$
- formatMap.put("MM-dd-yy", 10); //$NON-NLS-1$
- formatMap.put("yy/MM/dd", 11); //$NON-NLS-1$
- formatMap.put("yyMMdd", 12); //$NON-NLS-1$
- formatMap.put("yyddMM", 13); //$NON-NLS-1$
- formatMap.put("MM/yy/dd", 14); //$NON-NLS-1$
- formatMap.put("dd/yy/MM", 15); //$NON-NLS-1$
- formatMap.put("MMM dd yy HH:mm:ss", 16); //$NON-NLS-1$
- for (Map.Entry<String, Integer> entry : new HashSet<Map.Entry<String, Integer>>(formatMap.entrySet())) {
- formatMap.put(entry.getKey().replace("yy", "yyyy"), entry.getValue() + 100); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- formatMap.put("MMM d yyyy hh:mma", 100); //$NON-NLS-1$
- formatMap.put("HH:mm:ss", 8); //$NON-NLS-1$
- formatMap.put("MMM d yyyy hh:mm:ss:SSSa", 109); //$NON-NLS-1$
- formatMap.put("hh:mma", 17); //$NON-NLS-1$
- formatMap.put("HH:mm", 18); //$NON-NLS-1$
- formatMap.put("hh:mm:ss:SSSa", 19); //$NON-NLS-1$
- formatMap.put("HH:mm:ss:SSS", 20); //$NON-NLS-1$
- formatMap.put("yy/MM/dd HH:mm:ss", 21); //$NON-NLS-1$
- formatMap.put("yy/MM/dd hh:mm:ssa", 22); //$NON-NLS-1$
- formatMap.put("yyyy-MM-dd'T'HH:mm:ss", 23); //$NON-NLS-1$
- }
+public class SybaseExecutionFactory extends BaseSybaseExecutionFactory {
+
+ public static final Version TWELVE_5_3 = Version.getVersion("12.5.3"); //$NON-NLS-1$
+ public static final Version TWELVE_5 = Version.getVersion("12.5"); //$NON-NLS-1$
+ public static final Version FIFTEEN_0_2 = Version.getVersion("15.0.2"); //$NON-NLS-1$
+ public static final Version FIFTEEN_5 = Version.getVersion("15.5"); //$NON-NLS-1$
+
+ protected Map<String, Integer> formatMap = new HashMap<String, Integer>();
+
+ public SybaseExecutionFactory() {
+ setDatabaseVersion(TWELVE_5);
+ setSupportsFullOuterJoins(false);
+ setMaxInCriteriaSize(250);
+ setMaxDependentInPredicates(10);
+ populateDateFormats();
+ }
+
+ protected void populateDateFormats() {
+ formatMap.put("MM/dd/yy", 1); //$NON-NLS-1$
+ formatMap.put("yy.MM.dd", 2); //$NON-NLS-1$
+ formatMap.put("dd/MM/yy", 3); //$NON-NLS-1$
+ formatMap.put("dd.MM.yy", 4); //$NON-NLS-1$
+ formatMap.put("dd-MM-yy", 5); //$NON-NLS-1$
+ formatMap.put("dd MMM yy", 6); //$NON-NLS-1$
+ formatMap.put("MMM dd, yy", 7); //$NON-NLS-1$
+ formatMap.put("MM-dd-yy", 10); //$NON-NLS-1$
+ formatMap.put("yy/MM/dd", 11); //$NON-NLS-1$
+ formatMap.put("yyMMdd", 12); //$NON-NLS-1$
+ formatMap.put("yyddMM", 13); //$NON-NLS-1$
+ formatMap.put("MM/yy/dd", 14); //$NON-NLS-1$
+ formatMap.put("dd/yy/MM", 15); //$NON-NLS-1$
+ formatMap.put("MMM dd yy HH:mm:ss", 16); //$NON-NLS-1$
+ for (Map.Entry<String, Integer> entry : new HashSet<Map.Entry<String, Integer>>(formatMap.entrySet())) {
+ formatMap.put(entry.getKey().replace("yy", "yyyy"), entry.getValue() + 100); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ formatMap.put("MMM d yyyy hh:mma", 100); //$NON-NLS-1$
+ formatMap.put("HH:mm:ss", 8); //$NON-NLS-1$
+ formatMap.put("MMM d yyyy hh:mm:ss:SSSa", 109); //$NON-NLS-1$
+ formatMap.put("hh:mma", 17); //$NON-NLS-1$
+ formatMap.put("HH:mm", 18); //$NON-NLS-1$
+ formatMap.put("hh:mm:ss:SSSa", 19); //$NON-NLS-1$
+ formatMap.put("HH:mm:ss:SSS", 20); //$NON-NLS-1$
+ formatMap.put("yy/MM/dd HH:mm:ss", 21); //$NON-NLS-1$
+ formatMap.put("yy/MM/dd hh:mm:ssa", 22); //$NON-NLS-1$
+ formatMap.put("yyyy-MM-dd'T'HH:mm:ss", 23); //$NON-NLS-1$
+ }
public void start() throws TranslatorException {
- super.start();
+ super.start();
- registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("%", getLanguageFactory())); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("%", getLanguageFactory())); //$NON-NLS-1$
if (nullPlusNonNullIsNull()) {
- registerFunctionModifier(SourceSystemFunctions.CONCAT, new AliasModifier("+")); //$NON-NLS-1$
- } else {
- registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()) {
- @Override
- public List<?> translate(Function function) {
- function.setName("+"); //$NON-NLS-1$
- return super.translate(function);
- }
- });
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new AliasModifier("+")); //$NON-NLS-1$
+ } else {
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()) {
+ @Override
+ public List<?> translate(Function function) {
+ function.setName("+"); //$NON-NLS-1$
+ return super.translate(function);
+ }
+ });
}
registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("isnull")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.REPEAT, new AliasModifier("replicate")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new SubstringFunctionModifier(getLanguageFactory()));
- registerFunctionModifier(SourceSystemFunctions.DAYNAME, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.HOUR, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.MINUTE, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.QUARTER, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.SECOND, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.WEEK, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.LENGTH, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.ATAN2, new EscapeSyntaxModifier());
- registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier() {
-
- @Override
- public List<?> translate(Function function) {
- if (!isFracSeconds(function)) {
- return super.translate(function);
- }
- //convert from billionths to thousandths
- return Arrays.asList("dateadd(millisecond, ", function.getParameters().get(1), "/1000000, ", function.getParameters().get(2), ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- });
- registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier() {
-
- @Override
- public List<?> translate(Function function) {
- if (!isFracSeconds(function)) {
- return super.translate(function);
- }
- //convert from billionths to thousandths
- return Arrays.asList("datediff(millisecond, ", function.getParameters().get(1), ",", function.getParameters().get(2), ")*1000000"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- });
-
- //add in type conversion
- ConvertModifier convertModifier = new ConvertModifier();
- convertModifier.setBooleanNullable(booleanNullable());
- //boolean isn't treated as bit, since it doesn't support null
- //byte is treated as smallint, since tinyint is unsigned
- convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT); //$NON-NLS-1$
- convertModifier.addTypeMapping("int", FunctionModifier.INTEGER); //$NON-NLS-1$
- convertModifier.addTypeMapping("numeric(19,0)", FunctionModifier.LONG); //$NON-NLS-1$
- convertModifier.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
- convertModifier.addTypeMapping("double precision", FunctionModifier.DOUBLE); //$NON-NLS-1$
- convertModifier.addTypeMapping("numeric(38, 0)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
- convertModifier.addTypeMapping("numeric(38, 19)", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
- convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
- convertModifier.addTypeMapping("varchar(40)", FunctionModifier.STRING); //$NON-NLS-1$
- convertModifier.addTypeMapping("datetime", FunctionModifier.DATE, FunctionModifier.TIME, FunctionModifier.TIMESTAMP); //$NON-NLS-1$
- convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- List<Object> result = new ArrayList<Object>();
- result.add("cast("); //$NON-NLS-1$
- boolean needsEnd = false;
- if (!nullPlusNonNullIsNull() && !ConcatFunctionModifier.isNotNull(function.getParameters().get(0))) {
- result.add("CASE WHEN "); //$NON-NLS-1$
- result.add(function.getParameters().get(0));
- result.add(" IS NOT NULL THEN "); //$NON-NLS-1$
- needsEnd = true;
- }
- result.add("'1970-01-01 ' + "); //$NON-NLS-1$
- result.addAll(convertTimeToString(function));
- if (needsEnd) {
- result.add(" END"); //$NON-NLS-1$
- }
- result.add(" AS datetime)"); //$NON-NLS-1$
- return result;
- }
- });
- convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- List<Object> result = new ArrayList<Object>();
- result.add("cast("); //$NON-NLS-1$
- result.addAll(convertDateToString(function));
- result.add(" AS datetime)"); //$NON-NLS-1$
- return result;
- }
- });
- convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- return convertTimeToString(function);
- }
- });
- convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- return convertDateToString(function);
- }
- });
- convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- return convertTimestampToString(function);
- }
- });
- convertModifier.addNumericBooleanConversions();
- registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
- registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new ParseFormatFunctionModifier("CONVERT(DATETIME, ") { //$NON-NLS-1$
- @Override
- protected Object translateFormat(String format) {
- return formatMap.get(format);
- }
- });
- registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new ParseFormatFunctionModifier("CONVERT(VARCHAR, ") { //$NON-NLS-1$
- @Override
- protected Object translateFormat(String format) {
- return formatMap.get(format);
- }
- });
- }
-
- private List<Object> convertTimeToString(Function function) {
- return Arrays.asList("convert(varchar, ", function.getParameters().get(0), ", 8)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected List<Object> convertDateToString(Function function) {
- return Arrays.asList("stuff(stuff(convert(varchar, ", function.getParameters().get(0), ", 102), 5, 1, '-'), 8, 1, '-')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- //TODO: this looses the milliseconds
- protected List<?> convertTimestampToString(Function function) {
- LinkedList<Object> result = new LinkedList<Object>();
- result.addAll(convertDateToString(function));
- result.add('+');
- result.addAll(convertTimeToString(function));
- return result;
- }
-
- @Override
- public List<String> getSupportedFunctions() {
- List<String> supportedFunctions = new ArrayList<String>();
- supportedFunctions.addAll(super.getSupportedFunctions());
- supportedFunctions.add("ABS"); //$NON-NLS-1$
- supportedFunctions.add("ACOS"); //$NON-NLS-1$
- supportedFunctions.add("ASIN"); //$NON-NLS-1$
- supportedFunctions.add("ATAN"); //$NON-NLS-1$
- supportedFunctions.add("ATAN2"); //$NON-NLS-1$
- supportedFunctions.add("COS"); //$NON-NLS-1$
- supportedFunctions.add("COT"); //$NON-NLS-1$
- supportedFunctions.add("DEGREES"); //$NON-NLS-1$
- supportedFunctions.add("EXP"); //$NON-NLS-1$
- supportedFunctions.add("FLOOR"); //$NON-NLS-1$
- supportedFunctions.add("LOG"); //$NON-NLS-1$
- supportedFunctions.add("LOG10"); //$NON-NLS-1$
- supportedFunctions.add("MOD"); //$NON-NLS-1$
- supportedFunctions.add("PI"); //$NON-NLS-1$
- supportedFunctions.add("POWER"); //$NON-NLS-1$
- supportedFunctions.add("RADIANS"); //$NON-NLS-1$
- supportedFunctions.add("SIGN"); //$NON-NLS-1$
- supportedFunctions.add("SIN"); //$NON-NLS-1$
- supportedFunctions.add("SQRT"); //$NON-NLS-1$
- supportedFunctions.add("TAN"); //$NON-NLS-1$
- supportedFunctions.add("ASCII"); //$NON-NLS-1$
- supportedFunctions.add("CHAR"); //$NON-NLS-1$
- supportedFunctions.add("CHR"); //$NON-NLS-1$
- supportedFunctions.add("CONCAT"); //$NON-NLS-1$
- supportedFunctions.add("||"); //$NON-NLS-1$
- supportedFunctions.add("LCASE"); //$NON-NLS-1$
- supportedFunctions.add("LEFT"); //$NON-NLS-1$
- supportedFunctions.add("LENGTH"); //$NON-NLS-1$
- supportedFunctions.add("LOWER"); //$NON-NLS-1$
- supportedFunctions.add("LTRIM"); //$NON-NLS-1$
- supportedFunctions.add("REPEAT"); //$NON-NLS-1$
- //supportedFunctions.add("RAND"); //$NON-NLS-1$
- supportedFunctions.add("RIGHT"); //$NON-NLS-1$
- supportedFunctions.add("RTRIM"); //$NON-NLS-1$
- supportedFunctions.add("SPACE"); //$NON-NLS-1$
- supportedFunctions.add("SUBSTRING"); //$NON-NLS-1$
- supportedFunctions.add("UCASE"); //$NON-NLS-1$
- supportedFunctions.add("UPPER"); //$NON-NLS-1$
- //supportedFunctons.add("CURDATE"); //$NON-NLS-1$
- //supportedFunctons.add("CURTIME"); //$NON-NLS-1$
- supportedFunctions.add("DAYNAME"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFMONTH"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFWEEK"); //$NON-NLS-1$
- supportedFunctions.add("DAYOFYEAR"); //$NON-NLS-1$
- supportedFunctions.add("HOUR"); //$NON-NLS-1$
- supportedFunctions.add("MINUTE"); //$NON-NLS-1$
- supportedFunctions.add("MONTH"); //$NON-NLS-1$
- supportedFunctions.add("MONTHNAME"); //$NON-NLS-1$
- //supportedFunctions.add("NOW"); //$NON-NLS-1$
- supportedFunctions.add("QUARTER"); //$NON-NLS-1$
- supportedFunctions.add("SECOND"); //$NON-NLS-1$
- supportedFunctions.add("TIMESTAMPADD"); //$NON-NLS-1$
- supportedFunctions.add("TIMESTAMPDIFF"); //$NON-NLS-1$
- supportedFunctions.add("WEEK"); //$NON-NLS-1$
- supportedFunctions.add("YEAR"); //$NON-NLS-1$
- supportedFunctions.add("CAST"); //$NON-NLS-1$
- supportedFunctions.add("CONVERT"); //$NON-NLS-1$
- supportedFunctions.add("IFNULL"); //$NON-NLS-1$
- supportedFunctions.add("NVL"); //$NON-NLS-1$
- //supportedFunctions.add("FORMATTIMESTAMP"); //$NON-NLS-1$
-
- return supportedFunctions;
- }
-
- @Override
- public boolean supportsInlineViews() {
- return true;
- }
-
- @Override
- public boolean supportsFunctionsInGroupBy() {
- return true;
- }
-
- @Override
- public int getMaxFromGroups() {
- return 50;
- }
-
- @Override
- public boolean supportsAggregatesEnhancedNumeric() {
- return getDatabaseVersion().compareTo(FIFTEEN_0_2) >= 0;
- }
-
- public boolean nullPlusNonNullIsNull() {
- return false;
- }
-
- public boolean booleanNullable() {
- return false;
- }
-
- @Override
- public String translateLiteralTimestamp(Timestamp timestampValue) {
- return "CAST('" + formatDateValue(timestampValue) +"' AS DATETIME)"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Override
- public String translateLiteralDate(Date dateValue) {
- return "CAST('" + formatDateValue(dateValue) +"' AS DATE)"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private boolean isFracSeconds(Function function) {
- Expression e = function.getParameters().get(0);
- return (e instanceof Literal && SQLConstants.NonReserved.SQL_TSI_FRAC_SECOND.equalsIgnoreCase((String)((Literal)e).getValue()));
- }
-
- @Override
- public boolean supportsRowLimit() {
- return (getDatabaseVersion().startsWith("12") && getDatabaseVersion().compareTo(TWELVE_5_3) >= 0) || getDatabaseVersion().compareTo(FIFTEEN_0_2) >=0; //$NON-NLS-1$
- }
-
+ registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.REPEAT, new AliasModifier("replicate")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new SubstringFunctionModifier(getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.DAYNAME, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.HOUR, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.MINUTE, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.QUARTER, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.SECOND, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.WEEK, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.LENGTH, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.ATAN2, new EscapeSyntaxModifier());
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier() {
+
+ @Override
+ public List<?> translate(Function function) {
+ if (!isFracSeconds(function)) {
+ return super.translate(function);
+ }
+ //convert from billionths to thousandths
+ return Arrays.asList("dateadd(millisecond, ", function.getParameters().get(1), "/1000000, ", function.getParameters().get(2), ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ });
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier() {
+
+ @Override
+ public List<?> translate(Function function) {
+ if (!isFracSeconds(function)) {
+ return super.translate(function);
+ }
+ //convert from billionths to thousandths
+ return Arrays.asList("datediff(millisecond, ", function.getParameters().get(1), ",", function.getParameters().get(2), ")*1000000"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ });
+
+ //add in type conversion
+ ConvertModifier convertModifier = new ConvertModifier();
+ convertModifier.setBooleanNullable(booleanNullable());
+ //boolean isn't treated as bit, since it doesn't support null
+ //byte is treated as smallint, since tinyint is unsigned
+ convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT); //$NON-NLS-1$
+ convertModifier.addTypeMapping("int", FunctionModifier.INTEGER); //$NON-NLS-1$
+ convertModifier.addTypeMapping("numeric(19,0)", FunctionModifier.LONG); //$NON-NLS-1$
+ convertModifier.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
+ convertModifier.addTypeMapping("double precision", FunctionModifier.DOUBLE); //$NON-NLS-1$
+ convertModifier.addTypeMapping("numeric(38, 0)", FunctionModifier.BIGINTEGER); //$NON-NLS-1$
+ convertModifier.addTypeMapping("numeric(38, 19)", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
+ convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
+ convertModifier.addTypeMapping("varchar(40)", FunctionModifier.STRING); //$NON-NLS-1$
+ convertModifier.addTypeMapping("datetime", FunctionModifier.DATE, FunctionModifier.TIME, FunctionModifier.TIMESTAMP); //$NON-NLS-1$
+ convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ List<Object> result = new ArrayList<Object>();
+ result.add("cast("); //$NON-NLS-1$
+ boolean needsEnd = false;
+ if (!nullPlusNonNullIsNull() && !ConcatFunctionModifier.isNotNull(function.getParameters().get(0))) {
+ result.add("CASE WHEN "); //$NON-NLS-1$
+ result.add(function.getParameters().get(0));
+ result.add(" IS NOT NULL THEN "); //$NON-NLS-1$
+ needsEnd = true;
+ }
+ result.add("'1970-01-01 ' + "); //$NON-NLS-1$
+ result.addAll(convertTimeToString(function));
+ if (needsEnd) {
+ result.add(" END"); //$NON-NLS-1$
+ }
+ result.add(" AS datetime)"); //$NON-NLS-1$
+ return result;
+ }
+ });
+ convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ List<Object> result = new ArrayList<Object>();
+ result.add("cast("); //$NON-NLS-1$
+ result.addAll(convertDateToString(function));
+ result.add(" AS datetime)"); //$NON-NLS-1$
+ return result;
+ }
+ });
+ convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ return convertTimeToString(function);
+ }
+ });
+ convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ return convertDateToString(function);
+ }
+ });
+ convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ return convertTimestampToString(function);
+ }
+ });
+ convertModifier.addNumericBooleanConversions();
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
+ registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new ParseFormatFunctionModifier("CONVERT(DATETIME, ") { //$NON-NLS-1$
+ @Override
+ protected Object translateFormat(String format) {
+ return formatMap.get(format);
+ }
+ });
+ registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new ParseFormatFunctionModifier("CONVERT(VARCHAR, ") { //$NON-NLS-1$
+ @Override
+ protected Object translateFormat(String format) {
+ return formatMap.get(format);
+ }
+ });
+ }
+
+ private List<Object> convertTimeToString(Function function) {
+ return Arrays.asList("convert(varchar, ", function.getParameters().get(0), ", 8)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ protected List<Object> convertDateToString(Function function) {
+ return Arrays.asList("stuff(stuff(convert(varchar, ", function.getParameters().get(0), ", 102), 5, 1, '-'), 8, 1, '-')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ //TODO: this looses the milliseconds
+ protected List<?> convertTimestampToString(Function function) {
+ LinkedList<Object> result = new LinkedList<Object>();
+ result.addAll(convertDateToString(function));
+ result.add('+');
+ result.addAll(convertTimeToString(function));
+ return result;
+ }
+
+ @Override
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
+ supportedFunctions.addAll(super.getSupportedFunctions());
+ supportedFunctions.add("ABS"); //$NON-NLS-1$
+ supportedFunctions.add("ACOS"); //$NON-NLS-1$
+ supportedFunctions.add("ASIN"); //$NON-NLS-1$
+ supportedFunctions.add("ATAN"); //$NON-NLS-1$
+ supportedFunctions.add("ATAN2"); //$NON-NLS-1$
+ supportedFunctions.add("COS"); //$NON-NLS-1$
+ supportedFunctions.add("COT"); //$NON-NLS-1$
+ supportedFunctions.add("DEGREES"); //$NON-NLS-1$
+ supportedFunctions.add("EXP"); //$NON-NLS-1$
+ supportedFunctions.add("FLOOR"); //$NON-NLS-1$
+ supportedFunctions.add("LOG"); //$NON-NLS-1$
+ supportedFunctions.add("LOG10"); //$NON-NLS-1$
+ supportedFunctions.add("MOD"); //$NON-NLS-1$
+ supportedFunctions.add("PI"); //$NON-NLS-1$
+ supportedFunctions.add("POWER"); //$NON-NLS-1$
+ supportedFunctions.add("RADIANS"); //$NON-NLS-1$
+ supportedFunctions.add("SIGN"); //$NON-NLS-1$
+ supportedFunctions.add("SIN"); //$NON-NLS-1$
+ supportedFunctions.add("SQRT"); //$NON-NLS-1$
+ supportedFunctions.add("TAN"); //$NON-NLS-1$
+ supportedFunctions.add("ASCII"); //$NON-NLS-1$
+ supportedFunctions.add("CHAR"); //$NON-NLS-1$
+ supportedFunctions.add("CHR"); //$NON-NLS-1$
+ supportedFunctions.add("CONCAT"); //$NON-NLS-1$
+ supportedFunctions.add("||"); //$NON-NLS-1$
+ supportedFunctions.add("LCASE"); //$NON-NLS-1$
+ supportedFunctions.add("LEFT"); //$NON-NLS-1$
+ supportedFunctions.add("LENGTH"); //$NON-NLS-1$
+ supportedFunctions.add("LOWER"); //$NON-NLS-1$
+ supportedFunctions.add("LTRIM"); //$NON-NLS-1$
+ supportedFunctions.add("REPEAT"); //$NON-NLS-1$
+ //supportedFunctions.add("RAND"); //$NON-NLS-1$
+ supportedFunctions.add("RIGHT"); //$NON-NLS-1$
+ supportedFunctions.add("RTRIM"); //$NON-NLS-1$
+ supportedFunctions.add("SPACE"); //$NON-NLS-1$
+ supportedFunctions.add("SUBSTRING"); //$NON-NLS-1$
+ supportedFunctions.add("UCASE"); //$NON-NLS-1$
+ supportedFunctions.add("UPPER"); //$NON-NLS-1$
+ //supportedFunctons.add("CURDATE"); //$NON-NLS-1$
+ //supportedFunctons.add("CURTIME"); //$NON-NLS-1$
+ supportedFunctions.add("DAYNAME"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFMONTH"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFWEEK"); //$NON-NLS-1$
+ supportedFunctions.add("DAYOFYEAR"); //$NON-NLS-1$
+ supportedFunctions.add("HOUR"); //$NON-NLS-1$
+ supportedFunctions.add("MINUTE"); //$NON-NLS-1$
+ supportedFunctions.add("MONTH"); //$NON-NLS-1$
+ supportedFunctions.add("MONTHNAME"); //$NON-NLS-1$
+ //supportedFunctions.add("NOW"); //$NON-NLS-1$
+ supportedFunctions.add("QUARTER"); //$NON-NLS-1$
+ supportedFunctions.add("SECOND"); //$NON-NLS-1$
+ supportedFunctions.add("TIMESTAMPADD"); //$NON-NLS-1$
+ supportedFunctions.add("TIMESTAMPDIFF"); //$NON-NLS-1$
+ supportedFunctions.add("WEEK"); //$NON-NLS-1$
+ supportedFunctions.add("YEAR"); //$NON-NLS-1$
+ supportedFunctions.add("CAST"); //$NON-NLS-1$
+ supportedFunctions.add("CONVERT"); //$NON-NLS-1$
+ supportedFunctions.add("IFNULL"); //$NON-NLS-1$
+ supportedFunctions.add("NVL"); //$NON-NLS-1$
+ //supportedFunctions.add("FORMATTIMESTAMP"); //$NON-NLS-1$
+
+ return supportedFunctions;
+ }
+
+ @Override
+ public boolean supportsInlineViews() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsFunctionsInGroupBy() {
+ return true;
+ }
+
+ @Override
+ public int getMaxFromGroups() {
+ return 50;
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return getVersion().compareTo(FIFTEEN_0_2) >= 0;
+ }
+
+ public boolean nullPlusNonNullIsNull() {
+ return false;
+ }
+
+ public boolean booleanNullable() {
+ return false;
+ }
+
+ @Override
+ public String translateLiteralTimestamp(Timestamp timestampValue) {
+ return "CAST('" + formatDateValue(timestampValue) +"' AS DATETIME)"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralDate(Date dateValue) {
+ return "CAST('" + formatDateValue(dateValue) +"' AS DATE)"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ private boolean isFracSeconds(Function function) {
+ Expression e = function.getParameters().get(0);
+ return (e instanceof Literal && SQLConstants.NonReserved.SQL_TSI_FRAC_SECOND.equalsIgnoreCase((String)((Literal)e).getValue()));
+ }
+
+ @Override
+ public boolean supportsRowLimit() {
+ return (getVersion().getMajorVersion() == 12 && getVersion().compareTo(TWELVE_5_3) >= 0) || getVersion().compareTo(FIFTEEN_0_2) >=0; //$NON-NLS-1$
+ }
+
}
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -30,6 +30,7 @@
import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
+import org.teiid.translator.jdbc.Version;
/**
* @since 4.3
@@ -37,13 +38,13 @@
@Translator(name="teiid", description="A translator for Teiid 7.0 or later")
public class TeiidExecutionFactory extends JDBCExecutionFactory {
- public static final String SEVEN_0 = "7.0"; //$NON-NLS-1$
- public static final String SEVEN_1 = "7.1"; //$NON-NLS-1$
- public static final String SEVEN_2 = "7.2"; //$NON-NLS-1$
- public static final String SEVEN_3 = "7.3"; //$NON-NLS-1$
- public static final String SEVEN_4 = "7.4"; //$NON-NLS-1$
- public static final String SEVEN_5 = "7.5"; //$NON-NLS-1$
- public static final String SEVEN_6 = "7.6"; //$NON-NLS-1$
+ public static final Version SEVEN_0 = Version.getVersion("7.0"); //$NON-NLS-1$
+ public static final Version SEVEN_1 = Version.getVersion("7.1"); //$NON-NLS-1$
+ public static final Version SEVEN_2 = Version.getVersion("7.2"); //$NON-NLS-1$
+ public static final Version SEVEN_3 = Version.getVersion("7.3"); //$NON-NLS-1$
+ public static final Version SEVEN_4 = Version.getVersion("7.4"); //$NON-NLS-1$
+ public static final Version SEVEN_5 = Version.getVersion("7.5"); //$NON-NLS-1$
+ public static final Version SEVEN_6 = Version.getVersion("7.6"); //$NON-NLS-1$
public TeiidExecutionFactory() {
setDatabaseVersion(SEVEN_0);
@@ -144,17 +145,17 @@
supportedFunctions.add("NULLIF"); //$NON-NLS-1$
supportedFunctions.add("COALESCE"); //$NON-NLS-1$
- if (getDatabaseVersion().compareTo(SEVEN_3) >= 0) {
+ if (getVersion().compareTo(SEVEN_3) >= 0) {
supportedFunctions.add(SourceSystemFunctions.UNESCAPE);
}
- if (getDatabaseVersion().compareTo(SEVEN_4) >= 0) {
+ if (getVersion().compareTo(SEVEN_4) >= 0) {
supportedFunctions.add(SourceSystemFunctions.UUID);
supportedFunctions.add(SourceSystemFunctions.ARRAY_GET);
supportedFunctions.add(SourceSystemFunctions.ARRAY_LENGTH);
}
- if (getDatabaseVersion().compareTo(SEVEN_5) >= 0) {
+ if (getVersion().compareTo(SEVEN_5) >= 0) {
supportedFunctions.add(SourceSystemFunctions.TRIM);
}
@@ -190,7 +191,7 @@
@Override
public boolean supportsAggregatesEnhancedNumeric() {
- return getDatabaseVersion().compareTo(SEVEN_1) >= 0;
+ return getVersion().compareTo(SEVEN_1) >= 0;
}
@Override
@@ -205,42 +206,42 @@
@Override
public boolean supportsCommonTableExpressions() {
- return getDatabaseVersion().compareTo(SEVEN_2) >= 0;
+ return getVersion().compareTo(SEVEN_2) >= 0;
}
@Override
public boolean supportsAdvancedOlapOperations() {
- return getDatabaseVersion().compareTo(SEVEN_5) >= 0;
+ return getVersion().compareTo(SEVEN_5) >= 0;
}
@Override
public boolean supportsElementaryOlapOperations() {
- return getDatabaseVersion().compareTo(SEVEN_5) >= 0;
+ return getVersion().compareTo(SEVEN_5) >= 0;
}
@Override
public boolean supportsArrayAgg() {
- return getDatabaseVersion().compareTo(SEVEN_5) >= 0;
+ return getVersion().compareTo(SEVEN_5) >= 0;
}
@Override
public boolean supportsLikeRegex() {
- return getDatabaseVersion().compareTo(SEVEN_5) >= 0;
+ return getVersion().compareTo(SEVEN_5) >= 0;
}
@Override
public boolean supportsSimilarTo() {
- return getDatabaseVersion().compareTo(SEVEN_5) >= 0;
+ return getVersion().compareTo(SEVEN_5) >= 0;
}
@Override
public boolean supportsWindowDistinctAggregates() {
- return getDatabaseVersion().compareTo(SEVEN_6) >= 0;
+ return getVersion().compareTo(SEVEN_6) >= 0;
}
@Override
public boolean supportsWindowOrderByWithAggregates() {
- return getDatabaseVersion().compareTo(SEVEN_5) >= 0;
+ return getVersion().compareTo(SEVEN_5) >= 0;
}
}
Modified: branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCExecutionFactory.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -52,4 +52,15 @@
assertNotSame(cals[0], cals[1]);
}
+
+ @Test public void testVersion() {
+ JDBCExecutionFactory jef = new JDBCExecutionFactory();
+ jef.setDatabaseVersion("Some db 1.2.3 (some build)");
+ assertEquals("1.2.3", jef.getDatabaseVersion().toString());
+ assertEquals(new Version(new Integer[] {1, 2, 3}), jef.getVersion());
+
+ Version version = Version.getVersion("10.0");
+ assertTrue(version.compareTo(Version.getVersion("9.1")) > 0);
+ assertTrue(version.compareTo(Version.getVersion("10.0.1")) < 0);
+ }
}
Modified: branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/derby/TestDerbyCapabilities.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/derby/TestDerbyCapabilities.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/derby/TestDerbyCapabilities.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -31,14 +31,14 @@
@Test public void testLimitSupport() {
DerbyExecutionFactory derbyCapabilities = new DerbyExecutionFactory();
assertFalse(derbyCapabilities.supportsRowLimit());
- derbyCapabilities.setDatabaseVersion(DerbyExecutionFactory.TEN_5);
+ derbyCapabilities.setDatabaseVersion(DerbyExecutionFactory.TEN_5.toString());
assertTrue(derbyCapabilities.supportsRowLimit());
}
@Test public void testFunctionSupport() {
DerbyExecutionFactory derbyCapabilities = new DerbyExecutionFactory();
assertEquals(27, derbyCapabilities.getSupportedFunctions().size());
- derbyCapabilities.setDatabaseVersion(DerbyExecutionFactory.TEN_4);
+ derbyCapabilities.setDatabaseVersion(DerbyExecutionFactory.TEN_4.toString());
assertEquals(44, derbyCapabilities.getSupportedFunctions().size());
}
Modified: branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2014-04-16 12:56:32 UTC (rev 4629)
+++ branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2014-04-16 15:26:45 UTC (rev 4630)
@@ -970,5 +970,12 @@
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, output, TRANSLATOR);
}
+
+ @Test public void testVersionedCapabilities() throws Exception {
+ OracleExecutionFactory oef = new OracleExecutionFactory();
+ oef.setDatabaseVersion("10.0");
+ oef.start();
+ assertTrue(oef.supportsCommonTableExpressions());
+ }
}
10 years, 9 months
teiid SVN: r4629 - in branches/7.7.x/engine/src: test/java/org/teiid/query/function/source and 1 other directory.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2014-04-16 08:56:32 -0400 (Wed, 16 Apr 2014)
New Revision: 4629
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
branches/7.7.x/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
Log:
TEIID-1896 fix for nested json array xml conversion
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2014-04-16 01:51:24 UTC (rev 4628)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2014-04-16 12:56:32 UTC (rev 4629)
@@ -113,37 +113,33 @@
private static final class JsonToXmlContentHandler implements
ContentHandler {
private final XMLStreamWriter streamWriter;
- private String currentName;
- private LinkedList<Boolean> inArray = new LinkedList<Boolean>();
+ private boolean rootArray;
+ private LinkedList<String> nameStack = new LinkedList<String>();
private JsonToXmlContentHandler(String rootName,
XMLStreamWriter streamWriter) {
this.streamWriter = streamWriter;
- this.currentName = rootName;
+ this.nameStack.push(rootName);
}
@Override
public boolean startObjectEntry(String key)
throws org.json.simple.parser.ParseException, IOException {
- currentName = key;
- start();
+ this.nameStack.push(key);
return true;
}
@Override
public boolean startObject() throws org.json.simple.parser.ParseException,
IOException {
- if (inArray.peek()) {
- start();
- }
- inArray.push(false);
+ start();
return true;
}
private void start()
throws IOException {
try {
- streamWriter.writeStartElement(escapeName(currentName, true));
+ streamWriter.writeStartElement(escapeName(this.nameStack.peek(), true));
} catch (XMLStreamException e) {
throw new IOException(e);
}
@@ -157,23 +153,22 @@
} catch (XMLStreamException e) {
throw new IOException(e);
}
- inArray.push(false);
- start();
}
@Override
public boolean startArray() throws org.json.simple.parser.ParseException,
IOException {
- inArray.push(true);
+ if (this.nameStack.size() == 1) {
+ this.rootArray = true;
+ start();
+ }
return true;
}
@Override
public boolean primitive(Object value)
throws org.json.simple.parser.ParseException, IOException {
- if (inArray.peek()) {
- start();
- }
+ start();
try {
if (value != null) {
streamWriter.writeCharacters(value.toString());
@@ -184,9 +179,7 @@
} catch (XMLStreamException e) {
throw new IOException(e);
}
- if (inArray.peek()) {
- end();
- }
+ end();
return true;
}
@@ -202,24 +195,20 @@
@Override
public boolean endObjectEntry()
throws org.json.simple.parser.ParseException, IOException {
- end();
+ this.nameStack.pop();
return true;
}
@Override
public boolean endObject() throws org.json.simple.parser.ParseException,
IOException {
- inArray.pop();
- if (inArray.peek()) {
- end();
- }
+ end();
return true;
}
@Override
public void endJSON() throws org.json.simple.parser.ParseException,
IOException {
- end();
try {
streamWriter.writeEndDocument();
} catch (XMLStreamException e) {
@@ -230,7 +219,9 @@
@Override
public boolean endArray() throws org.json.simple.parser.ParseException,
IOException {
- inArray.pop();
+ if (this.nameStack.size() == 1 && rootArray) {
+ end();
+ }
return true;
}
}
Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2014-04-16 01:51:24 UTC (rev 4628)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2014-04-16 12:56:32 UTC (rev 4629)
@@ -194,7 +194,7 @@
@Test public void testJsonToXml() throws Exception {
String json = "[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
- String expected = "<?xml version=\"1.0\" ?><Array><Array>0</Array><Array><_u0031_><_u0032_><_u0033_><_u0034_><_u0034_>5</_u0034_><_u0034_><_u0036_>7</_u0036_></_u0034_></_u0034_></_u0033_></_u0032_></_u0031_></Array></Array>";
+ String expected = "<?xml version=\"1.0\" ?><Array><Array>0</Array><Array><_u0031_><_u0032_><_u0033_><_u0034_>5</_u0034_><_u0034_><_u0036_>7</_u0036_></_u0034_></_u0033_></_u0032_></_u0031_></Array></Array>";
helpTestJson(json, "Array", expected);
}
@@ -214,7 +214,7 @@
@Test public void testJsonToXml1() throws Exception {
String json = "{ \"firstName\": \"John\", \"lastName\": \"Smith\", \"age\": 25, \"address\": { \"streetAddress\": \"21 2nd Street\", \"city\": \"New York\", \"state\": \"NY\", "+
"\"postalCode\": \"10021\" }, \"phoneNumber\": [ { \"type\": \"home\", \"number\": \"212 555-1234\" }, { \"type\": \"fax\", \"number\": \"646 555-4567\" } ] }";
- String expected = "<?xml version=\"1.0\" ?><Person><firstName>John</firstName><lastName>Smith</lastName><age>25</age><address><streetAddress>21 2nd Street</streetAddress><city>New York</city><state>NY</state><postalCode>10021</postalCode></address><phoneNumber><phoneNumber><type>home</type><number>212 555-1234</number></phoneNumber><number><type>fax</type><number>646 555-4567</number></number></phoneNumber></Person>";
+ String expected = "<?xml version=\"1.0\" ?><Person><firstName>John</firstName><lastName>Smith</lastName><age>25</age><address><streetAddress>21 2nd Street</streetAddress><city>New York</city><state>NY</state><postalCode>10021</postalCode></address><phoneNumber><type>home</type><number>212 555-1234</number></phoneNumber><phoneNumber><type>fax</type><number>646 555-4567</number></phoneNumber></Person>";
helpTestJson(json, "Person", expected);
}
@@ -224,6 +224,28 @@
helpTestJson(json, "Person", expected);
}
+ @Test public void testJsonToXml3() throws Exception {
+ String json = "{ \"kids\":[{ \"firstName\" : \"George\" }, { \"firstName\" : \"Jerry\" }]}";
+ String expected = "<?xml version=\"1.0\" ?><Person><kids><firstName>George</firstName></kids><kids><firstName>Jerry</firstName></kids></Person>";
+ helpTestJson(json, "Person", expected);
+ }
+
+ @Test public void testJsonToXml4() throws Exception {
+ String json = "{ \"kids\":[{ \"firstName\" : \"George\" }, { \"firstName\" : \"Jerry\" }]}";
+ String expected = "<?xml version=\"1.0\" ?><Person><kids><firstName>George</firstName></kids><kids><firstName>Jerry</firstName></kids></Person>";
+ helpTestJson(json, "Person", expected);
+ }
+
+ /**
+ * This shows an ambiguity with the approach in that array/object children of an array cannot be distinguished
+ * @throws Exception
+ */
+ @Test public void testJsonToXml5() throws Exception {
+ String json = "[[],{\"x\": 1},[]]";
+ String expected = "<?xml version=\"1.0\" ?><Person><Person></Person><Person><x>1</x></Person><Person></Person></Person>";
+ helpTestJson(json, "Person", expected);
+ }
+
@BeforeClass static public void setUpOnce() {
TimeZone.setDefault(TimeZone.getTimeZone("GMT-6:00"));
}
10 years, 9 months
[teiid/teiid] 5748a1: [maven-release-plugin] prepare for next developmen...
by Steve Hawkins
Branch: refs/heads/8.7.x
Home: https://github.com/teiid/teiid
Commit: 5748a13ade3564cf6069f80b39c5b461cc8e657a
https://github.com/teiid/teiid/commit/5748a13ade3564cf6069f80b39c5b461cc8...
Author: Steve Hawkins <shawkins(a)redhat.com>
Date: 2014-04-16 (Wed, 16 Apr 2014)
Changed paths:
M admin/pom.xml
M adminshell/pom.xml
M api/pom.xml
M build/pom.xml
M client-jdk15/pom.xml
M client/pom.xml
M common-core/pom.xml
M connectors/connector-accumulo/pom.xml
M connectors/connector-cassandra/pom.xml
M connectors/connector-file/pom.xml
M connectors/connector-google/pom.xml
M connectors/connector-infinispan.6/pom.xml
M connectors/connector-infinispan/pom.xml
M connectors/connector-ldap/pom.xml
M connectors/connector-mongodb/pom.xml
M connectors/connector-salesforce/pom.xml
M connectors/connector-simpledb/pom.xml
M connectors/connector-solr/pom.xml
M connectors/connector-ws/pom.xml
M connectors/google-api/pom.xml
M connectors/mongodb-api/pom.xml
M connectors/pom.xml
M connectors/salesforce-api/pom.xml
M connectors/sandbox/pom.xml
M connectors/sandbox/translator-yahoo/pom.xml
M connectors/simpledb-api/pom.xml
M connectors/translator-accumulo/pom.xml
M connectors/translator-cassandra/pom.xml
M connectors/translator-excel/pom.xml
M connectors/translator-file/pom.xml
M connectors/translator-google/pom.xml
M connectors/translator-hive/pom.xml
M connectors/translator-jdbc/pom.xml
M connectors/translator-jpa/pom.xml
M connectors/translator-ldap/pom.xml
M connectors/translator-loopback/pom.xml
M connectors/translator-mongodb/pom.xml
M connectors/translator-object/pom.xml
M connectors/translator-odata/pom.xml
M connectors/translator-olap/pom.xml
M connectors/translator-salesforce/pom.xml
M connectors/translator-simpledb/pom.xml
M connectors/translator-solr/pom.xml
M connectors/translator-ws/pom.xml
M engine/pom.xml
M hibernate-dialect/pom.xml
M jboss-integration/pom.xml
M metadata/pom.xml
M odata/pom.xml
M pom.xml
M runtime/pom.xml
M test-integration/common/pom.xml
M test-integration/db/pom.xml
M test-integration/perf/pom.xml
M test-integration/pom.xml
Log Message:
-----------
[maven-release-plugin] prepare for next development iteration
10 years, 9 months