KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > mondrian > TestConnection


1 package com.tonbeller.jpivot.mondrian;
2
3 import com.tonbeller.jpivot.olap.model.OlapException;
4 import com.tonbeller.tbutils.res.Resources;
5
6 /**
7  * provide settings for test environment
8  */

9 public class TestConnection {
10   static Resources res = Resources.instance();
11
12   public static String JavaDoc getConnectString() {
13     String JavaDoc catalog = res.getString("catalog.uri");
14     if (catalog == null)
15       throw new RuntimeException JavaDoc(
16           "missing system property \"catalog.uri\", e.g. -Dcatalog.uri=file:///c:/dev/mondrian/demo/FoodMart.xml");
17     return getConnectString(catalog);
18   }
19
20   public static String JavaDoc getConnectString(String JavaDoc catUri) {
21     String JavaDoc jdbcUrl = res.getString("jdbc.url");
22     String JavaDoc jdbcUser = res.getString("jdbc.user");
23     String JavaDoc jdbcPassword = res.getString("jdbc.password");
24
25     StringBuffer JavaDoc con = new StringBuffer JavaDoc();
26     con.append("provider=Mondrian;");
27     con.append("Jdbc=");
28     con.append(jdbcUrl);
29     con.append(";Catalog=");
30     con.append(catUri);
31     if (jdbcUser.length() > 0)
32       con.append(";JdbcUser=").append(jdbcUser);
33     if (jdbcPassword.length() > 0)
34       con.append(";JdbcPassword=").append(jdbcPassword);
35
36     return con.toString();
37   }
38
39   public static String JavaDoc getJdbcDriver() {
40     return res.getString("jdbc.driver");
41   }
42
43   public static void initModel(MondrianModel model) throws OlapException {
44     String JavaDoc connectString = getConnectString();
45     model.setConnectString(connectString);
46     String JavaDoc jdbcDriver = getJdbcDriver();
47     model.setJdbcDriver(jdbcDriver);
48     model.initialize();
49   }
50 }
Popular Tags