001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2008-2009 Jaspersoft
008// Copyright (C) 2009-2013 Pentaho
009// All Rights Reserved.
010*/
011package mondrian.spi.impl;
012
013import mondrian.rolap.SqlStatement;
014
015import java.sql.Connection;
016import java.sql.ResultSetMetaData;
017import java.sql.SQLException;
018import java.sql.Types;
019
020/**
021 * Implementation of {@link mondrian.spi.Dialect} for the Netezza database.
022 *
023 * @author swood
024 * @since April 17, 2009
025 */
026public class NetezzaDialect extends PostgreSqlDialect {
027
028    public static final JdbcDialectFactory FACTORY =
029        new JdbcDialectFactory(
030            NetezzaDialect.class,
031            // Netezza behaves the same as PostGres but doesn't use the
032            // postgres driver, so we setup the factory to NETEZZA.
033            DatabaseProduct.NETEZZA)
034        {
035            protected boolean acceptsConnection(Connection connection) {
036                return isDatabase(DatabaseProduct.NETEZZA, connection);
037            }
038        };
039
040    /**
041     * Creates a NetezzaDialect.
042     *
043     * @param connection Connection
044     */
045    public NetezzaDialect(Connection connection) throws SQLException {
046        super(connection);
047    }
048
049    @Override
050    public DatabaseProduct getDatabaseProduct() {
051        return DatabaseProduct.NETEZZA;
052    }
053
054    @Override
055    public boolean allowsRegularExpressionInWhereClause() {
056        return false;
057    }
058
059    @Override
060    public String generateRegularExpression(String source, String javaRegex) {
061        throw new UnsupportedOperationException();
062    }
063
064    @Override
065    public SqlStatement.Type getType(
066        ResultSetMetaData metaData, int columnIndex)
067        throws SQLException
068    {
069        final int precision = metaData.getPrecision(columnIndex + 1);
070        final int scale = metaData.getScale(columnIndex + 1);
071        final int columnType = metaData.getColumnType(columnIndex + 1);
072
073        if (columnType == Types.NUMERIC || columnType == Types.DECIMAL
074            && (scale == 0 && precision == 38))
075        {
076            // Netezza marks longs as scale 0 and precision 38.
077            // An int would overflow.
078            logTypeInfo(metaData, columnIndex, SqlStatement.Type.DOUBLE);
079            return SqlStatement.Type.DOUBLE;
080        }
081        return super.getType(metaData, columnIndex);
082    }
083}
084
085// End NetezzaDialect.java