Hitachi Vantara Pentaho Community Forums
Results 1 to 6 of 6

Thread: Using TableModels

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Posts
    1

    Question Using TableModels

    Hello,
    let me try to describe my problem:
    I'm designing my reports using the Report Designer, in which i use a jdbc-datasource to select my data. Then i need to integrate this report into my java-application, using jfreereport. In my application, i can't directly connect to the database, so i can't use a jdbc-datasource. I need to use my report with a tablemodel, into which i have previously selected my data. So, what do i have to do in order to use my report.xml with a tablemodel instead of the jdbc-datasource i used to design the report? Or is it even possible to use a tablemodel during the design process in the report designer (via custom datasource perhaps)? I've tried looking for some kind of documentation on this issue but couldn't find anything helpful. So, i would really appreciate someone pointing me in the right direction.
    Thanks alot.
    Sacha

  2. #2

    Default

    Hello,

    Isn't such code snipplet what you are looking for?

    PHP Code:
    final JFreeReport report parseReport(); // do what you have to do to parse report definition
        
    report.setDataFactory(new TableDataFactory("default"myjtable.getModel())); 
    Mimil,
    May the Moo force be with you,
    Said Mimil

    A student of JFree & Pentaho Academies,
    Cedric Pronzato

  3. #3
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    You can use the "org.jfree.report.modules.misc.datafactory.StaticDataFactory" or "org.jfree.report.modules.misc.datafactory.NamedStaticDataFactory" for that task.
    From inside the report-designer, these data-sources are available under the rather strange name "Custom DataSet".

    That datasource uses reflection to instantiate a class or call a method on a class. The syntax for the queries is:

    Code:
    <full-qualified-class-name><constructor-parameters>? ('#' <method-name><method-parameters>?)?
    Example:
    (1) The target class is a TableModel implementation and has a default constructor
    Code:
    org.jfree.report.test.base.basic.StaticDataSourceFactoryTestSupport
    (2) The target class is a TableModel implementation and has a parametrized constructor
    Code:
    org.jfree.report.test.base.basic.StaticDataSourceFactoryTestSupport(parameter1,parameter2)
    (3) The target class contains a unparameterized method (either static or not, does not matter)
    Code:
    org.jfree.report.test.base.basic.StaticDataSourceFactoryTestSupport#createTableModel
    (4) The target class contains a parameterized method (either static or not, does not matter)
    Code:
    org.jfree.report.test.base.basic.StaticDataSourceFactoryTestSupport#createTableModel(parameter1,parameter2)
    (5) The target class is a bean contains a unparameterized method (not static!) and the object itself uses a default constructor
    Code:
    org.jfree.report.test.base.basic.StaticDataSourceFactoryTestSupport()#createTableModel
    (6) The target class contains a parameterized method (not static!) and the object is instantiated using a parameterized constructor
    Code:
    org.jfree.report.test.base.basic.StaticDataSourceFactoryTestSupport(parameter1,parameter2)#createTableModel(parameter1,parameter2)

    "parameter1" and "parameter2" used in the query are names of a field from the current data-row or the initial report-parameters. The value of these fields will be passed into the method. The algorithm does not check parameter types, it uses the first method that matches the number of parameters and tries for force the parameters in. If that fails, your data-source reports an error.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  4. #4
    Join Date
    Mar 2008
    Posts
    364

    Default

    Hi!
    I have a similar task as the original poster. I have reports that are generated in an application running on a jboss. They get their Table Models from a NamedStaticDataFactory
    which uses a bean with some hibernate views to retrieve their data.
    Now I am asked if it would be possible to edit those reports in the designer. Can I somehow access the method of a bean running in a J2EE-Container from the designer using a "Custom DataSet"? Would I have to change the designer itself to use RMI-Calls or so? I'm not too familiar with these contcepts as I have only been designing reports with simple SQL-Datasources.

    Best reagrds,

    MGIE

  5. #5
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    First: The report designer nor the engine really cares how your class performs the query. We just call the method specified in the query - everything that happens after that is a implementation detail of the class we call.

    That being said:
    If your class is actually a EJB, then calling the EJB from outside should be trivial. But as writing a EJB is a pain, I assume that your class is actually a plain (and sane ) class.
    Otherwise you will either have to refactor your class so that it can work outside of JBoss or you have to write a second client-only version with the same interface as the original one.

    I usually do not deal with application containers. Most of the time I simply have a simple mock-up class that returns some design-time data with the same column names and types. That class is named exactly as the real class and has the same methods. Then RD can work happily with some data that looks good, while you dont have to make a complicated RMI implementation.
    But then again: I usually only do prove of concepts and leave the ugly part of the work to the poor souls who have to clean up after that. You might not be that lucky
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  6. #6
    Join Date
    Mar 2008
    Posts
    364

    Default

    Quote Originally Posted by Taqua View Post
    I usually do not deal with application containers. Most of the time I simply have a simple mock-up class that returns some design-time data with the same column names and types. That class is named exactly as the real class and has the same methods. Then RD can work happily with some data that looks good, while you dont have to make a complicated RMI implementation.
    This is in fact a great idea I didnt think of before. I could just make a class that uses the same hibernate mapping files, that the serverside code uses, which just returns a model with some random sampledata.

    Thanks a lot for that suggestion!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.