Source Code Cross Referenced for DefaultSQLDataSourceResolver.java in  » Report » jmagallanes-1.0 » com » calipso » reportgenerator » services » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » jmagallanes 1.0 » com.calipso.reportgenerator.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.calipso.reportgenerator.services;
002:
003:        import com.calipso.reportgenerator.reportcalculator.IDataSource;
004:        import com.calipso.reportgenerator.common.InfoException;
005:        import com.calipso.reportgenerator.common.*;
006:        import com.calipso.reportgenerator.reportcalculator.*;
007:        import com.calipso.reportgenerator.reportdefinitions.types.ReportDataType;
008:        import com.calipso.reportgenerator.common.LocalKeyEncrypter;
009:        import com.calipso.common.DateEx;
010:
011:        import java.sql.*;
012:        import java.util.*;
013:        import java.util.Date;
014:
015:        /**
016:         * Devuelve un ejecutor de SQL por defecto
017:         */
018:        public class DefaultSQLDataSourceResolver extends SQLDataSourceResolver {
019:
020:            public IDataSource execute(Matrix matrix) throws InfoException {
021:                return getDataSource(getSqlText(), matrix);
022:            }
023:
024:            /**
025:             * Ejecuta la query, construye el datasource y lo devuelve
026:             * @throws InfoException
027:             */
028:            public IDataSource getDataSource(String SQLText, Matrix matrix)
029:                    throws InfoException {
030:                //Matrix dataSource = null;
031:                Statement stmt = null;
032:                int colNum;
033:                try {
034:                    ReportManagerLogger.debug(SQLText);
035:                    stmt = getConnection().createStatement();
036:                    ResultSet rs = null;
037:                    System.out.println(LanguageTraslator.traslate("499")
038:                            + (new Date()).toString());
039:                    stmt.setFetchSize(getReportGeneratorConfiguration()
040:                            .getFetchSize());
041:                    rs = stmt.executeQuery(SQLText);
042:                    System.out.println(LanguageTraslator.traslate("500")
043:                            + (new Date()).toString());
044:                    //colNum = getReportSpec().getNotCalculatedDimensions().size()+getReportSpec().getNotCalculatedMetrics().size();//rs.getMetaData().getColumnCount();
045:                    int dimCount = getReportSpec().getDimensionsByIndex()
046:                            .size();
047:                    colNum = dimCount
048:                            + getReportSpec().getMetricsByIndex().size();
049:                    Vector columnsNames = new Vector();
050:                    columnsNames.addAll(getReportSpec().getColumnTypesByName()
051:                            .keySet());
052:                    //dataSource = (Matrix)DataSourceBuilder.buildDataSource(columnsNames, getReportGeneratorConfiguration(), getReportSpec());
053:                    /*************nueva parte**********/
054:                    /*if(getReportGeneratorConfiguration().isDatawareHouseEnabled()){
055:                      createCachedTable(getReportSpec(), dataSource);
056:                    }else{
057:                      Object[] collection = new Object[colNum];
058:                    }
059:                    /***********************************/
060:                    System.out.println(LanguageTraslator.traslate("501")
061:                            + (new Date()).toString());
062:                    while (rs.next()) {
063:                        Object[] collection = new Object[colNum];
064:                        for (int i = 0; i < (colNum); i++) {
065:                            if (i < dimCount) {
066:                                //Es dimension
067:                                ReportDimensionSpec dimension = getReportSpec()
068:                                        .getDimensionFromIndex(i);
069:                                if (dimension.getCalculated()) {
070:                                    collection[i] = dimension.getValue(
071:                                            collection, this .dataSource
072:                                                    .getReportDataSourceSpec());
073:                                } else {
074:                                    collection[i] = this .dataSource
075:                                            .getValueForDimension(
076:                                                    rs.getObject(dimension
077:                                                            .getExternalData()),
078:                                                    dimension, collection, i);
079:                                }
080:                            } else {
081:                                //Es metrica
082:                                ReportMetricSpec metric = getReportSpec()
083:                                        .getMetricFromIndex(i - dimCount);
084:                                if (metric.getCalculated()) {
085:                                    collection[i] = metric.getValue(collection);
086:                                } else {
087:                                    collection[i] = this .dataSource
088:                                            .getValueForMetric(
089:                                                    rs.getObject(metric
090:                                                            .getExternalData()),
091:                                                    metric, collection, i);
092:                                }
093:                            }
094:
095:                            /*
096:                            try{
097:                              type = getColumnType(i);
098:                              try {
099:                                defaultValue = rs.getObject(getColumnExternalData(i));// getString(i).trim();
100:                              }catch(Exception e){
101:                                try{
102:                                  defaultValue = rs.getObject(getColumnName(i)); // getString(i).trim();
103:                                }catch(Exception e1){
104:                                  throw new InfoException("Columna no encontrada", e1);
105:                                }
106:                              }
107:                              try{
108:                                switch(type){
109:                                  case ReportDataType.FLOAT_TYPE:
110:                                    SharedFloat sharedFloat = SharedFloat.newFrom(new Float(defaultValue.toString().trim()));
111:                                    collection.add(sharedFloat);
112:                                    break;
113:                                  case ReportDataType.INTEGER_TYPE:
114:                                    SharedInteger sharedInteger = SharedInteger.newFrom(new Integer(defaultValue.toString().trim()));
115:                                    collection.add(sharedInteger);
116:                                    break;
117:                                  case ReportDataType.STRING_TYPE:
118:                                    collection.add(SharedString.newFrom(defaultValue.toString().trim()));
119:                                    break;
120:                                  case ReportDataType.DATETIME_TYPE:
121:                                  case ReportDataType.DATE_TYPE:
122:                                    DateEx dateEx;
123:                                    if(defaultValue instanceof Date){
124:                                      dateEx = new DateEx((Date)defaultValue);
125:                                    } else {
126:                                      dateEx = new DateEx(defaultValue, getReportDataSourceSpec().getPattern(getReportSpec().getDimensionFromIndex(i).getDataType().getType()));
127:                                    }
128:                                    SharedDate sharedDate = SharedDate.newFrom(dateEx);
129:                                    collection.add(sharedDate);
130:                                    break;
131:                                  default:
132:                                    collection.add(SharedString.newFrom(defaultValue.toString().trim()));
133:                                    break;
134:                                }
135:                              }catch(Exception e){
136:                                collection.add(SharedString.newFrom(defaultValue.toString().trim()));
137:                              }
138:                            }catch(Exception e){
139:                              collection.add(SharedString.newFrom(""));
140:                            }*/
141:                        }
142:                        /****** New ******/
143:                        matrix.add(collection);
144:                    }
145:                } catch (Exception e) {
146:                    throw new InfoException(
147:                            com.calipso.reportgenerator.common.LanguageTraslator
148:                                    .traslate("95"), e);
149:                }
150:                System.out.println(LanguageTraslator.traslate("502")
151:                        + (new Date()).toString());
152:                return matrix;
153:            }
154:
155:            /*private void createCachedTable(ReportSpec reportSpec, IDataSource dataSource) throws InfoException {
156:              //if(dataSource instanceof DatawarehouseMatrix){
157:                ((DatawarehouseMatrix)dataSource).createCachedTable(reportSpec);
158:              //}
159:            } */
160:
161:            /*private String getColumnExternalData(int i) {
162:              if (getReportSpec().getNotCalculatedDimensions().size() > i){
163:                return ((ReportDimensionSpec)getReportSpec().getNotCalculatedDimensions().toArray()[i]).getExternalData();
164:              } else{
165:                return ((ReportMetricSpec)getReportSpec().getNotCalculatedMetrics().toArray()[i-(getReportSpec().getNotCalculatedDimensions().size())]).getExternalData();
166:              }
167:            }
168:
169:            private String getColumnName(int i) {
170:              if (getReportSpec().getNotCalculatedDimensions().size() > i){
171:                return ((ReportDimensionSpec)getReportSpec().getNotCalculatedDimensions().toArray()[i]).getName();
172:              } else{
173:                return ((ReportMetricSpec)getReportSpec().getNotCalculatedMetrics().toArray()[i-(getReportSpec().getNotCalculatedDimensions().size())]).getName();
174:              }
175:            }*/
176:
177:            /*private int getColumnType(int i) {
178:              return getColumnTypes()[i];
179:              if (getReportSpec().getNotCalculatedDimensions().size() > i){
180:                return ((ReportDimensionSpec)getReportSpec().getNotCalculatedDimensions().toArray()[i]).getDataType().getType();
181:              } else{
182:                return ReportDataType.FLOAT_TYPE;
183:              }
184:            }*/
185:
186:            /**
187:             * Retorna una connection de base de dato dependiendo del contexto donde se ejecuta. Local o distribuido.
188:             * @return
189:             * @throws InfoException
190:             */
191:            protected Connection getConnection() throws InfoException {
192:                Connection con = null;
193:                /*    if(!getReportGeneratorConfiguration().getIsDistributed()) {*/
194:                try {
195:                    Class.forName(getDataSourceDefinitionConnectionString()
196:                            .getValue("DatabaseConfigurationClassName"));
197:                    con = DriverManager.getConnection(
198:                            getDataSourceDefinitionConnectionString().getValue(
199:                                    "DatabaseConfigurationLocalUrl"),
200:                            getDataSourceDefinitionConnectionString().getValue(
201:                                    "DatabaseConfigurationUser"),
202:                            getDataSourceDefinitionConnectionString().getValue(
203:                                    "DatabaseConfigurationPassword"));
204:                } catch (Exception e) {
205:                    try {
206:                        String user = LocalKeyEncrypter
207:                                .decrypt(getDataSourceDefinitionConnectionString()
208:                                        .getValue("DatabaseConfigurationUser"));
209:                        String pass = LocalKeyEncrypter
210:                                .decrypt(getDataSourceDefinitionConnectionString()
211:                                        .getValue(
212:                                                "DatabaseConfigurationPassword"));
213:                        Class.forName(getDataSourceDefinitionConnectionString()
214:                                .getValue("DatabaseConfigurationClassName"));
215:                        con = DriverManager
216:                                .getConnection(
217:                                        getDataSourceDefinitionConnectionString()
218:                                                .getValue(
219:                                                        "DatabaseConfigurationLocalUrl"),
220:                                        user, pass);
221:                    } catch (ClassNotFoundException e1) {
222:                        throw new InfoException(
223:                                com.calipso.reportgenerator.common.LanguageTraslator
224:                                        .traslate("95"), e1);
225:                    } catch (SQLException e2) {
226:                        throw new InfoException(
227:                                com.calipso.reportgenerator.common.LanguageTraslator
228:                                        .traslate("95"), e2);
229:                    } catch (Exception e3) {
230:                        throw new InfoException(
231:                                com.calipso.reportgenerator.common.LanguageTraslator
232:                                        .traslate("95"));
233:                    }
234:                }
235:                /*    } else {
236:                 try {
237:                 Context jndiCntx = new InitialContext();
238:                 javax.sql.DataSource ds = (javax.sql.DataSource)jndiCntx.lookup(getDataSourceDefinitionConnectionString().getValue("DatabaseConfigurationDistributedUrl"));
239:                 con = ds.getConnection();
240:                 } catch(Exception e) {
241:                 throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("362"), e);
242:                 }
243:                 }
244:                 */return con;
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.