List of usage examples for org.jfree.data.category DefaultCategoryDataset getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.jfree.data.category.DefaultCategoryDatasetTest.java
/** * Confirm that cloning works./*from w w w. ja va2 s. c om*/ */ public void testCloning() throws CloneNotSupportedException { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); DefaultCategoryDataset d2 = (DefaultCategoryDataset) d1.clone(); assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); // try a dataset with some content... d1.addValue(1.0, "R1", "C1"); d1.addValue(2.0, "R1", "C2"); d2 = (DefaultCategoryDataset) d1.clone(); assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); // check that the clone doesn't share the same underlying arrays. d1.addValue(3.0, "R1", "C1"); assertFalse(d1.equals(d2)); d2.addValue(3.0, "R1", "C1"); assertTrue(d1.equals(d2)); }
From source file:org.jfree.data.category.junit.DefaultCategoryDatasetTest.java
/** * Confirm that cloning works.//from w w w. j a va 2 s . com */ public void testCloning() { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); DefaultCategoryDataset d2 = null; try { d2 = (DefaultCategoryDataset) d1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); // try a dataset with some content... d1.addValue(1.0, "R1", "C1"); d1.addValue(2.0, "R1", "C2"); try { d2 = (DefaultCategoryDataset) d1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); // check that the clone doesn't share the same underlying arrays. d1.addValue(3.0, "R1", "C1"); assertFalse(d1.equals(d2)); d2.addValue(3.0, "R1", "C1"); assertTrue(d1.equals(d2)); }
From source file:com.smhdemo.common.report.generate.factory.ChartFactory.java
/** * ?/* w w w. j a v a 2 s . c o m*/ * * @param reportDataSet ?? * @param sql SQL? * @return DefaultCategoryDataset * @throws BaseException */ @SuppressWarnings("rawtypes") private DefaultCategoryDataset buildDataset(Chart report, Map<String, String> pageParams) throws BaseException { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Connection con = null; DataSourceServiceable service = null; int colCount; try { Base dataSet = report.getBaseDS(); String executableSQL = report.getChartSql(); executableSQL = replaceParam(pageParams, report.getParameters(), executableSQL, true); if (dataSet == null) { con = dataSource.getConnection(); } else { DataSourceFactoryable factory = (DataSourceFactoryable) initDataSourceFactory .getBean(dataSet.getClass()); service = factory.createService(dataSet); con = service.openConnection(); } Statement st = con.createStatement(); ResultSet rs = st.executeQuery(executableSQL); colCount = rs.getMetaData().getColumnCount(); if (colCount == 2) { while (rs.next()) { try { try { dataset.addValue(rs.getDouble(1), "", (Comparable) rs.getObject(2)); } catch (Exception e) { dataset.addValue(rs.getDouble(2), "", (Comparable) rs.getObject(1)); } } catch (Exception e) { logger.error("SQL?", e); throw new BaseException("SQL?", "SQL?"); } } } else if (colCount == 3) { while (rs.next()) { try { try { dataset.addValue(rs.getDouble(3), (Comparable) rs.getObject(1), (Comparable) rs.getObject(2)); } catch (Exception e) { try { dataset.addValue(rs.getDouble(2), (Comparable) rs.getObject(1), (Comparable) rs.getObject(3)); } catch (Exception ex) { dataset.addValue(rs.getDouble(1), (Comparable) rs.getObject(2), (Comparable) rs.getObject(3)); } } } catch (Exception e) { logger.error("SQL?", e); throw new BaseException("SQL?", "SQL?"); } } } else { logger.error("SQL??12"); throw new BaseException("?12", "?12"); } st.close(); rs.close(); } catch (Exception e) { throw new BaseException(e.toString(), e.toString()); } finally { if (service != null) { service.closeConnection(); } if (con != null) { try { con.close(); } catch (SQLException e) { } con = null; } } return dataset; }
From source file:com.ewcms.plugin.report.generate.factory.ChartFactory.java
/** * ?// w w w . java 2 s. c om * * @param reportDataSet ?? * @param sql SQL? * @return DefaultCategoryDataset * @throws BaseException */ @SuppressWarnings("rawtypes") private DefaultCategoryDataset buildDataset(ChartReport report, Map<String, String> pageParams) throws BaseException { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Connection con = null; EwcmsDataSourceServiceable service = null; int colCount; try { BaseDS dataSet = report.getBaseDS(); String executableSQL = report.getChartSql(); executableSQL = replaceParam(pageParams, report.getParameters(), executableSQL, true); if (dataSet == null) { con = dataSource.getConnection(); } else { DataSourceFactoryable factory = (DataSourceFactoryable) getAlqcDataSourceFactory() .getBean(dataSet.getClass()); service = factory.createService(dataSet); con = service.openConnection(); } Statement st = con.createStatement(); ResultSet rs = st.executeQuery(executableSQL); colCount = rs.getMetaData().getColumnCount(); if (colCount == 2) { while (rs.next()) { try { try { dataset.addValue(rs.getDouble(1), "", (Comparable) rs.getObject(2)); } catch (Exception e) { dataset.addValue(rs.getDouble(2), "", (Comparable) rs.getObject(1)); } // if (rs.getMetaData().getColumnType(1) == Types.NUMERIC){ // dataset.addValue(rs.getDouble(1), "", (Comparable) rs.getObject(2)); // }else if (rs.getMetaData().getColumnType(2) == Types.NUMERIC) { // dataset.addValue(rs.getDouble(2), "", (Comparable) rs.getObject(1)); // } } catch (Exception e) { logger.error("SQL?", e); throw new BaseException("SQL?", "SQL?"); } } } else if (colCount == 3) { while (rs.next()) { try { // log.info(rs.getMetaData().getColumnType(1)); // log.info(rs.getMetaData().getColumnType(2)); // log.info(rs.getMetaData().getColumnType(3)); // if (rs.getMetaData().getColumnType(1) == Types.NUMERIC){ // dataset.addValue(rs.getDouble(1), (Comparable) rs.getObject(2), (Comparable) rs.getObject(3)); // }else if (rs.getMetaData().getColumnType(2) == Types.NUMERIC){ // dataset.addValue(rs.getDouble(2), (Comparable) rs.getObject(1), (Comparable) rs.getObject(3)); // }else if (rs.getMetaData().getColumnType(3) == Types.NUMERIC){ // dataset.addValue(rs.getDouble(3), (Comparable) rs.getObject(1), (Comparable) rs.getObject(2)); // } try { dataset.addValue(rs.getDouble(3), (Comparable) rs.getObject(1), (Comparable) rs.getObject(2)); } catch (Exception e) { try { dataset.addValue(rs.getDouble(2), (Comparable) rs.getObject(1), (Comparable) rs.getObject(3)); } catch (Exception ex) { dataset.addValue(rs.getDouble(1), (Comparable) rs.getObject(2), (Comparable) rs.getObject(3)); } } } catch (Exception e) { logger.error("SQL?", e); throw new BaseException("SQL?", "SQL?"); } } } else { logger.error("SQL??12"); throw new BaseException("?12", "?12"); } st.close(); rs.close(); } catch (SQLException e) { throw new BaseException(e.toString(), e.toString()); } catch (ConvertException e) { throw new BaseException(e.toString(), e.toString()); } catch (ClassNotFoundException e) { throw new BaseException(e.toString(), e.toString()); } finally { if (service != null) { service.closeConnection(); } if (con != null) { try { con.close(); } catch (SQLException e) { } con = null; } } return dataset; }