Jump to content
Changes to the Jaspersoft community edition download ×

bklawans

Members
  • Posts

    122
  • Joined

  • Last visited

bklawans's Achievements

Enthusiast

Enthusiast (6/14)

  • First Post Rare
  • Collaborator Rare
  • Conversation Starter Rare
  • Week One Done
  • One Month Later

Recent Badges

0

Reputation

  1. I always put any fonts I need in the JasperServer repository, typically in a /Fonts folder. Then in my report the pdfFontName is "repo:/Fonts/tahoma.ttf". -Barry
  2. I just had to do that for a client, but they own the code so I can't post it. I can tell you what I did though. Basically, you have to create a time based stacked area chart, then change the type of the x-axis to a time period axis. This involves writing a chart customizer that makes some pretty big changes to the underlying JFreeChart. It might be possible to do this via the new component or chart theme API in 3.1, but I was working with the 3.0. You want the area chart to be time based, so you have to author the report using a time series chart. Don't worry that a time series chart in JasperReports is a line chart, as your customizer will change it. This way your customizer gets a nice time based data set, and you can set the usual timePeriodExpression in the jrxml. The first thing your customizer has to do is convert the data set - JFreeChart requires a TimeTableXYDataset for stacked area charts, and JasperReports will have created the chart using a TimeSeriesCollection. You can get the TimeSeriesCollection by calling chart.getPlot().getDataset() on the chart passed in to the customizer. You create a new TimeTableXYDataset. Then for each series in the original dataset loop through all the items in the series. Add a new entry to your dataset using the period, value and key of the original item. Set the dataset in the chart's plot to the one you just created. Create a StackedXYAreaRender2, and set that in the plot. To avoid some JFreeChart issues set the plot's dataset rendering order and series rendering order to FORWARD. Finally, create a PeriodAxis, set the date intervals as appropriate for you chart, and then set that as the domain axis in the plot. I strongly recommend getting the JFreeChart documentation before trying this. Its tricky, but when done you get a chart like the one attached. It contains 30 days worth of data collected hourly, and the date axis is still readable. Post Edited by Barry Klawans at 12/19/08 20:05
  3. Do you want the nulls in the chart but with a different label, or do you want them filtered out? If you want to filter them out completely but can't do it in the query, use the filterExpression to skip rows that are null. The expression can be "new Boolean($F{field} == null)". In iReport there is a button on the query screen that lets you set the filter.
  4. Charts need a numeric value for the y-axis, otherwise the charting engine doesn't know how to space the values out. Do you want the y axis to reflect the duration, or the actual time? If its the duration, just plot the timestamp. From your first question I'm guessing this isn't what you want to do. If you want the labels on the y-axis to be dates, you can plot the values using the numeric timestamp you have, but format the axis labels as Dates. JasperReports supports setting a valueAxisLabelExpression, so you could set that to be "new Date($F{timestamp})" so the conversion to the date is only done for the axis labels. I can't remember where to set that in iReport. The drawback to this approach is that every distinct time value will have a different axis point - you are including the date and time. If you only want the chart axis to include dates, you may need to create a chart customizer that creates the axis labels manually.
  5. Its on JasperForge. Try http://jasperforge.org/plugins/project/project_home.php?group_id=173 It looks like the release packages and wiki content got confused during the recent JasperForge migration - the wiki content is for a different project... You should be able to access the source repository and anonymously check out the source to build. I've started work on a significantly improved version, and have the core JasperReports part all working, but I'm having trouble getting the iReport plugin to work with iReport 3.1. -Barry
  6. You need to convert the numeric field with the number of seconds to a Date field before you can use it with a time axis. How to do this depends on what the numeric field actually means. I recently finished an implementation for a client where they stored times in the database as number of milliseconds since January 1, 1970. (This is a common Unix timestamp.) That happens to be the way Java Dates work, so I declared a Variable in the report with the value "new Date($F{timestamp})" and then used the variable in the chart. There are a couple of things to consider when converting: What does the time "0" mean in your database? You may need to add/subtract an offset to get to the Java base. What is the resolution? Seconds, milliseconds, something else? You may need to scale to get to the Java value. Time Zones? At my clients site, all times were stored in UTC, so I didn't need to worry about time zones. You may have to.-Barry
  7. frblusso writes As we do not use Net BEan (we use IBM software developpment platform with RSA to develop our web applications), I have chosen to download 3.0.0 version of ireport. I think there is a bit of confustion here - the NetBeans version is available using the rich client platform, which means it is a stand alone application that happens to use the NetBeans framework, not a plug in. You download and install it and the user is not aware of the fact that it is based on NetBeans, at least until they go to the preferences pane. -Barry
  8. There is also a project here on JasperForge that allows you to run an Oracle stored procedure directly inside JasperReports. Its a bit old and doesn't include iReport support, but I've started work on a new version that will support iReport 3.1, once I figure out how to get plugins working in the the NetBeans version of iReport. -Barry Klawans
  9. DescriptionThis package adds support for using Oracle Berkeley DB (BDB) as a data source within JasperReports Library, iReport Designer and JasperReports Server. It supports both direct access to a BDB database via the base API and access via the Direct Persistence Layer (DPL) of Berkeley DB. It has been tested with JasperReports Library v3.0, iReport Designer v3.0, JasperReports Server v3.0 and Oracle Berkeley DB 4.7.25. Installing in iReport DesignerBefore you can create a report that uses Berkeley DB as a data source, you need to install the BDB plugin into iReport Designer. The plugin registers "bdb" as a query language and adds support for running a BDB query and automatically creating report fields from the returned data. At the time this document was written the NetBeans based version of iReport Designer was still in early Beta. All testing has been done with the Swing version, and some of the descriptions in this document will not directly match what you see in the NetBeans version. Installing the BDB plugin for iReport Designer is straight forward. Copy the file lib/jasperreports-bdb-<version>.jar to iReport Designer's lib directory. Copy the Berkeley DB jar db-<version>.jar to iReport Designer's lib directory.Add the location of your compiled BDB libraries to the script that starts iReport Designer. Go to $IREPORT_HOME/bin and edit either startup.bat (Windows) or startup.sh (*nix, Mac OS X). Add -Djava.library.path= . As an alternative you can set the environment variable LD_LIBRARY_PATH (use DYLD_LIBRARY_PATH on Mac OS X) to point to your Berkeledy DB libraries, but you must have it set every time you launch iReport Designer. On my system I have the libraries in /usr/local/BerkeledyDB.4.7/lib, so the last line of startup.sh reads java -classpath "$IREPORT_CLASSPATH:$CLASSPATH" -Direport.home=$IREPORT_HOME -Djava.security.policy=$IREPORT_HOME/policy.all -Djava.library.path=/usr/local/BerkeleyDB.4.7/lib it.businesslogic.ireport.gui.MainFrame "$@" If your path to the compiled libraries has spaces in it you must enclose the path in double quotes. This is fairly common on Windows systems. Copy your applications Entities into iReport Designer's lib directory. Exit and restart iReport Designer for your changes to take effectInstalling in JasperReports ServerBefore you can use Oracle Berkeley DB as a data source inside JasperReports Server you need to install the JasperReports Server plugin. The actual JasperReports Server plugin for Oracle Berkeley DB is in the main jar file. In addition there are two support files you need to install as well, to tell JasperReports Server how to access the plugin. Copy the file lib/jasperreports-bdb-<version>.jar to WEB-INF/lib in the JasperReports Server web application home. Copy your Oracle Berkeley DB jar db-<version>.jar to WEB-INF/lib in the JasperReports Server web application home. Copy jasperserver/applicationContext-bdbDS.xml to WEB-INF in the JasperReports Server web application home. Copy jasperserver/bdb.properties to WEB-INF/bundles in the JasperReports Server web application home. Restart the application server that JasperReports Server is deployed in.You need to make sure that the application server can find the compiled libraries use by Oracle Berkeley DB, as described in the section on setting the library path in Installing in iReport Designer. Many application servers have fairly complicated strtup files, so it is often safer to add a line to them setting LD_LIBRARY_PATH (use DYLD_LIBRARY_PATH on Mac OS X) instead of setting a property on the java command line. ConfigurationThe Oracle Berkeley DB data source needs to be configured to be able to open and use your Berkeley DB database. You need to configure the data source everywhere you plan to use it, typically once for use by iReport Designer and once for use by your JasperReports Server. If you plan to use the JasperReports Library directly in your application you will also need to add the configuration to your application via the JasperReports Library properties file. Configuring iReport DesigneriReport Designer allows you to add a data source for each BDB database you want to access. To define a new data source follow these steps: Go to the "Data" menu and select "Connections/Data Sources". In the resulting window press the "New" button. The "Creation of a new datasource" window will appear. Select "Oracle Berkeley DB Connection" from the list and press "Next". In the resulting window specify any name you want as the connection name. Press the "Browse" button next to the Environment field and select your Berkeley DB environment. The distribution includes a sample database at {install_dir}/samples/dpl/baseball_db_dpl. Set the Mode to match your database. If you are using the Direct Persistence Layer be sure to set the mode appropriately. If you are using DPL you must provide the name of the EntityStore to use. If you are using the base API and are using serialized classes you need to specify the name of the database that holds serialized class catalog. You do not need to do this if all the Objects you want to access use either primitive or custom bindings. When you have defined the connection you need to make sure it works. Press the "Test" button. The following window should appear. If it doesn't double check that the environment was set correctly. Once the connection test works, press the "OK" button to close the test results, and press "Save" in the "Connections properties" window. The new data source should appear at the bottom of the list of defined data sources and should be the default. Close the data sources windowYour Berkeley DB database is now ready to use with iReport Designer. If you have additional Berkeley DB databases you want to use, add them by repeating these steps. Be sure to give each database connection a unique name. You can switch between the databases by using the drop down list of defined data sources in the iReport Designer tool bar. Configuring JasperReports ServerJasperReports Server allows you to define custom data sources via the administrator view of the repository. To define a new data source in JasperReports Server follow these steps: Log in to JasperReports Server as an administrator. Go to the "View" menu and select "Repository". When the repository view comes up select the "Data Sources" node in the folder tree.Go to the "New Resource" icon and select "Data Source" in the drop down menu, as shown below. The list of defined data source types will appear. Select "Oracle Berkeley DB" and press "Next>>". Fill in the data source definition. Set the "Name" and "Label" fields to whatever you want. The name is used internally to JasperReports Server and can not contain any white space. The "Path To Database Environment" field is mandatory. If you are using the Direct Persistence Layer (DPL) you need to specify the Entity Store Name, and if you are using the base API and serialization, you need to specify the Clase Database Name. The remaining fields are optional. Note that the database environment path is the path on the server, not a client machine. For the meaning of the rest of the fields see the section on configuring JasperReports Library below. Configuring JasperReports LibraryWhen you deploy your reports inside your application, you will need to tell the JasperReports Library how to connect to your Oracle Berkeley DB database(s). You can do this either by embedding the connection details inside of every report or by placing it inside your jasperreports.properties file. The later method is strongly recommended. To specify the connection information you need at a minimum to specify where the database environment can be found. If you are using the base API and serialization for bindings you also need to specify the name of the database that holds class serialization information. If you are using the Direct Persistence Layer you need to specify the name of the entity store to use. ValuePropertyParameterEnvironmentorg.jasperforge.jaspersoft.berkeleydb.environmentBDB_ENVIRONMENTEntity Storeorg.jasperforge.jaspersoft.berkeleydb.entity_storeBDB_ENTITY_STOREClass Databaseorg.jasperforge.jaspersoft.berkeleydb.class_database_nameBDB_CLASS_DATABASE_NAMEEnable Cachingorg.jasperforge.jaspersoft.berkeleydb.cache_resultsBDB_CACHE_RESULTSA sample jasperreports.properties file that defines a Berkeley DB database that uses serialization and the base API would contain the lines org.jasperforge.jaspersoft.berkeleydb.environment=../baseball_db_bindorg.jasperforge.jaspersoft.berkeleydb.class_database_name=java_class_catalog Using Oracle Berkeley DB With iReport DesignerCreating a report that uses a Berkeley DB database is easy with iReport Designer. First follow the direction above to install the plugin with iReport Designer. Once that is done just follow these steps. In iReport Designer, go to the "File" menu and select "New Document". A "Report properties" window will appear. Give the report any name and other settings you want. Press "OK" when done. You should now be editing a new, empty report. Go to the "Data" menu and select "Report Query". Set the Query language to "bdb". The Query language is set via the drop down list in the upper right corner of the Report Query Window. Type in the query for the report. See the section titled "Query Language" for information on the query syntax used. As an example, if you use the included DPL Baseball database (available at {install_dir}/samples/dpl/baseball_db_dpl) the simple query "Team" will return all the Team entities. After typing your query press the "Read Fields" button. If your query is valid all the returned data will be automatically mapped to query fields and added to your report. Press "OK" to save your query. Look at the "Document structure" panel of iReport Designer and expand the "Fields" section. You should see all of the available fielAt this point you can author and test your report just like one that uses any other type of data source. Query LanguageThe basic syntax for any query that you add to a report is the same regardless of whether the base API or the Direct Persistence Layer is being used. The syntax is either PrimaryName=[searchKey]or PrimaryName[:SecondaryName=[searchKey]]*The actual syntax of how to specify a Name and a SearchKey depends on the API being used, and is described in the following sections. Querying The Direct Persistence LayerWhen using the Direct Persistence Layer a PrimaryName refers to the Entity defined in the database to return. A SecondaryName is the name of a secondary key defined on the Entity the PrimaryName refers to. If you just specify the Entity or the Entity and one or more secondary indices then all the objects contained in that Entity or index are returned. If you want to filter for certain Entities then you need to specify a SearchKey. If you specify a SearchKey on the primary Entity then all the Entities that match are returned. If you specify a SearchKey on a single secondary index then all the Entities that are contained in that index and match the specified search are returned. Finally, if you specify multiple secondary indices and SearchKeys, Entities that match all the specified conditions match. (Berkeley DB only supports "AND" style queries on multiple indices.) DPL Search KeysA search key can either specify an exact value to search for or a range of values. To search for a single value just specify that value as the search key. To search for a range of values the syntax is fromValue-;toValue-. Append a minus sign "-" to either the from or to search key to perform an exclusive search; by default all searches are inclusive. Depending on the data type of the Entity or secondary index, the value in a search key can be a simple value (a Java byte, char, short, int, long, float, double, Byte, Character, Short,Integer, Long, Float, Double, String, Date or BigInteger) or a complex type. A complex type contains one or more named values, where the name of the value is a String and the value is one of the simple types. When the datatype is a simple type, just specify a value as a String. When the datatype is complex, use key=[class.]fieldName=value[class.]fieldName=value*Each field name refers to a single field in the object, and the value is the value to set that field to, as a String. If the field occurs in more than one parent Persistent Object of the Entity, you can disambiguate by specifying which Class the field refers to. Returned DataWhen using DPL every field in the returned Entity can be access via it's name. If the field is a simple type it will be returned as its native Java type. If the field refers to a compound class an object of that class will will be instantiated from the database and returned. You can declare a special field named "_THIS" which will return the actual entity. The contents of Collections and Maps will be similarly restored. For an object to be restored and returned, it must match the current definition of its class in the store. If the definition has evolved since an object was inserted, an attempt to retrieve it will trigger an exception. Querying The Base APIWhen using the base API all objects used as keys and values must be JavaBeans. Only fields in the objects that are exposed as Bean properties will be available inside of a report. A Berkeley DB database created using the base API does not have any metadata about the types of object it contains, or how to bind Objects to database entries. To use a base API database with JasperReports Library you have to embed this information inside the query. You do this by specifying the PrimaryName in the query as PrimaryDatabaseName,keyClass,keyBinding,valueClass,valueBindingThe keyClass and valueClass give the fully qualified class name of the objects used as keys and values in the database. Even when using a secondary database you need to specify the keys and values of the primary, not the secondary. (You specify information about the secondary database keys as part of the secondary search condition, as described below.) Similarly, the keyBinding and valueBinding indicate how to bind the keyClass and valueClass Objects to database entries. If you are using the default Berkeley DB binding for a Java primitive (such as an int field) set the binding to "primitive". If you use the standard Java serialization binding on your key or value specify a binding of "serial". In this case you must have specified a java class catalog as part of the data source definition or an exception will be thrown. Finally, if either or both the key or value use a custom TupleBinding then set the binding to the fully qualified name of the class that implements the binding. When using the base API a PrimaryName in the query refers to a PrimaryDatabase to search, and a SecondaryName referes to SecondaryDatabase. At a minimum a primary database must be specified with an optional search key. When used this way the matching contents of the primary database will be returned. If you specify an optional secondary database, it will be opened against the primary and the entire contents will be returned. If you specify a secondary database and a search key, only objects in the secondary database that match the search key will be returned. If you specify a search key on both the primary database and a secondary, the search on the primary will be ignored. Base API Database NamesA database in the BDB base API is specified by a file name and an optional database name inside that file. You specify both parts of a DatabaseName using a path like expression of file/db-nameIf you have a BDB database file of data.db and want to access the database named "info" inside it, you would use data.db/info as the name of the database. If you need to specify a path to the file, and their is no named database inside it be sure to terminate the path with a trailing "/". Base API Search KeysA search key for the base API can specify either an exact value to search for or that all objects that are greater than or equal to the value should be returned. Since a Berkeley DB database using the base API does not have any metadata about the contents of the database you have to specify information about the type of database being searched and how to bind a database record to the associated object. The basic syntax of a value when using the base API is key=keyClass,binding,value-where keyClass is the Java class for the key, binding indicates the type of binding being used, and value is the actual value of the key, as a String. The syntax for specifying the actual value is identical as when using the Direct Persistence Layer, so see the section titled "DPL Search Keys" for more information. By default, only exact matches are returned. If you append a trailing "-" to a value then all database entries with a value greater than or equal to the specified one will be returned. The key class is the Java class if the key is an Object, or the corresponding class if the key is a primitive type. In other words, if the key is an int field, use a Java Integer instead. The binding field indicates the type of binding being used. If you are using the default Berkeley DB binding for a primitive type, such an integer, specify a binding of "primitive". If you are using Java Serialization for binding a complex type, set the binding type to "serial". Finally, if you use a custom implementation of TupleBinding then give the fully qualified name of your binding class to use. Returned DataEach row in the returned dataset corresponds to a single key/value pair in the database. A top level JavaBean wraps each row, with two accessible fields - "key" and "value". For example, if your key object has a property named "id" then you will access it by declaring a field named "key.id". Similarly, if your value object has a field named "address" you would declare it in the report as "value.address".
  10. DescriptionThis package adds support for using Oracle Berkeley DB Java Edition (BDB JE) as a data source within JasperReports. It supports both direct access to a BDB JE database via the base API and access via the Direct Persistence Layer (DPL) of Berkeley DB. The project includes the actual datasource, an iReport plugin to support creating new reports using BDB JE, and a JasperReports Server plugin so you can deploy your reports on the web or schedule their execution and delivery. InstallingBefore you can create or run a report that uses Berkeley DB as a data source, you need to install the BDB jE plugin into iReport or JasperReports Server. At the time this document was written the NetBeans based version of iReport was still in Beta. All testing has been done with the Swing version, and some of the descriptions in this document will not directly match what you see in the NetBeans version. Installing the BDB plugin for iReport is straight forward. Copy lib/jasperreports-bdb-je-<version>.jar to iReport's lib directory Copy the Berkeley DB Java Edition library je-<version>.jar to iReport's lib directory Copy all the Entities used by your application to iReport's lib directory Exit and restart iReport for your changes to take effectInstalling into JasperReports Server is also straight forward. Copy the file jasperserver/applicationContext-bdbjeDS.xml to the WEB-INF directory of the JasperReports Server web application. Copy the file jasperserver/bdbje.properties to the WEB-INF/bundles directory of the JasperReports Server web application. Copy the file lib/jasperreports-bdb-je-<version>.jar to the WEB-INF/lib directory of the JasperReports Server web application. Copy the Berkeley DB Java Edition jar je-<version>.jar to the WEB-INF/lib directory of the JasperReports Server web application. Copy your applications Entities into WEB-INF/lib in the JasperReports Server web application. Exit and restart JasperReports Server for your changes to take effectConfigurationThe Oracle Berkeley DB Java Edition data source needs to be configured to be able to open and use your Berkeley DB database. You need to configure the data source everywhere you are going to use it, typically once for use by iReport and once for use by JasperReports Server or your application. Configuring iReportiReport allows you to add a datasource for each BDB database you want to access. To define a new datasource follow these steps: Go to the "Data" menu and select "Connections/Data Sources". In the resulting window press the "New" button. The "Connections properties" window will appear. Select "Oracle BerkeleyDB Java Edition Connection" from the list and press "Next" In the resulting window specify any name you want as the connection name. Press the "Browse" button next to the Environment field and select your BerkeleyDB enviornment. The distribution includes a sample database at <install_dir>/samples/dpl/baseball_db_dpl. Set the Mode to match your database. If you are using the Direct Persistence Layer be sure to set the mode appropriately. If you are using DPL and have more than one Entity Store in your database you need to provide the name of the Store to use. A typical DPL database has only one Entity Store so you will rarely need to do this. If you are using the Base API and are using serialized classes you need to specify the name of the database that holds serialized class catalog. You do not need to do this if all the Objects you want to access use either primitive or custom bindings. When you have defined the connection you need to make sure it works. Press the "Test" button. The following window should appear. If it doesn't double check that the environment was set correctly. Once the connection test works, press the "OK" button to close the test results, and press "Save" in the "Connections properties" window. The new datasource should appear at the bottom of the list of defined datasources and should be the default. Close the datasources windowYour BerkeleyDB database is now ready to use with iReport. If you have additional BekeleyDB databases you want to use, add them by repeating these steps. Be sure to give each database connection a unique name. You can switch between the databases by using the drop down list of defined data sources in the iReport tool bar. Configuring JasperReports ServerJasperReports Server allows you to define custom data sources via the administrator's view of the repository. To define a new data source in JasperReports Server follow these steps: Log in to JasperReports Server as an administrator. Go to the "View" menu and select "Repository" When the repository view comes up select the "Data Sources" node in the folder tree. Go to the "New Resource" icon and select "Data Source" in the drop down menu, as shown below. The list of defined data source types will appear. Select "Oracle Berkeley DB Java Edition" and press "Next>>" Fill in the data source definition. The "Name", "Label" and "Path To Database Environment" fields are mandatory, the rest are optional. If you are using the Direct Persistence Layer and have more than one Entity Store in your database, specify the Entity Store to use in the "Entity Store Name" field. If you are using the base API and default serialization of Java classes, specify the name of the class serialization database in the "Class Database Name" field. Press "Save" to save your new data sourceYour new data source is now available to use with a report in JasperReports Server. If you have more than one database environment you want to use with JasperReports Server define an additional data source for each environment. You need JasperReports Server (Professional or Community Edition) 3.0 or later to use Oracle Berkeley DB Java Edition with JasperReports Server. Earlier versions of JasperReports Server used a different plugin architecture for custom data sources. Configuring JasperReportsWhen you deploy your reports inside your application, you will need to tell the JasperReports library how to connect to your Oracle Berkeley DB database(s). You can do this either by embedding the connection details inside of every report or by placing it inside your jasperreports.properties file. The later method is strongly recommended. To specify the connection information you need at a minimum to specify where the database environment can be found. If you are using the base API and serialization for bindings you also need to specify the name of the database that holds class serialization information. If you are using the Direct Persistence Layer and have more than one Entity Store inside the database you need to specify the name of the entity store to use. Environment org.jasperforge.jaspersoft.berkeleydb.javaedition.environment BDB_JE_ENVIRONMENT Entity Store org.jasperforge.jaspersoft.berkeleydb.javaedition.entity_store BDB_JE_ENTITY_STORE Class Database org.jasperforge.jaspersoft.berkeleydb.javaedition.class_database_name BDB_JE_CLASS_DATABASE_NAME Enable Caching org.jasperforge.jaspersoft.berkeleydb.javaedition.cache_results BDB_JE_CACHE_RESULTS A sample jasperreports.properties file that defines a Berkeley DB database that uses serialization and the base API would contain the lines org.jasperforge.jaspersoft.berkeleydb.javaedition.environment=../baseball_db_bind org.jasperforge.jaspersoft.berkeleydb.javaedition.class_database_name=java_class_catalog How To Use With iReportCreating a report that uses a BerkeleyDB database is easy with iReport. First follow the direction above to install the plugin with iReport. Once that is done just follow these steps. In iReport, go to the "File" menu and select "New Document". A "Report properties" window will appear. Give the report any name and other settings you want. Press "OK" when done. You should now be editing a new, empty report. Go to the "Data" menu and select "Report Query" Set the Query language to "bdb-je". Type in the query for the report. See the section titled "Query Language" for information on the query syntax used. As an example, if you use the included DPL Baseball database (available at <install_dir>/samples/dpl/baseball_db_dpl) the simple query "Team" will return all the Team entities. After typing your query press the "Read Fields" button. If your query is valid all the returned data will be automatically mapped to query fields and added to your report. Press "OK" to save your query. Look at the "Document structure" panel of iReport and expand the "Fields" section. You should see all of the avaliable fields. At this point you can author and test your report just like one that uses any other type of data source. Query LanguageThe basic syntax for any query that you add to a report is the same regardless of whether the base API or the Direct Persistence Layer is being used. The syntax is either PrimaryName[[Oracleberkeleydbjavaedition/[=SearchKey | [=SearchKey]] or PrimaryName[[Oracleberkeleydbjavaedition/[:SecondaryName[[=SearchKey | [:SecondaryName[[Oracleberkeleydbjavaedition/=SearchKey|=SearchKey]]]* Querying The Direct Persistence LayerWhen using the Direct Persistence Layer a PrimaryName refers to the Entity defined in the database to return. A SecondaryName is the name of a secondary key defined on the Entity the PrimaryName refers to. If you just specify the Entity or the Entity and one or more secondary indices then all the objects contained in that Entity or index are returned. If you want to filter for certain Entities then you need to specify a SearchKey. If you specify a SearchKey on the primary Entity then all the Entities that match are returned. If you specify a SearchKey on a single secondary index then all the Entities that are contained in that index and match the specified search are returned. Finally, if you specify multiple secondary indices and SearchKeys, Entities that match all the specified conditions match. (BerkeleyDB only supports "AND" style queries on multiple indices.) DPL Search KeysA search key can either specify an exact value to search for or a range of values. To search for a single value just specify that value as the search key. To search for a range of values the syntax is fromValue[[Oracleberkeleydbjavaedition/[- | [-]];toValue[[Oracleberkeleydbjavaedition/[- | [-]] Append a minus sign "-" to either the from or to search key to perform an exclusive search; by default all searches are inclusive. Depending on the datatype of the Entity or secondary index, the value in a search key can be a simple value (a Java byte, char, short, int, long, float, double, Byte, Character, Short, Integer, Long, Float, Double, String, Date or BigInteger) or a complex type. A complex type contains one or more named values, where the name of the value is a String and the value is one of the simple types. When the datatype is a simple type, just specify a value as a String. When the datatype is complex, use key=[[Oracleberkeleydbjavaedition/[class. | [class.]]fieldName=value[[Oracleberkeleydbjavaedition/[[class.| []]fieldName=value]* Each field name refers to a single field in the object, and the value is the value to set that field to, as a String. If the field occurs in more than one parent Persistent Object of the Entity, you can disambiguate by specifying which Class the field refers to. Returned DataWhen using DPL every field in the returned Entity can be access via it's name. If the field is a simple type it will be returned as its native Java type. If the field refers to a compound class an object of that class will will be instantiated from the database and returned. You can declare a special field named "_THIS" which will return the actual entity. The contents of Collections and Maps will be similarly restored. For an object to be restored and returned, it must match the current definition of its class in the store. If the definition has evolved since an object was inserted, an attempt to retrieve it will trigger an exception. Querying The Base APIWhen using the base API all objects used as keys and values must be JavaBeans. Only fields in the objects that are exposed as Bean properties will be available inside of a report. A BerkeleyDB database created using the base API does not have any metadata about the types of object it contains, or how to bind Objects to database entries. To use a base API database with JasperReports you have to embed this information inside the query. You do this by specifying the PrimaryName in the query as PrimaryDatabaseName,keyClass,keyBinding,valueClass,valueBindingThe keyClass and valueClass give the fully qualified class name of the objects used as keys and values in the database. Even when using a secondary database you need to specify the keys and values of the primary, not the secondary. (You specify information about the secondary database keys as part of the secondary search condition, as described below.) Similarly, the keyBinding and valueBinding indicate how to bind the keyClass and valueClass Objects to database entries. If you are using the default BerkeleyDB binding for a Java primitive (such as an int field) set the binding to "primitive". If you use the standard Java serialization binding on your key or value specify a binding of "serial". In this case you must have specified a java class catalog as part of the datasource definition, or an exception will be thrown. Finally, if either or both the key or value use a custom TupleBinding then set the binding to the fully qualified name of the class that implements the binding. When using the base API a PrimaryName in the query refers to a PrimaryDatabase to search, and a SecondaryName referes to a SecondaryDatabase. At a minimum a primary database must be specified with an optional search key. When used this way the matching contents of the primary database will be returned. If you specify an optional secondary database, it will be opened against the primary and the entire contents will be returned. If you specify a secondary database and a search key, only objects in the secondary database that match the search key will be returned. If you specify a search key on both the primary database and a secondary, the search on the primary will be ignored. Base API Search KeysA search key for the base API can specify either an exact value to search for or that all objects that are greater than or equal to the value should be returned. Since a BerkeledyDB database using the base API does not have any metadata about the contents of the database you have to specify information about the type of database being searched and how to bind a database record to the associated object. The basic syntax of a value when using the base API is key=keyClass,binding,value[[Oracleberkeleydbjavaedition/[- | [-]]]where keyClass is the Java class for the key, binding indicates the type of binding being used, and value is the actual value of the key, as a String. The syntax for specifying the actual value is identical as when using the Direct Persistence Layer, so see the section tiled "DPL Search Keys" for more information. By default, only exact matches are returned. If you append a trailing "-" to a value then all database entries with a value greater than or equal to the specified one will be returned. The key class is the Java class if the key is an Object, or the corresponding class if the key is a primitive type. In other words, if the key is an int field, use a Java Integer instead. The binding field indicates the type of binding being used. If you are using the default BerkeleyDB binding for a primitive type, such an integer, specify a binding of "primitive". If you are using Java Serialization for binding a complex type, set the binding type to "serial". Finally, if you use a custom implementation of TupleBinding then give the fully qualified name of your binding class to use. Returned DataEach row in the returned dataset corresponds to a single key/value pair in the database. A top level JavaBean wraps each row, with two accessible fields - "key" and "value". For example, if your key object has a property named "id" then you will access it by declaring a field named "key.id". Similarly, if your value object has a field named "address" you would declare it in the report as "value.address".
  11. Another possible approach is to do it in the query, if your datasource is SQL. Try something like SELECT "Answered" as type, num_answered as value from ... UNION SELECT "Not Answered" as type, num_not_answered as value from ... then you will get two rows, one with the answered data, one with the unanswered data. -Barry
  12. Glad its working for you. One thing I like about your method is that if you ever need to change the number of items, all you have to do is add another bean to your collection. My way would have required changing the report, which would be a bit of a pain. -Barry
  13. I'd guess that the jar containing the oracle stored procedure query executer didn't get copied into the lib directory of iReport 3.0. -Barry
  14. $P!{} is a literal string substitution, while $P{} tries to use any built it parametrization support available by the data source. For example, if the data source is a JDBC connection, all the $P{} parameters are treated as IN parameters in a java.sql.PreparedStatement. This means only values can be parameterized. There are times where you want the query to include things that aren't valid JDBC parameters, such as an order by clause. In this case you have to use the $P!{} syntax. As an example, consider the SQL statement SELECT a, b, c FROM some_table WHERE b > $P{filterParam} ORDER BY $P!{orderParam} In this case the value in the WHERE clause should use $P, because it can be optimized by the JDBC driver. The ORDER BY clause can not be parameterized in a PreparedStatement, so we use the literal substitution form instead. Think of it this way - all parameter values using "$P!" are processed by JasperReports, and the resulting string is passed to the data source driver, that then handles the "$P" parameters. -Barry
  15. One possibility is to manually create a new dataset that uses those three values. The CSV or XML data sources are pretty good for this. For example, you can create a new Variable with a value of "$P{param1}n$P{param2}n$P{param3}". Set the pie chart to use its own dataset. In the pie's dataset, set the dataSourceExpression to Code:new JRCsvDataSource(new StringReader($V{yourVariable})) and see if that works. You will have to use a field called "COLUMN_0" as the name of the value. -Barry
×
×
  • Create New...