Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [birt-dev] How to get metadata from JPA for create theResultSetMetaData


If by "using reflection" means to get the metadata from an actual result
set, it is ok if there is no other way to get a result set meta data
before a query is executed.   If you are trying to support providing
result set metadata immediately after prepare() is called, that means
your ODA driver has to internally execute the query and get the result
set first during prepare().  That approach is feasible, it just means
your ODA driver has to track its query execution state, and return the
result set retrieved during prepare() when a consumer application later
calls IQuery.executeQuery.
BIRT data engine normally tries to get a query's result set metadata
before calling IQuery.executeQuery, but it is able to handle the case
where none is available until after executeQuery is called.  So it is
optional for an ODA driver to support having result set metadata before
executeQuery is called.
Note that if your ODA driver intends to support parameters, it probably
won't be able to use reflection to get the metadata.  An alternative to
consider is whether it makes sense to collect such metadata (of result
set and/or parameters) during design time instead.  If so, such info can
be saved as private properties of a data set query by the custom ODA
designer.  And the data set private properties will then get passed by
BIRT to your ODA runtime driver to use by the call to
IQuery.setProperty(String, String).
BTW, such question is best discussed in BIRT newsgroup.  Please post any
follow-up questions there.

-----Original Message-----
From: birt-dev-bounces@xxxxxxxxxxx [mailto:birt-dev-bounces@xxxxxxxxxxx]
On Behalf Of Victoriano Alfonso Phocco Diaz
Sent: Wednesday, July 02, 2008 10:59 AM
To: birt-dev@xxxxxxxxxxx
Subject: [birt-dev] How to get metadata from JPA for create

Hi BIRT community,

Actually I'm  to make a JPA ODA driver extensions for BIRT, for that I
am based on the implementation in Hibernate ODA Extension since it is an
implementation of JPA.

The problem I have is to implement the method prepare( ) of the
interface for "IQuery"
for sets up array lists to contain the columns, column types, and column

Here I show the code of this method based on the Implementation from
Hibernate and commenting on the part to embed code for support with JPA
wanting :

public void prepare( String query ) throws OdaException
		Query qry = null;
		//Test the connection
                //testConnection( );
		//holds the column types

		ArrayList arColsType = new ArrayList();
		ArrayList arCols = new ArrayList();
               ArrayList arColClass = new ArrayList();
		//holds the column names, also used for labels
		String[] props = null;
			EntityManager em = JPAUtil.currentSession();
			//Create a Hibernate Query	
			query = query.replaceAll("[\\n\\r]+"," ");
			query =query.trim();
			qry = em.createQuery(query);// Create an
instance of Query for executing a  Java Persistence query language
	        /*In Hibernate is like this:
			Get the list of return types from the query
			Type[] qryReturnTypes = qry.getReturnTypes();*/
			//When specifing the HQL "from object" the
returned type is a Hibernate EntityType
			//When the columns are specified the returned
values are normal data types
			//The first half of this if statment handles the
EntityType, the else handles the
			//other case.
			//We are not handling multipe result sets.
			if( qryReturnTypes.length > 0 &&
				for(int j=0; j< qryReturnTypes.length;
					//Get the classname and use
utility function to retrieve data types
					//props holds the column names
					props =
					for( int x = 0; x <
props.length; x++){
						String propType =
HibernateUtil.getHibernatePropTypes(clsName, props[x]);
						//Verify that the data
type is valid
							//Only do this
on Entity Types so we dont have a name collision

							throw new
Messages.getString("Statement.SOURCE_DATA_ERROR") );
				//Extract the column names from the
				props =
				//Get the return types from the Type[]
				for(int t=0; t < qryReturnTypes.length;
					//Verify that the data type is
						throw new OdaException(
Messages.getString("Statement.SOURCE_DATA_ERROR") );

		}catch(Exception e){
			throw new OdaException( e.getLocalizedMessage()
		//this example does not enforce unique column names
		//Create a new ResultSetMetaData object passing in the
column names and data types
		//Have to remove . which BIRT does not allow
		String[] arLabels = (String[])arCols.toArray(new
		for(int j=0; j < arLabels.length; j++){
			arLabels[j] = arLabels[j].replace('.', ':');
		this.resultSetMetaData = new ResultSetMetaData(
		//query is saved for execution
		this.query = query;
	}// end of Prepare()

In the implemntation the Hibernate ODA, is used the API of HIbernate to
obtain the metadata of the query, but in JPA doesn't have something
The same happen to implement the method Object getResult (int rstcol) on
the interface IResulSet.
I thought use reflection to obtain such metada, I am not very familiar
with it but could be a probable solution.

I will be grateful for all the help that I can provide me.

birt-dev mailing list

Back to the top