Skip to content

Commit

Permalink
MONDRIAN: More Firebird support.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 3627]
  • Loading branch information
julianhyde committed Jun 1, 2005
1 parent 8e2fb74 commit 3f1673b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 57 deletions.
31 changes: 10 additions & 21 deletions build.properties
Expand Up @@ -21,11 +21,21 @@
scp.user=jhyde@mondrian.sourceforge.net
scp.path=/home/groups/m/mo/mondrian/htdocs

# Properties for Mondrian during tests
#mondrian.rolap.aggregates.Use=true
#mondrian.rolap.aggregates.ChooseByVolume=false
#mondrian.trace.level=2

# To run the test suite, first load the FoodMart data set into the
# database of your choice. Then set the driver.classpath,
# mondrian.foodmart.jdbcURL and mondrian.jdbcDrivers properties, by
# uncommenting and modifying one of the sections below.

# FireBirdSQL
#mondrian.foodmart.jdbcURL=jdbc:firebirdsql:localhost/3050:/mondrian/foodmart.gdb
#mondrian.jdbcDrivers=org.firebirdsql.jdbc.FBDriver
#driver.classpath=/jdbc/fb/firebirdsql-full.jar

# Oracle
#oracle.home=G:/oracle/product/10.1.0/Db_1
#driver.classpath=/home/jhyde/open/mondrian/lib/ojdbc14.jar
Expand Down Expand Up @@ -54,26 +64,5 @@ scp.path=/home/groups/m/mo/mondrian/htdocs
#driver.classpath=xx

# End build.properties
xalan.lib=/home/emberson/OH/lib
junit.home=/home/emberson/OH/build/lib
catalina.home=/home/emberson/java/jakarta/jakarta-tomcat-4.1.31

# Oracle
#driver.classpath=/home/jhyde/open/mondrian/lib/ojdbc14.jar
#mondrian.jdbcDrivers=oracle.jdbc.OracleDriver
#mondrian.foodmart.jdbcURL=jdbc:oracle:thin:foodmart/foodmart@EDGEPSW01:1521:pstest


# Oracle
#mondrian.jdbcDrivers=oracle.jdbc.OracleDriver
#mondrian.foodmart.jdbcURL=jdbc:oracle:thin:foodmart/foodmart@EDGEPSW01:1521:pstest

# MySQL
mondrian.jdbcDrivers=com.mysql.jdbc.Driver
mondrian.foodmart.jdbcURL=jdbc:mysql://localhost/foodmart?user=foodmart&password=foodmart
#mondrian.rolap.aggregates.Use=true
#mondrian.rolap.aggregates.ChooseByVolume=false

#mondrian.trace.level=2


97 changes: 61 additions & 36 deletions testsrc/main/mondrian/test/loader/MondrianFoodMartLoader.java
Expand Up @@ -10,6 +10,7 @@
package mondrian.test.loader;

import mondrian.olap.MondrianResource;
import mondrian.olap.Util;
import mondrian.rolap.RolapUtil;
import mondrian.rolap.sql.SqlQuery;

