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-2013 Pentaho 008// All Rights Reserved. 009*/ 010package mondrian.spi.impl; 011 012import mondrian.olap.Util; 013 014import java.sql.Connection; 015import java.sql.SQLException; 016 017/** 018 * Implementation of {@link mondrian.spi.Dialect} for the Infobright database. 019 * 020 * @author jhyde 021 * @since Nov 23, 2008 022 */ 023public class InfobrightDialect extends MySqlDialect { 024 025 public static final JdbcDialectFactory FACTORY = 026 new JdbcDialectFactory( 027 InfobrightDialect.class, 028 // While we're choosing dialects, this still looks like a MySQL 029 // connection. 030 DatabaseProduct.MYSQL) 031 { 032 protected boolean acceptsConnection(Connection connection) { 033 try { 034 return super.acceptsConnection(connection) 035 && isInfobright(connection.getMetaData()); 036 } catch (SQLException e) { 037 throw Util.newError( 038 e, "Error while instantiating dialect"); 039 } 040 } 041 }; 042 043 /** 044 * Creates an InfobrightDialect. 045 * 046 * @param connection Connection 047 */ 048 public InfobrightDialect(Connection connection) throws SQLException { 049 super(connection); 050 } 051 052 public DatabaseProduct getDatabaseProduct() { 053 return DatabaseProduct.INFOBRIGHT; 054 } 055 056 public boolean allowsCompoundCountDistinct() { 057 return false; 058 } 059 060 @Override 061 public String generateOrderItem( 062 String expr, 063 boolean nullable, 064 boolean ascending, 065 boolean collateNullsLast) 066 { 067 // Like MySQL, Infobright collates NULL values as negative-infinity 068 // (first in ASC, last in DESC). But we can't generate ISNULL to 069 // correct the NULL ordering, as we do for MySQL, because Infobright 070 // does not support this function. 071 if (ascending) { 072 return expr + " ASC"; 073 } else { 074 return expr + " DESC"; 075 } 076 } 077 078 public boolean supportsGroupByExpressions() { 079 return false; 080 } 081 082 public boolean requiresGroupByAlias() { 083 return true; 084 } 085 086 public boolean allowsOrderByAlias() { 087 return false; 088 } 089 090 public boolean requiresOrderByAlias() { 091 // Actually, Infobright doesn't ALLOW aliases to be used in the ORDER BY 092 // clause, let alone REQUIRE them. Infobright doesn't allow expressions 093 // in the ORDER BY clause, so returning true gives the right effect. 094 return true; 095 } 096 097 public boolean supportsMultiValueInExpr() { 098 // Infobright supports multi-value IN by falling through to MySQL, 099 // which is very slow (see for example 100 // PredicateFilterTest.testFilterAtSameLevel) so we pretend that it 101 // does not. 102 return false; 103 } 104} 105 106// End InfobrightDialect.java