1 package com.tonbeller.jpivot.mondrian; 2 3 import com.tonbeller.jpivot.olap.model.OlapException; 4 import com.tonbeller.tbutils.res.Resources; 5 6 9 public class TestConnection { 10 static Resources res = Resources.instance(); 11 12 public static String getConnectString() { 13 String catalog = res.getString("catalog.uri"); 14 if (catalog == null) 15 throw new RuntimeException ( 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 getConnectString(String catUri) { 21 String jdbcUrl = res.getString("jdbc.url"); 22 String jdbcUser = res.getString("jdbc.user"); 23 String jdbcPassword = res.getString("jdbc.password"); 24 25 StringBuffer con = new StringBuffer (); 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 getJdbcDriver() { 40 return res.getString("jdbc.driver"); 41 } 42 43 public static void initModel(MondrianModel model) throws OlapException { 44 String connectString = getConnectString(); 45 model.setConnectString(connectString); 46 String jdbcDriver = getJdbcDriver(); 47 model.setJdbcDriver(jdbcDriver); 48 model.initialize(); 49 } 50 } | Popular Tags |