1 package com.calipso.reportgenerator.services; 2 3 import com.calipso.reportgenerator.reportcalculator.IDataSource; 4 import com.calipso.reportgenerator.common.InfoException; 5 import com.calipso.reportgenerator.common.*; 6 import com.calipso.reportgenerator.reportcalculator.*; 7 import com.calipso.reportgenerator.reportdefinitions.types.ReportDataType; 8 import com.calipso.reportgenerator.common.LocalKeyEncrypter; 9 import com.calipso.common.DateEx; 10 11 import java.sql.*; 12 import java.util.*; 13 import java.util.Date ; 14 15 18 public class DefaultSQLDataSourceResolver extends SQLDataSourceResolver{ 19 20 21 public IDataSource execute(Matrix matrix) throws InfoException { 22 return getDataSource(getSqlText(), matrix); 23 } 24 25 29 public IDataSource getDataSource(String SQLText, Matrix matrix) throws InfoException { 30 Statement stmt = null; 32 int colNum; 33 try { 34 ReportManagerLogger.debug(SQLText); 35 stmt = getConnection().createStatement(); 36 ResultSet rs = null; 37 System.out.println(LanguageTraslator.traslate("499")+(new Date ()).toString()); 38 stmt.setFetchSize(getReportGeneratorConfiguration().getFetchSize()); 39 rs = stmt.executeQuery(SQLText); 40 System.out.println(LanguageTraslator.traslate("500")+(new Date ()).toString()); 41 int dimCount = getReportSpec().getDimensionsByIndex().size(); 43 colNum = dimCount + getReportSpec().getMetricsByIndex().size(); 44 Vector columnsNames = new Vector(); 45 columnsNames.addAll(getReportSpec().getColumnTypesByName().keySet()); 46 48 54 System.out.println(LanguageTraslator.traslate("501")+(new Date ()).toString()); 55 while (rs.next()) { 56 Object [] collection = new Object [colNum]; 57 for (int i = 0; i < (colNum); i++) { 58 if(i < dimCount){ 59 ReportDimensionSpec dimension = getReportSpec().getDimensionFromIndex(i); 61 if(dimension.getCalculated()){ 62 collection[i] = dimension.getValue(collection, this.dataSource.getReportDataSourceSpec()); 63 }else{ 64 collection[i] = this.dataSource.getValueForDimension(rs.getObject(dimension.getExternalData()), dimension, collection, i); 65 } 66 }else{ 67 ReportMetricSpec metric = getReportSpec().getMetricFromIndex(i - dimCount); 69 if(metric.getCalculated()){ 70 collection[i] = metric.getValue(collection); 71 }else{ 72 collection[i] = this.dataSource.getValueForMetric(rs.getObject(metric.getExternalData()), metric, collection, i); 73 } 74 } 75 76 122 } 123 124 matrix.add(collection); 125 } 126 } catch (Exception e) { 127 throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("95"), e); 128 } 129 System.out.println(LanguageTraslator.traslate("502")+(new Date ()).toString()); 130 return matrix; 131 } 132 133 138 139 154 155 156 164 165 166 171 protected Connection getConnection() throws InfoException { 172 Connection con = null; 173 174 try { 175 Class.forName(getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationClassName")); 176 con = DriverManager.getConnection(getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationLocalUrl"), getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationUser"), getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationPassword")); 177 } catch (Exception e) { 178 try { 179 String user = LocalKeyEncrypter.decrypt(getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationUser")); 180 String pass =LocalKeyEncrypter.decrypt(getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationPassword")); 181 Class.forName(getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationClassName")); 182 con = DriverManager.getConnection(getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationLocalUrl"), user, pass); 183 } catch (ClassNotFoundException e1) { 184 throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("95"), e1); 185 } catch (SQLException e2) { 186 throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("95"), e2); 187 } catch (Exception e3) { 188 throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("95")); 189 } 190 } 191 return con; 201 } 202 203 } 204 | Popular Tags |