cancel
Showing results for 
Search instead for 
Did you mean: 

Using pojo with report desinged with XML/XSD

Former Member
0 Kudos

First, I'm currently using version 12.2.218

I have been trying to figure out a clean way to let a less technical users use designer to design rpt files that use POJO structures when actually exporting the report.  I went down this path because it looked a little difficult to get rpt developers to play with their registry just to make POJOs appear available in designer.

So using  JAXBContext, Marshaller and SchemaOutputResolver, I was able to create a sample .xml and a .xsd for the POJO.

Then create a .rpt with that xml/xsd pair.

Just wish I had more to go on then "invalid alias" or "database connection error detected"

Below is the "work in progress" method to provide the dynamic data I want to pass the report

public static void replaceWithPojoConnection( ITable origTable, DatabaseController dbc, Class<? extends Object> pojoClass,

   Collection<Object> dataSet    ) throws Exception{

      //Tired using a hand written ResultSet implementing class (attempt 3)

            String oldAlias = origTable.getAlias();

            //I know there was some unsuporteded jar that could do this, but I'd rather use something I could tinker and fix..

            //ResultSet rs = new PojoResultSet<Collection<Object>, Object>(dataSet, pojoClass);

            //dbc.setDataSource(rs, oldAlias,oldAlias+"_ResultSet");// this game me "invalid alias" once PojoResultSet behaved to spec

      //Thinking that I just needed to convert the table to a pojo one, I copied from working code that swapped an ODBC connection with a JDBC one:

      // Then stripped the user/password and related items that should not matter for passing a pojo or xml

            ITable newTable = (ITable)origTable.clone(true);

            //String newAlias = oldAlias;// + "_POJO";

            newTable.setAlias(oldAlias);

            //newTable.setQualifiedName(oldAlias);

            IConnectionInfo connectionInfo = newTable.getConnectionInfo();

           

            PropertyBag properties = new PropertyBag();

     // Part of attempt 2: Tried replacing the connection with the set of properties in the comment below:

            /*

           //Yes after the fact I noticed PropertyBagHelper labels this "internal only" I just didn't put back the plain text again...

           //I got these values by querying the properties of a SAP sample rpt that used a "Person" pojo

            properties.put(PropertyBagHelper.CONNINFO_POJO_PACKAGE_NAME, ""); //pojoClass.getPackage().getName());

            properties.put(PropertyBagHelper.CONNINFO_SERVER_TYPE, "Java Beans Connectivity");

            properties.put("PreQEServerName", "CrystalReports.ResultSet");  //? can't find constant for name

            properties.put("PreQEServerType", "Javabean");

            properties.put(PropertyBagHelper.CONNINFO_DATABASE_DLL, "crdb_javabeans.dll");

            properties.put(PropertyBagHelper.CONNINFO_DATASOURCE_TYPE, "POJO");

            properties.put(PropertyBagHelper.CONNINFO_SERVER_NAME, "CrystalReports.ResultSet");

            properties.put(PropertyBagHelper.JAVA_RESULTSET, null);

            properties.put(PropertyBagHelper.CONNINFO_POJO_CLASS_NAME, pojoClass.getSimpleName());

            properties.put(PropertyBagHelper.CONNINFO_POJO_PROJECT_NAME, "CRJavaBeans");

            properties.put(PropertyBagHelper.CONNINFO_POJO_TYPE_PATH, "");//pojoClass.getProtectionDomain().getCodeSource().getLocation().getPath());

            */

           

       //Try 4 - give up and use XML: this is the only thing I could get working

       //Why dosen't the pojo "just work"?  The XSD was built directly from the POJO

       //toc2.xml was the new xml file I created by copying the original and hand editing so the report showed different data (so I knew the new data was used)

            //I got these from my .rpt after querying its current properties...

            properties.put("Local Schema File", "c:\\dev\\toc.xsd");

            properties.put("Server Type", "XML and Web Services");

            //properties.put("PreQEServerName", "c:\\dev\\toc2.xml c:\\dev\\toc.xsd");

            properties.put("Database DLL", "crdb_xml.dll");

            //properties.put("Server Name", "c:\\dev\\toc2.xml c:\\dev\\toc.xsd");

            properties.put("Convert Mulitivalue to Table", Boolean.FALSE);

            properties.put("Local XML File", "c:\\dev\\toc2.xml");

           

            connectionInfo.setAttributes(properties);

            connectionInfo.setKind(ConnectionInfoKind.SQL);

           

            newTable.setConnectionInfo(connectionInfo);

               //newTable.setQualifiedName(origTable.getQualifiedName());

               //dbc.setTableLocation(origTable, newTable);

              

               //._doNotVerifyDB);

           //part 2 of attempt 2 and 3: - as long as I say "do not verify" this line does not fail.

               dbc.replaceConnection(origTable.getConnection(), newTable.getConnection(), DBOptions._doNotVerifyDB);

//               dbc.setDataSource(rs, oldAlias,oldAlias+"_ResultSet");

               //dbc.setTableLocation(origTable, newTable);  (Also tried setTableLocationEx)

               //String newAlias = newTable.getAlias();

               //newTable.

               //String newAlias = newTable.getAlias();

      //Attempt 1 (and part 3 of attempt 2) - pass the Pojo straight to the table ( this game me "invalid alias")

               //dbc.setDataSource(dataSet, pojoClass, oldAlias, oldAlias);//);+"_POJO" 

               //dbc.a

        }

TIA for your help

Oh, and how long does the xml file need to live before I can delete it? after SetDataSource?  or do I need to wait till I actually export the report?

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member245121
Discoverer
0 Kudos

You have to wait till the report is exported.Till that time the xml file is required.

Former Member
0 Kudos

Thanks, I figured it would be like that.  (Was hoping otherwise)

But I'd really like more insight into why I can't switch the table to a POJO one.  That would be much more straight forward.