Expand Down Expand Up @@ -45,20 +46,42 @@
*
* <li>Oracle 10g using ojdbc14.jar</li>
*
* <li>FirebirdSQL 1.0.2 and JayBird 1.5 (JDBC)</li>
*
* </ul>
*
* <p>Output can be to a set of files with create table, insert and create index
* statements, or directly to a JDBC connection with JDBC batches (lots faster!)</p>
* <p>Output can be to a set of files with create table, insert and create
* index statements, or directly to a JDBC connection with JDBC batches
* (lots faster!)</p>
*
* <h3>Command line examples for specific databases</h3>
*
* <p>On the command line:</p>
* <h4>MySQL</h4>
*
* <blockquote>MySQL example<code>
* <blockquote><code>
* $ mysqladmin create foodmart<br/>
* $ java -cp 'classes;testclasses' mondrian.test.loader.MondrianFoodMartLoader
* -verbose -tables -data -indexes -jdbcDrivers=com.mysql.jdbc.Driver
* -inputJdbcURL=jdbc:odbc:MondrianFoodMart -outputJdbcURL=jdbc:mysql://localhost/foodmart
* </code></blockquote>
*
* <h4>FirebirdSQL</h4>
*
* <blockquote><code>
* $ /firebird/bin/isql -u SYSDBA -p masterkey<br/>
* Use CONNECT or CREATE DATABASE to specify a database<br/>
* SQL&gt; CREATE DATABASE '/mondrian/foodmart.gdb';<br/>
* SQL&gt; QUIT;<br/>
* $ java -cp "/mondrian/lib/mondrian.jar:/mondrian/lib/log4j-1.2.9.jar:/mondrian/lib/eigenbase-xom.jar:/mondrian/lib/eigenbase-resgen.jar:/jdbc/fb/firebirdsql-full.jar"
* mondrian.test.loader.MondrianFoodMartLoader
* -verbose -tables -data -indexes
* -jdbcDrivers="org.firebirdsql.jdbc.FBDriver"
* -inputFile="/mondrian/demo/FoodMartCreateData.sql"
* -outputJdbcURL="jdbc:firebirdsql:localhost/3050:/mondrian/foodmart.gdb"
* -inputJdbcUser=SYSDBA
* -inputJdbcPassword=masterkey
* </code></blockquote>
*
* @author jhyde
* @since 23 December, 2004
* @version $Id$
Expand Down Expand Up @@ -102,7 +125,7 @@ public class MondrianFoodMartLoader {
public MondrianFoodMartLoader(String[] args) {

StringBuffer errorMessage = new StringBuffer();
StringBuffer parametersMessage = new StringBuffer();
StringBuffer parametersMessage = new StringBuffer();

for ( int i=0; i<args.length; i++ ) {
if (args[i].equals("-tables")) {
Expand Down Expand Up @@ -136,7 +159,7 @@ public MondrianFoodMartLoader(String[] args) {
} else {
errorMessage.append("unknown arg: " + args[i] + nl);
}

if (LOGGER.isInfoEnabled()) {
parametersMessage.append("\t" + args[i] + nl);
}
Expand All @@ -154,7 +177,7 @@ public MondrianFoodMartLoader(String[] args) {
usage();
throw MondrianResource.instance().newMissingArg(errorMessage.toString());
}

if (LOGGER.isInfoEnabled()) {
LOGGER.info("Parameters: " + nl + parametersMessage.toString());
}
Expand Down Expand Up @@ -239,7 +262,7 @@ private void load() throws Exception {
}

bigIntColumnType = "BIGINT";
if (sqlQuery.isOracle()) {
if (sqlQuery.isOracle() || sqlQuery.isFirebird()) {
bigIntColumnType = "DECIMAL(15,0)";
}

Expand Down Expand Up @@ -316,7 +339,7 @@ private void loadDataFromFile() throws Exception {

Pattern regex = null;
String quoteChar = null;

while ((line = bufferedReader.readLine()) != null) {
++lineNumber;
if (line.startsWith("#")) {
Expand Down Expand Up @@ -358,7 +381,7 @@ private void loadDataFromFile() throws Exception {
batchSize = 0;
prevTable = tableName;
quotedTableName = quoteId(tableName);
quotedColumnNames = columnNames.replaceAll(quoteChar,
quotedColumnNames = columnNames.replaceAll(quoteChar,
sqlQuery.getQuoteIdentifierString());
String[] splitColumnNames = columnNames.replaceAll(quoteChar, "")
.replaceAll(" ", "").split(",");
Expand Down Expand Up @@ -420,9 +443,10 @@ private void loadDataFromFile() throws Exception {
}

/**
* @param splitColumnNames the individual column names in the same order as the values
* @param columns column metadata for the table
* @param values the contents of the INSERT VALUES clause ie. "34,67.89,'GHt''ab'". These are in MySQL form.
* @param values the contents of the INSERT VALUES clause,
* for example "34,67.89,'GHt''ab'".
* These are in MySQL form.
* @return String values for the destination dialect
* @throws Exception
*/
Expand Down Expand Up @@ -514,10 +538,10 @@ private void loadDataFromJdbcInput() throws Exception {
fileOutput.close();
}
}

/**
* After data has been loaded from a file or via JDBC, create any derived data
*
*
*/
private void loadFromSQLInserts() throws Exception {
InputStream is = getClass().getResourceAsStream("insert.sql");
Expand All @@ -527,9 +551,9 @@ private void loadFromSQLInserts() throws Exception {

String line;
int lineNumber = 0;
Util.discard(lineNumber);

StringBuffer statement = new StringBuffer();
int batchSize = 0;

String fromQuoteChar = null;
String toQuoteChar = null;
Expand All @@ -538,50 +562,50 @@ private void loadFromSQLInserts() throws Exception {
} else {
toQuoteChar = "\"";
}

while ((line = bufferedReader.readLine()) != null) {
++lineNumber;

line = line.trim();
if (line.startsWith("#") || line.length() == 0) {
continue;
}

if (fromQuoteChar == null) {
if (line.indexOf('`') >=0) {
fromQuoteChar = "`";
} else if (line.indexOf('"') >=0) {
fromQuoteChar = "\"";
}
}

if (fromQuoteChar != null && fromQuoteChar != toQuoteChar) {
line = line.replaceAll(fromQuoteChar, toQuoteChar);
}

// End of statement
if (line.charAt(line.length() - 1) == ';') {
statement.append(" ")
.append(line.substring(0, line.length() - 1));
executeDDL(statement.toString());
statement = new StringBuffer();

} else {
statement.append(" ")
.append(line.substring(0, line.length()));
}
}

if (statement.length() > 0) {
executeDDL(statement.toString());
}

} finally {
if (is != null) {
is.close();
}
}

}

/**
Expand Down Expand Up @@ -908,7 +932,7 @@ private void createIndex(
LOGGER.info("Index Drop failed for " + tableName + ", " + indexName + " : but continue");
}
}

buf = new StringBuffer();
buf.append(isUnique ? "CREATE UNIQUE INDEX " : "CREATE INDEX ")
.append(quoteId(indexName)).append(" ON ")
Expand Down Expand Up @@ -995,9 +1019,9 @@ private void createTables() throws Exception {
new Column("supply_time", "SMALLINT", ""),
new Column("store_invoice", "DECIMAL(10,4)", ""),
});

// Aggregate tables

createTable("agg_pl_01_sales_fact_1997", new Column[] {
new Column("product_id", "INTEGER", "NOT NULL"),
new Column("time_id", "INTEGER", "NOT NULL"),
Expand Down Expand Up @@ -1070,7 +1094,7 @@ private void createTables() throws Exception {
new Column("unit_sales_sum", "DECIMAL(10,4)", "NOT NULL"),
new Column("fact_count", "INTEGER", "NOT NULL"),
}, false, true);

createTable("currency", new Column[] {
new Column("currency_id", "INTEGER", "NOT NULL"),
new Column("date", "DATE", "NOT NULL"),
Expand Down Expand Up @@ -1352,21 +1376,21 @@ private void createTables() throws Exception {
private void createTable(String name, Column[] columns) {
createTable(name, columns, true, false);
}

private void createTable(String name, Column[] columns, boolean loadData, boolean aggregate) {
try {

// Store this metadata if we are going to load the table
// from JDBC or a file

if (loadData) {
tableMetadataToLoad.put(name, columns);
}

if (aggregate) {
aggregateTableMetadataToLoad.put(name, columns);
}

if (!tables) {
if (data && jdbcOutput) {
if (populationQueries && !aggregate) {
Expand All @@ -1381,7 +1405,7 @@ private void createTable(String name, Column[] columns, boolean loadData, boole
}
}
return;

} else if (populationQueries && !aggregate) {
// only create the aggregate tables if we are running
// -tables -populationQueries
Expand All @@ -1397,7 +1421,7 @@ private void createTable(String name, Column[] columns, boolean loadData, boole
// Define the table.
StringBuffer buf = new StringBuffer();
buf.append("CREATE TABLE ").append(quoteId(name)).append("(");

for (int i = 0; i < columns.length; i++) {
Column column = columns[i];
if (i > 0) {
Expand All @@ -1417,7 +1441,7 @@ private void createTable(String name, Column[] columns, boolean loadData, boole
throw MondrianResource.instance().newCreateTableFailed(name, e);
}
}

private void executeDDL(String ddl) throws Exception {
LOGGER.info(ddl);

Expand Down Expand Up @@ -1638,7 +1662,8 @@ private String columnValue(String columnValue, Column column) throws Exception {
} else if (columnType.equals(booleanColumnType)) {
String trimmedValue = columnValue.trim();
if (!sqlQuery.isMySQL() &&
!sqlQuery.isOracle()) {
!sqlQuery.isOracle() &&
!sqlQuery.isFirebird()) {
if (trimmedValue.equals("1")) {
return "true";
} else if (trimmedValue.equals("0")) {
Expand Down

0 comments on commit 3f1673b

Please sign in to comment.