1 32 33 package it.businesslogic.ireport.connection; 34 import it.businesslogic.ireport.*; 35 import it.businesslogic.ireport.gui.MainFrame; 36 import it.businesslogic.ireport.util.*; 37 import java.net.URLClassLoader ; 38 import java.sql.*; 39 import java.util.HashMap ; 40 import java.util.List ; 41 import java.util.Vector ; 42 import javax.swing.*; 43 44 import mondrian.olap.Connection; 45 import mondrian.olap.DriverManager; 46 47 51 public class MondrianConnection extends it.businesslogic.ireport.IReportConnection { 52 53 public static final String CATALOG_URI = "CatalogUri"; 54 public static final String CONNECTION_NAME = "ConnectionName"; 55 56 private String name; 57 58 59 60 private java.util.HashMap map = null; 61 private String persistenceUnit; 62 63 private mondrian.olap.Connection mondrianConnection = null; 64 65 private int usedby = 0; 66 67 68 69 70 public MondrianConnection() { 71 map = new java.util.HashMap (); 72 } 73 74 78 public java.sql.Connection getConnection() { 79 return null; 80 } 81 82 public boolean isJDBCConnection() { 83 return false; 84 } 85 86 public boolean isJRDataSource() { 87 return false; 88 } 89 90 93 public java.util.HashMap getProperties() 94 { 95 return map; 96 } 97 98 public void loadProperties(java.util.HashMap map) 99 { 100 this.map = map; 101 } 102 103 public String getDescription(){ return "Mondrian OLAP connection"; } 104 105 106 110 public net.sf.jasperreports.engine.JRDataSource getJRDataSource() 111 { 112 return null; 113 } 114 115 116 public void closeMondrianConnection() 117 { 118 try { 119 if (getMondrianConnection() != null) 120 { 121 usedby--; 122 if (usedby == 0) 123 { 124 mondrianConnection.close(); 125 mondrianConnection = null; 126 } 127 } 128 } catch (Exception ex) 129 { 130 } 131 } 132 133 public mondrian.olap.Connection getMondrianConnection() throws Exception { 134 135 if (mondrianConnection == null) 136 { 137 JDBCConnection con = getJDBCConnection(); 138 139 mondrianConnection = 140 DriverManager.getConnection( 141 "Provider=mondrian;" + 142 "JdbcDrivers=" + escapeProperty( con.getJDBCDriver() ) + ";" + 143 "Jdbc=" + escapeProperty( con.getUrl() ) + ";" + 144 "JdbcUser=" + escapeProperty( con.getUsername() ) + ";" + 145 "JdbcPassword=" + escapeProperty( con.getPassword() ) + ";" + 146 "Catalog=" + escapeProperty( getCatalogUri() ) + ";", 147 null, false); 148 } 149 usedby++; 150 return mondrianConnection; 151 } 152 153 public void setMondrianConnection(mondrian.olap.Connection mondrianConnection) { 154 this.mondrianConnection = mondrianConnection; 155 } 156 157 public String getCatalogUri() { 158 return (String )getProperties().get( CATALOG_URI ); 159 } 160 161 public void setCatalogUri(String catalogUri) { 162 getProperties().put( CATALOG_URI, catalogUri); 163 } 164 165 public String getConnectionName() { 166 return (String )getProperties().get( CONNECTION_NAME ); 167 } 168 169 public void setConnectionName(String connectionName) { 170 getProperties().put( CONNECTION_NAME, connectionName); 171 } 172 173 private JDBCConnection getJDBCConnection() 174 { 175 String name = getConnectionName(); 176 Vector conns = MainFrame.getMainInstance().getConnections(); 177 for (int i=0; i<conns.size(); ++i) 178 { 179 IReportConnection con = (IReportConnection)conns.elementAt(i); 180 if (con instanceof JDBCConnection && 181 con.getName().equals(name)) 182 { 183 return (JDBCConnection)con; 184 } 185 } 186 187 return null; 188 } 189 190 public String escapeProperty( String s) 191 { 192 if (s == null) s = ""; 193 s = Misc.string_replace("\"\"","\"",s); 194 195 return s; 196 } 197 } 198 | Popular Tags |