Author: snjeza
Date: 2008-06-18 15:29:12 -0400 (Wed, 18 Jun 2008)
New Revision: 8832
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaFactory.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaFactory.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ReflectServerOdaFactory.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaFactory.java
Removed:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaSessionFactory.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaSessionFactory.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaSessionFactory.java
Modified:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateConnection.java
Log:
JBIDE-2220 JBoss BIRT Integration
Copied:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaFactory.java
(from rev 8732,
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaSessionFactory.java)
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaFactory.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaFactory.java 2008-06-18
19:29:12 UTC (rev 8832)
@@ -0,0 +1,41 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.birt.oda;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.jboss.tools.birt.oda.impl.HibernateOdaQuery;
+import org.jboss.tools.birt.oda.impl.HibernateResultSetMetaData;
+
+/**
+ *
+ * @author snjeza
+ *
+ */
+public interface IOdaFactory {
+
+ public static final String MAX_ROWS = "maxRows";
+ public static final String CONFIGURATION = "configuration";
+ public static final String ORG_HIBERNATE_ECLIPSE_BUNDLE_ID =
"org.hibernate.eclipse";
+
+ void close();
+ boolean isOpen();
+ HibernateResultSetMetaData prepare(String queryText) throws OdaException;
+ void setMaxRows(int max);
+ int getMaxRows();
+ void executeQuery(HibernateOdaQuery query) throws OdaException;
+ Iterator getIterator();
+ List getResult();
+ Object getResult(int rstcol) throws OdaException;
+ void next();
+}
Deleted:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaSessionFactory.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaSessionFactory.java 2008-06-18
19:28:59 UTC (rev 8831)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/IOdaSessionFactory.java 2008-06-18
19:29:12 UTC (rev 8832)
@@ -1,41 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2008 JBoss, a division of Red Hat and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- *
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * JBoss, a division of Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.birt.oda;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.datatools.connectivity.oda.OdaException;
-import org.jboss.tools.birt.oda.impl.HibernateOdaQuery;
-import org.jboss.tools.birt.oda.impl.HibernateResultSetMetaData;
-
-/**
- *
- * @author snjeza
- *
- */
-public interface IOdaSessionFactory {
-
- public static final String MAX_ROWS = "maxRows";
- public static final String CONFIGURATION = "configuration";
- public static final String ORG_HIBERNATE_ECLIPSE_BUNDLE_ID =
"org.hibernate.eclipse";
-
- void close();
- boolean isOpen();
- HibernateResultSetMetaData prepare(String queryText) throws OdaException;
- void setMaxRows(int max);
- int getMaxRows();
- void executeQuery(HibernateOdaQuery query) throws OdaException;
- Iterator getIterator();
- List getResult();
- Object getResult(int rstcol) throws OdaException;
- void next();
-}
Copied:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaFactory.java
(from rev 8732,
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaSessionFactory.java)
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaFactory.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaFactory.java 2008-06-18
19:29:12 UTC (rev 8832)
@@ -0,0 +1,76 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.birt.oda.impl;
+
+import java.util.Properties;
+
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.hibernate.HibernateException;
+import org.hibernate.SessionFactory;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
+import org.jboss.tools.birt.oda.IOdaFactory;
+
+/**
+ *
+ * @author snjeza
+ *
+ */
+public class ConsoleConfigurationOdaFactory extends AbstractOdaFactory {
+
+ ConsoleConfiguration consoleConfiguration;
+
+ public ConsoleConfigurationOdaFactory(Properties properties) throws OdaException {
+ getSessionFactory(properties);
+ String maxRowString = properties.getProperty(IOdaFactory.MAX_ROWS);
+ try {
+ setMaxRows(new Integer(maxRowString).intValue());
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ }
+
+ public SessionFactory getSessionFactory(Properties properties) throws OdaException {
+ String configurationName = properties.getProperty(CONFIGURATION);
+ ConsoleConfiguration[] configurations =
KnownConfigurations.getInstance().getConfigurations();
+ for (int i = 0; i < configurations.length; i++) {
+ if (configurations[i].getName().equals(configurationName)) {
+ consoleConfiguration=configurations[i];
+ break;
+ }
+ }
+ if (isOpen()) {
+ try {
+ sessionFactory = consoleConfiguration.getSessionFactory();
+ if (sessionFactory == null) {
+ consoleConfiguration.build();
+ consoleConfiguration.buildSessionFactory();
+ sessionFactory = consoleConfiguration.getSessionFactory();
+ }
+ } catch (HibernateException e) {
+ throw new OdaException(e.getLocalizedMessage());
+ }
+ } else {
+ throw new OdaException("Invalid configuration '" +
configurationName + "'");
+ }
+ return sessionFactory;
+ }
+
+ @Override
+ public void close() {
+ consoleConfiguration = null;
+ super.close();
+ }
+
+ public boolean isOpen() {
+ return consoleConfiguration != null;
+ }
+}
Deleted:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaSessionFactory.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaSessionFactory.java 2008-06-18
19:28:59 UTC (rev 8831)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ConsoleConfigurationOdaSessionFactory.java 2008-06-18
19:29:12 UTC (rev 8832)
@@ -1,268 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2008 JBoss, a division of Red Hat and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- *
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * JBoss, a division of Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.birt.oda.impl;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-import org.eclipse.datatools.connectivity.oda.IResultSetMetaData;
-import org.eclipse.datatools.connectivity.oda.OdaException;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.KnownConfigurations;
-import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.type.Type;
-import org.jboss.tools.birt.oda.IOdaSessionFactory;
-
-/**
- *
- * @author snjeza
- *
- */
-public class ConsoleConfigurationOdaSessionFactory implements
- IOdaSessionFactory {
-
- private ConsoleConfiguration consoleConfiguration;
- private SessionFactory sessionFactory;
- private int maxRows;
- private List result;
- private Iterator iterator;
- private Type[] queryReturnTypes;
- private Object currentRow;
- private HibernateOdaQuery query;
- private org.hibernate.classic.Session session;
- private String queryText;
-
- public ConsoleConfigurationOdaSessionFactory(Properties properties) throws OdaException
{
- getSessionFactory(properties);
- String maxRowString = properties.getProperty(IOdaSessionFactory.MAX_ROWS);
- try {
- maxRows = new Integer(maxRowString);
- } catch (NumberFormatException e) {
- // ignore
- }
- }
-
- public SessionFactory getSessionFactory(Properties properties) throws OdaException {
- String configurationName = properties.getProperty(CONFIGURATION);
- ConsoleConfiguration[] configurations =
KnownConfigurations.getInstance().getConfigurations();
- for (int i = 0; i < configurations.length; i++) {
- if (configurations[i].getName().equals(configurationName)) {
- consoleConfiguration=configurations[i];
- break;
- }
- }
- if (isOpen()) {
- try {
- sessionFactory = consoleConfiguration.getSessionFactory();
- if (sessionFactory == null) {
- consoleConfiguration.build();
- consoleConfiguration.buildSessionFactory();
- sessionFactory = consoleConfiguration.getSessionFactory();
- }
- } catch (HibernateException e) {
- throw new OdaException(e.getLocalizedMessage());
- }
- } else {
- throw new OdaException("Invalid configuration '" +
configurationName + "'");
- }
- return sessionFactory;
- }
-
- public void close() {
- consoleConfiguration = null;
- sessionFactory = null;
- if (session != null) {
- session.close();
- session = null;
- }
- }
-
- public boolean isOpen() {
- return consoleConfiguration != null;
- }
-
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public HibernateResultSetMetaData prepare(String queryText) throws OdaException {
- this.queryText = queryText;
- List arColsType = new ArrayList();
- List arCols = new ArrayList();
- List arColClass = new ArrayList();
- String[] props = null;
- Session session = null;
- try {
- session = getSessionFactory().openSession();
- Query query = session.createQuery(queryText);
- int maxRows = getMaxRows();
- if (maxRows > 0) {
- query.setFirstResult(0);
- query.setMaxResults(maxRows);
- }
- this.maxRows = maxRows;
- Type[] qryReturnTypes = query.getReturnTypes();
- if (qryReturnTypes.length > 0 && qryReturnTypes[0].isEntityType()) {
- for (int j = 0; j < qryReturnTypes.length; j++) {
- String clsName = qryReturnTypes[j].getName();
- props = getHibernateProp(clsName);
- for (int x = 0; x < props.length; x++) {
- String propType = getHibernatePropTypes(clsName,
- props[x]);
- if (DataTypes.isValidType(propType)) {
- arColsType.add(propType);
- arCols.add(props[x]);
- arColClass.add(clsName);
- } else {
- //throw new OdaException("Data Type is Not Valid");
- arColsType.add(DataTypes.UNKNOWN);
- arCols.add(props[x]);
- arColClass.add("java.lang.String");
- }
- }
- }
- } else {
- props = extractColumns(query.getQueryString());
- for (int t = 0; t < qryReturnTypes.length; t++) {
- if (DataTypes.isValidType(qryReturnTypes[t].getName())) {
- arColsType.add(qryReturnTypes[t].getName());
- arCols.add(props[t]);
- } else {
- throw new OdaException("'"
- + qryReturnTypes[t].getName()
- + "' is not a valid type.");
- }
- }
-
- }
- String[] arLabels = (String[]) arCols.toArray(new String[arCols
- .size()]);
- for (int j = 0; j < arLabels.length; j++) {
- arLabels[j] = arLabels[j].replace('.', ':');
- }
-
- return new HibernateResultSetMetaData(arLabels,
- (String[]) arColsType
- .toArray(new String[arColsType.size()]), arLabels,
- (String[]) arColClass
- .toArray(new String[arColClass.size()]));
- } catch (Exception e) {
- throw new OdaException(e.getLocalizedMessage());
- } finally {
- if (session != null) {
- session.close();
- }
- }
- }
-
- private static String[] extractColumns(final String query) {
- int fromPosition = query.toLowerCase().indexOf("from");
- int selectPosition = query.toLowerCase().indexOf("select");
- if (selectPosition >= 0) {
- String columns = query.substring(selectPosition + 6, fromPosition);
- StringTokenizer st = new StringTokenizer(columns, ",");
- List columnList = new ArrayList();
- while (st.hasMoreTokens()) {
- columnList.add(st.nextToken().trim());
- }
- return (String[]) columnList.toArray(new String[0]);
- } else {
- return null;
- }
- }
-
- private String[] getHibernateProp(String className){
- SessionFactory sf = getSessionFactory();
- String[] properties = sf.getClassMetadata(className).getPropertyNames();
- return( properties);
- }
-
- private String getHibernatePropTypes(String className, String property){
- SessionFactory sf = getSessionFactory();
- Type hibClassProps = sf.getClassMetadata(className).getPropertyType(property);
- return(hibClassProps.getName());
-
- }
-
- public int getMaxRows() {
- return maxRows;
- }
-
- public void setMaxRows(int maxRows) {
- this.maxRows = maxRows;
- }
-
- public void executeQuery(HibernateOdaQuery query) throws OdaException {
- this.query = query;
- try {
- session = getSessionFactory().openSession();
- Query q = session.createQuery(queryText);
- result = q.list();
- iterator = result.iterator();
- this.queryReturnTypes = q.getReturnTypes();
- } catch (HibernateException e) {
- throw new OdaException(e.getLocalizedMessage());
- }
- }
-
- public Iterator getIterator() {
- return iterator;
- }
-
- public List getResult() {
- return result;
- }
-
- public Object getResult(int rstcol) throws OdaException {
- Object obj = this.currentRow;
- Object value = null;
- try {
- if (queryReturnTypes.length > 0
- && queryReturnTypes[0].isEntityType()) {
- String checkClass = ((HibernateResultSetMetaData) getMetaData())
- .getColumnClass(rstcol);
- SessionFactory sf = getSessionFactory();
- ClassMetadata metadata = sf.getClassMetadata(checkClass);
- if (metadata == null) {
- metadata = sf.getClassMetadata(obj.getClass());
- }
- value = metadata.getPropertyValue(obj, getMetaData()
- .getColumnName(rstcol), EntityMode.POJO);
- } else {
- if (getMetaData().getColumnCount() == 1) {
- value = obj;
- } else {
- Object[] values = (Object[]) obj;
- value = values[rstcol - 1];
- }
- }
- } catch (Exception e) {
- throw new OdaException(e.getLocalizedMessage());
- }
- return (value);
- }
-
- private IResultSetMetaData getMetaData() throws OdaException {
- return query.getMetaData();
- }
-
- public void next() {
- currentRow = getIterator().next();
- }
-}
Modified:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateConnection.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateConnection.java 2008-06-18
19:28:59 UTC (rev 8831)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateConnection.java 2008-06-18
19:29:12 UTC (rev 8832)
@@ -16,7 +16,7 @@
import org.eclipse.datatools.connectivity.oda.IDataSetMetaData;
import org.eclipse.datatools.connectivity.oda.IQuery;
import org.eclipse.datatools.connectivity.oda.OdaException;
-import org.jboss.tools.birt.oda.IOdaSessionFactory;
+import org.jboss.tools.birt.oda.IOdaFactory;
import org.osgi.framework.Bundle;
/**
@@ -24,103 +24,102 @@
*
* @author snjeza
*/
-public class HibernateConnection implements IConnection
-{
- private IOdaSessionFactory odaSessionFactory;
+public class HibernateConnection implements IConnection {
+ private IOdaFactory odaSessionFactory;
private Map appContext;
-
+
/*
- * @see org.eclipse.datatools.connectivity.oda.IConnection#open(java.util.Properties)
+ * @see
+ * org.eclipse.datatools.connectivity.oda.IConnection#open(java.util.Properties
+ * )
*/
- public void open( Properties connProperties ) throws OdaException
- {
- Bundle bundle =
Platform.getBundle(IOdaSessionFactory.ORG_HIBERNATE_ECLIPSE_BUNDLE_ID);
+ public void open(Properties connProperties) throws OdaException {
+ Bundle bundle = Platform
+ .getBundle(IOdaFactory.ORG_HIBERNATE_ECLIPSE_BUNDLE_ID);
if (bundle != null) {
- odaSessionFactory = new ConsoleConfigurationOdaSessionFactory(connProperties);
+ odaSessionFactory = new ConsoleConfigurationOdaFactory(
+ connProperties);
} else {
- //parentClassLoader = appContext.get(key);
- // FIXME
- odaSessionFactory = new ServerOdaSessionFactory(connProperties);
+ odaSessionFactory = new ServerOdaFactory(connProperties);
}
- }
+ }
/*
- * @see
org.eclipse.datatools.connectivity.oda.IConnection#setAppContext(java.lang.Object)
+ * @see
+ * org.eclipse.datatools.connectivity.oda.IConnection#setAppContext(java
+ * .lang.Object)
*/
- public void setAppContext( Object context ) throws OdaException
- {
- if (!(context instanceof Map)) {
- throw new OdaException("Invalid AppContext");
- }
- this.appContext = (Map) context;
+ public void setAppContext(Object context) throws OdaException {
+ if (!(context instanceof Map)) {
+ throw new OdaException("Invalid AppContext");
+ }
+ this.appContext = (Map) context;
}
/*
* @see org.eclipse.datatools.connectivity.oda.IConnection#close()
*/
- public void close() throws OdaException
- {
- odaSessionFactory.close();
+ public void close() throws OdaException {
+ odaSessionFactory.close();
}
/*
* @see org.eclipse.datatools.connectivity.oda.IConnection#isOpen()
*/
- public boolean isOpen() throws OdaException
- {
+ public boolean isOpen() throws OdaException {
return odaSessionFactory != null && odaSessionFactory.isOpen();
}
/*
- * @see
org.eclipse.datatools.connectivity.oda.IConnection#getMetaData(java.lang.String)
+ * @see
+ * org.eclipse.datatools.connectivity.oda.IConnection#getMetaData(java.lang
+ * .String)
*/
- public IDataSetMetaData getMetaData( String dataSetType ) throws OdaException
- {
- // assumes that this driver supports only one type of data set,
- // ignores the specified dataSetType
- return new HibernateDataSetMetaData( this );
+ public IDataSetMetaData getMetaData(String dataSetType) throws OdaException {
+ // assumes that this driver supports only one type of data set,
+ // ignores the specified dataSetType
+ return new HibernateDataSetMetaData(this);
}
/*
- * @see org.eclipse.datatools.connectivity.oda.IConnection#newQuery(java.lang.String)
+ * @see
+ * org.eclipse.datatools.connectivity.oda.IConnection#newQuery(java.lang
+ * .String)
*/
- public IQuery newQuery( String dataSetType ) throws OdaException
- {
- // assumes that this driver supports only one type of data set,
- // ignores the specified dataSetType
+ public IQuery newQuery(String dataSetType) throws OdaException {
+ // assumes that this driver supports only one type of data set,
+ // ignores the specified dataSetType
return new HibernateOdaQuery(this);
}
/*
* @see org.eclipse.datatools.connectivity.oda.IConnection#getMaxQueries()
*/
- public int getMaxQueries() throws OdaException
- {
- return 0; // no limit
+ public int getMaxQueries() throws OdaException {
+ return 0; // no limit
}
/*
* @see org.eclipse.datatools.connectivity.oda.IConnection#commit()
*/
- public void commit() throws OdaException
- {
- // do nothing; assumes no transaction support needed
+ public void commit() throws OdaException {
+ // do nothing; assumes no transaction support needed
}
/*
* @see org.eclipse.datatools.connectivity.oda.IConnection#rollback()
*/
- public void rollback() throws OdaException
- {
- // do nothing; assumes no transaction support needed
+ public void rollback() throws OdaException {
+ // do nothing; assumes no transaction support needed
}
- /*public SessionFactory getSessionFactory() {
- return odaSessionFactory.getSessionFactory();
- }*/
-
- public IOdaSessionFactory getOdaSessionFactory() {
+ /*
+ * public SessionFactory getSessionFactory() { return
+ * odaSessionFactory.getSessionFactory(); }
+ */
+
+ public IOdaFactory getOdaSessionFactory() {
return odaSessionFactory;
}
-
+
}
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ReflectServerOdaFactory.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ReflectServerOdaFactory.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ReflectServerOdaFactory.java 2008-06-18
19:29:12 UTC (rev 8832)
@@ -0,0 +1,336 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.birt.oda.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import javax.naming.InitialContext;
+
+import org.eclipse.datatools.connectivity.oda.IResultSetMetaData;
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.hibernate.SessionFactory;
+import org.jboss.tools.birt.oda.Activator;
+import org.jboss.tools.birt.oda.IOdaFactory;
+
+/**
+ *
+ * @author snjeza
+ *
+ */
+public class ReflectServerOdaFactory implements IOdaFactory {
+
+ private static final Integer INTZERO = new Integer(0);
+ private static Class[] emptyClassArg = new Class[0];
+ private static Object[] emptyObjectArg = new Object[0];
+ private Object sessionFactory;
+ private Integer maxRows;
+ private String queryText;
+ private List result;
+ private Iterator iterator;
+ private Object currentRow;
+ private HibernateOdaQuery query;
+ private Object session;
+ private Object[] queryReturnTypes;
+
+ public ReflectServerOdaFactory(Properties properties) throws OdaException {
+ getSessionFactory(properties);
+ String maxRowString = properties.getProperty(IOdaFactory.MAX_ROWS);
+ try {
+ maxRows = new Integer(maxRowString);
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ }
+
+ public Object getSessionFactory(Properties properties)
+ throws OdaException {
+ String configurationName = properties.getProperty(CONFIGURATION);
+ if (sessionFactory == null) {
+ InitialContext ctx = null;
+ try {
+ ctx = new InitialContext();
+ Object obj = ctx.lookup("java:/" + configurationName);
+ sessionFactory = obj;
+ SessionFactory sf = (SessionFactory) obj;
+ System.out.println(sf);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new OdaException(
+ "Cannot create Hibernate session factory");
+ }
+
+ }
+ return sessionFactory;
+ }
+
+ public Object getSessionFactory() {
+ return sessionFactory;
+ }
+
+ public void close() {
+ closeSession(session);
+ }
+
+ public boolean isOpen() {
+ if (sessionFactory == null)
+ return false;
+ boolean isClosed = true;
+ try {
+ Method method = sessionFactory.getClass().getMethod("isClosed", new
Class[0]);
+ if (method != null) {
+ Object closed = method.invoke(sessionFactory, new Object[0]);
+ isClosed = ((Boolean) closed).booleanValue();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ return !isClosed;
+ }
+
+ public int getMaxRows() {
+ return maxRows;
+ }
+
+ public HibernateResultSetMetaData prepare(String queryText)
+ throws OdaException {
+ this.queryText = queryText;
+ List arColsType = new ArrayList();
+ List arCols = new ArrayList();
+ List arColClass = new ArrayList();
+ String[] props = null;
+ Object session = null;
+
+ try {
+ session = openSession();
+ Object query = createQuery(session, queryText);
+ if (maxRows > 0) {
+ Method setFirstResult = query.getClass().getMethod("setFirstResult", new
Class[] {Integer.TYPE});
+ setFirstResult.invoke(query, new Object[] {INTZERO});
+ Method setMaxResults = query.getClass().getMethod("setMaxResults", new
Class[] {Integer.TYPE});
+ setMaxResults.invoke(query, new Object[] {new Integer(maxRows)});
+ }
+ Method getReturnTypes = query.getClass().getMethod("getReturnTypes",
emptyClassArg);
+ Object returnType = getReturnTypes.invoke(query, emptyObjectArg);
+ Object[] qryReturnTypes = (Object[]) returnType;
+ if (checkEntityType(qryReturnTypes)) {
+ for (int j = 0; j < qryReturnTypes.length; j++) {
+ String clsName = getReturnTypeName(qryReturnTypes[j]);
+ props = getHibernateProp(clsName);
+ for (int x = 0; x < props.length; x++) {
+ String propType = getHibernatePropTypes(clsName,
+ props[x]);
+ if (DataTypes.isValidType(propType)) {
+ arColsType.add(propType);
+ arCols.add(props[x]);
+ arColClass.add(clsName);
+ } else {
+ arColsType.add(DataTypes.UNKNOWN);
+ arCols.add(props[x]);
+ arColClass.add("java.lang.String");
+ }
+ }
+ }
+ } else {
+ props = extractColumns(queryText);
+ for (int t = 0; t < qryReturnTypes.length; t++) {
+ String typeName = getReturnTypeName(qryReturnTypes[t]);
+ if (DataTypes.isValidType(typeName)) {
+ arColsType.add(typeName);
+ arCols.add(props[t]);
+ } else {
+ throw new OdaException("'"
+ + typeName
+ + "' is not a valid type.");
+ }
+ }
+ }
+ String[] arLabels = (String[]) arCols.toArray(new String[arCols
+ .size()]);
+ for (int j = 0; j < arLabels.length; j++) {
+ arLabels[j] = arLabels[j].replace('.', ':');
+ }
+
+ return new HibernateResultSetMetaData(arLabels,
+ (String[]) arColsType
+ .toArray(new String[arColsType.size()]), arLabels,
+ (String[]) arColClass
+ .toArray(new String[arColClass.size()]));
+ } catch (Exception e) {
+ throw new OdaException(e.getLocalizedMessage());
+ } finally {
+ closeSession(session);
+ }
+ }
+
+ private void closeSession(Object session) {
+ if (session != null) {
+ try {
+ Method close = session.getClass().getMethod("close", emptyClassArg);
+ close.invoke(session, emptyObjectArg);
+ session = null;
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+
+ private boolean checkEntityType(Object[] qryReturnTypes) throws SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
+ Object first = qryReturnTypes[0];
+ Method isEntityType = first.getClass().getMethod("isEntityType",
emptyClassArg);
+ Object ret = isEntityType.invoke(first, emptyObjectArg);
+ boolean isEntity = ((Boolean)ret).booleanValue();
+ return qryReturnTypes.length > 0 && isEntity;
+ }
+
+ private Object createQuery(Object session, String queryText)
+ throws NoSuchMethodException, IllegalAccessException,
+ InvocationTargetException {
+ Method createQuery = session.getClass().getMethod("createQuery", new Class[]
{String.class});
+ Object query = createQuery.invoke(session, new Object[] {queryText});
+ return query;
+ }
+
+ private Object openSession() throws NoSuchMethodException,
+ IllegalAccessException, InvocationTargetException {
+ Object session;
+ Method openSession = sessionFactory.getClass().getMethod("openSession",
emptyClassArg);
+ session = openSession.invoke(sessionFactory, emptyObjectArg);
+ return session;
+ }
+
+ private static String[] extractColumns(final String query) {
+ int fromPosition = query.toLowerCase().indexOf("from");
+ int selectPosition = query.toLowerCase().indexOf("select");
+ if (selectPosition >= 0) {
+ String columns = query.substring(selectPosition + 6, fromPosition);
+ StringTokenizer st = new StringTokenizer(columns, ",");
+ List columnList = new ArrayList();
+ while (st.hasMoreTokens()) {
+ columnList.add(st.nextToken().trim());
+ }
+ return (String[]) columnList.toArray(new String[0]);
+ } else {
+ return null;
+ }
+ }
+
+ private String getReturnTypeName(Object returnType) throws SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
+ Method getName = returnType.getClass().getMethod("getName", emptyClassArg);
+ Object name = getName.invoke(returnType, emptyObjectArg);
+ return (String) name;
+ }
+
+ private String[] getHibernateProp(String className) throws SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException{
+ Object classMetadata = getClassMetadata(className);
+ Method getPropertyNames =
classMetadata.getClass().getMethod("getPropertyNames", emptyClassArg);
+ String[] properties = (String[]) getPropertyNames.invoke(classMetadata,
emptyObjectArg);
+ return properties;
+ }
+
+ private Object getClassMetadata(String className)
+ throws NoSuchMethodException, IllegalAccessException,
+ InvocationTargetException {
+ Method getClassMetadata =
sessionFactory.getClass().getMethod("getClassMetadata", new Class[]
{String.class});
+ Object classMetadata = getClassMetadata.invoke(sessionFactory, new Object[]
{className});
+ return classMetadata;
+ }
+
+ private Object getClassMetadata(Class clazz) throws NoSuchMethodException,
+ IllegalAccessException, InvocationTargetException {
+ Method getClassMetadata = sessionFactory.getClass().getMethod(
+ "getClassMetadata", new Class[] { Class.class });
+ Object classMetadata = getClassMetadata.invoke(sessionFactory,
+ new Object[] { clazz });
+ return classMetadata;
+ }
+
+ private String getHibernatePropTypes(String className, String property) throws
NoSuchMethodException, IllegalAccessException, InvocationTargetException{
+ Object classMetadata = getClassMetadata(className);
+ Method getPropertyType =
classMetadata.getClass().getMethod("getPropertyType", new Class[]
{String.class});
+ Object type = getPropertyType.invoke(classMetadata, new Object[] {property});
+ return getReturnTypeName(type);
+ }
+
+ public void setMaxRows(int max) {
+ maxRows = max;
+ }
+
+ public void executeQuery(HibernateOdaQuery query) throws OdaException {
+ this.query = query;
+ try {
+ session = openSession();
+ Object q = createQuery(session,queryText);
+ Method list = q.getClass().getMethod("list", emptyClassArg);
+ result = (List) list.invoke(q, emptyObjectArg);
+ iterator = result.iterator();
+ Method getReturnTypes = q.getClass().getMethod("getReturnTypes",
emptyClassArg);
+ this.queryReturnTypes = (Object[]) getReturnTypes.invoke(q, emptyObjectArg);
+ } catch (Exception e) {
+ throw new OdaException(e.getLocalizedMessage());
+ }
+ }
+
+ public Iterator getIterator() {
+ return iterator;
+ }
+
+ public List getResult() {
+ return result;
+ }
+
+ public Object getResult(int rstcol) throws OdaException {
+ Object obj = this.currentRow;
+ Object value = null;
+ try {
+ if (checkEntityType(queryReturnTypes)) {
+ String checkClass = ((HibernateResultSetMetaData) getMetaData())
+ .getColumnClass(rstcol);
+ Object metadata = getClassMetadata(checkClass);
+ if (metadata == null) {
+ metadata = getClassMetadata(obj.getClass());
+ }
+ String className = "org.hibernate.EntityMode";
+ Class pojo = Activator.classForName(className, getClass());
+ Field pojoField = pojo.getField("POJO");
+ Object POJO = pojoField.get(null);
+ Class[] parameterTypes = new Class[] {Object.class,String.class, POJO.getClass()};
+ Method getPropertyValue = metadata.getClass().getMethod("getPropertyValue",
parameterTypes);
+ Object[] args = new Object[] {obj,getMetaData().getColumnName(rstcol),POJO};
+ value = getPropertyValue.invoke(metadata, args);
+ } else {
+ if (getMetaData().getColumnCount() == 1) {
+ value = obj;
+ } else {
+ Object[] values = (Object[]) obj;
+ value = values[rstcol - 1];
+ }
+ }
+ } catch (Exception e) {
+ throw new OdaException(e.getLocalizedMessage());
+ }
+ return (value);
+ }
+
+ public void next() {
+ currentRow = getIterator().next();
+ }
+
+ private IResultSetMetaData getMetaData() throws OdaException {
+ return query.getMetaData();
+ }
+}
Copied:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaFactory.java
(from rev 8732,
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaSessionFactory.java)
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaFactory.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaFactory.java 2008-06-18
19:29:12 UTC (rev 8832)
@@ -0,0 +1,47 @@
+package org.jboss.tools.birt.oda.impl;
+
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.hibernate.SessionFactory;
+import org.jboss.tools.birt.oda.IOdaFactory;
+
+public class ServerOdaFactory extends AbstractOdaFactory {
+
+ public ServerOdaFactory(Properties properties) throws OdaException {
+ getSessionFactory(properties);
+ String maxRowString = properties
+ .getProperty(IOdaFactory.MAX_ROWS);
+ try {
+ setMaxRows(new Integer(maxRowString).intValue());
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ }
+
+ public Object getSessionFactory(Properties properties) throws OdaException {
+ String configurationName = properties.getProperty(CONFIGURATION);
+ if (sessionFactory == null) {
+ InitialContext ctx = null;
+ try {
+ ctx = new InitialContext();
+ sessionFactory = (SessionFactory) ctx.lookup("java:/"
+ + configurationName);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new OdaException(
+ "Cannot create Hibernate session factory");
+ }
+
+ }
+ return sessionFactory;
+ }
+
+ public boolean isOpen() {
+ return sessionFactory != null && !sessionFactory.isClosed();
+ }
+
+}
Deleted:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaSessionFactory.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaSessionFactory.java 2008-06-18
19:28:59 UTC (rev 8831)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/ServerOdaSessionFactory.java 2008-06-18
19:29:12 UTC (rev 8832)
@@ -1,333 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2008 JBoss, a division of Red Hat and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- *
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * JBoss, a division of Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.birt.oda.impl;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-import javax.naming.InitialContext;
-
-import org.eclipse.datatools.connectivity.oda.IResultSetMetaData;
-import org.eclipse.datatools.connectivity.oda.OdaException;
-import org.jboss.tools.birt.oda.Activator;
-import org.jboss.tools.birt.oda.IOdaSessionFactory;
-
-/**
- *
- * @author snjeza
- *
- */
-public class ServerOdaSessionFactory implements IOdaSessionFactory {
-
- private static final Integer INTZERO = new Integer(0);
- private static Class[] emptyClassArg = new Class[0];
- private static Object[] emptyObjectArg = new Object[0];
- private Object sessionFactory;
- private Integer maxRows;
- private String queryText;
- private List result;
- private Iterator iterator;
- private Object currentRow;
- private HibernateOdaQuery query;
- private Object session;
- private Object[] queryReturnTypes;
-
- public ServerOdaSessionFactory(Properties properties) throws OdaException {
- getSessionFactory(properties);
- String maxRowString = properties.getProperty(IOdaSessionFactory.MAX_ROWS);
- try {
- maxRows = new Integer(maxRowString);
- } catch (NumberFormatException e) {
- // ignore
- }
- }
-
- public Object getSessionFactory(Properties properties)
- throws OdaException {
- String configurationName = properties.getProperty(CONFIGURATION);
- if (sessionFactory == null) {
- InitialContext ctx = null;
- try {
- ctx = new InitialContext();
- Object obj = ctx.lookup("java:/" + configurationName);
- sessionFactory = obj;
- } catch (Exception e) {
- e.printStackTrace();
- throw new OdaException(
- "Cannot create Hibernate session factory");
- }
-
- }
- return sessionFactory;
- }
-
- public Object getSessionFactory() {
- return sessionFactory;
- }
-
- public void close() {
- closeSession(session);
- }
-
- public boolean isOpen() {
- if (sessionFactory == null)
- return false;
- boolean isClosed = true;
- try {
- Method method = sessionFactory.getClass().getMethod("isClosed", new
Class[0]);
- if (method != null) {
- Object closed = method.invoke(sessionFactory, new Object[0]);
- isClosed = ((Boolean) closed).booleanValue();
- }
- } catch (Exception e) {
- // ignore
- }
- return !isClosed;
- }
-
- public int getMaxRows() {
- return maxRows;
- }
-
- public HibernateResultSetMetaData prepare(String queryText)
- throws OdaException {
- this.queryText = queryText;
- List arColsType = new ArrayList();
- List arCols = new ArrayList();
- List arColClass = new ArrayList();
- String[] props = null;
- Object session = null;
-
- try {
- session = openSession();
- Object query = createQuery(session, queryText);
- if (maxRows > 0) {
- Method setFirstResult = query.getClass().getMethod("setFirstResult", new
Class[] {Integer.TYPE});
- setFirstResult.invoke(query, new Object[] {INTZERO});
- Method setMaxResults = query.getClass().getMethod("setMaxResults", new
Class[] {Integer.TYPE});
- setMaxResults.invoke(query, new Object[] {new Integer(maxRows)});
- }
- Method getReturnTypes = query.getClass().getMethod("getReturnTypes",
emptyClassArg);
- Object returnType = getReturnTypes.invoke(query, emptyObjectArg);
- Object[] qryReturnTypes = (Object[]) returnType;
- if (checkEntityType(qryReturnTypes)) {
- for (int j = 0; j < qryReturnTypes.length; j++) {
- String clsName = getReturnTypeName(qryReturnTypes[j]);
- props = getHibernateProp(clsName);
- for (int x = 0; x < props.length; x++) {
- String propType = getHibernatePropTypes(clsName,
- props[x]);
- if (DataTypes.isValidType(propType)) {
- arColsType.add(propType);
- arCols.add(props[x]);
- arColClass.add(clsName);
- } else {
- arColsType.add(DataTypes.UNKNOWN);
- arCols.add(props[x]);
- arColClass.add("java.lang.String");
- }
- }
- }
- } else {
- props = extractColumns(queryText);
- for (int t = 0; t < qryReturnTypes.length; t++) {
- String typeName = getReturnTypeName(qryReturnTypes[t]);
- if (DataTypes.isValidType(typeName)) {
- arColsType.add(typeName);
- arCols.add(props[t]);
- } else {
- throw new OdaException("'"
- + typeName
- + "' is not a valid type.");
- }
- }
- }
- String[] arLabels = (String[]) arCols.toArray(new String[arCols
- .size()]);
- for (int j = 0; j < arLabels.length; j++) {
- arLabels[j] = arLabels[j].replace('.', ':');
- }
-
- return new HibernateResultSetMetaData(arLabels,
- (String[]) arColsType
- .toArray(new String[arColsType.size()]), arLabels,
- (String[]) arColClass
- .toArray(new String[arColClass.size()]));
- } catch (Exception e) {
- throw new OdaException(e.getLocalizedMessage());
- } finally {
- closeSession(session);
- }
- }
-
- private void closeSession(Object session) {
- if (session != null) {
- try {
- Method close = session.getClass().getMethod("close", emptyClassArg);
- close.invoke(session, emptyObjectArg);
- session = null;
- } catch (Exception e) {
- // ignore
- }
- }
- }
-
- private boolean checkEntityType(Object[] qryReturnTypes) throws SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
- Object first = qryReturnTypes[0];
- Method isEntityType = first.getClass().getMethod("isEntityType",
emptyClassArg);
- Object ret = isEntityType.invoke(first, emptyObjectArg);
- boolean isEntity = ((Boolean)ret).booleanValue();
- return qryReturnTypes.length > 0 && isEntity;
- }
-
- private Object createQuery(Object session, String queryText)
- throws NoSuchMethodException, IllegalAccessException,
- InvocationTargetException {
- Method createQuery = session.getClass().getMethod("createQuery", new Class[]
{String.class});
- Object query = createQuery.invoke(session, new Object[] {queryText});
- return query;
- }
-
- private Object openSession() throws NoSuchMethodException,
- IllegalAccessException, InvocationTargetException {
- Object session;
- Method openSession = sessionFactory.getClass().getMethod("openSession",
emptyClassArg);
- session = openSession.invoke(sessionFactory, emptyObjectArg);
- return session;
- }
-
- private static String[] extractColumns(final String query) {
- int fromPosition = query.toLowerCase().indexOf("from");
- int selectPosition = query.toLowerCase().indexOf("select");
- if (selectPosition >= 0) {
- String columns = query.substring(selectPosition + 6, fromPosition);
- StringTokenizer st = new StringTokenizer(columns, ",");
- List columnList = new ArrayList();
- while (st.hasMoreTokens()) {
- columnList.add(st.nextToken().trim());
- }
- return (String[]) columnList.toArray(new String[0]);
- } else {
- return null;
- }
- }
-
- private String getReturnTypeName(Object returnType) throws SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
- Method getName = returnType.getClass().getMethod("getName", emptyClassArg);
- Object name = getName.invoke(returnType, emptyObjectArg);
- return (String) name;
- }
-
- private String[] getHibernateProp(String className) throws SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException{
- Object classMetadata = getClassMetadata(className);
- Method getPropertyNames =
classMetadata.getClass().getMethod("getPropertyNames", emptyClassArg);
- String[] properties = (String[]) getPropertyNames.invoke(classMetadata,
emptyObjectArg);
- return properties;
- }
-
- private Object getClassMetadata(String className)
- throws NoSuchMethodException, IllegalAccessException,
- InvocationTargetException {
- Method getClassMetadata =
sessionFactory.getClass().getMethod("getClassMetadata", new Class[]
{String.class});
- Object classMetadata = getClassMetadata.invoke(sessionFactory, new Object[]
{className});
- return classMetadata;
- }
-
- private Object getClassMetadata(Class clazz) throws NoSuchMethodException,
- IllegalAccessException, InvocationTargetException {
- Method getClassMetadata = sessionFactory.getClass().getMethod(
- "getClassMetadata", new Class[] { Class.class });
- Object classMetadata = getClassMetadata.invoke(sessionFactory,
- new Object[] { clazz });
- return classMetadata;
- }
-
- private String getHibernatePropTypes(String className, String property) throws
NoSuchMethodException, IllegalAccessException, InvocationTargetException{
- Object classMetadata = getClassMetadata(className);
- Method getPropertyType =
classMetadata.getClass().getMethod("getPropertyType", new Class[]
{String.class});
- Object type = getPropertyType.invoke(classMetadata, new Object[] {property});
- return getReturnTypeName(type);
- }
-
- public void setMaxRows(int max) {
- maxRows = max;
- }
-
- public void executeQuery(HibernateOdaQuery query) throws OdaException {
- this.query = query;
- try {
- session = openSession();
- Object q = createQuery(session,queryText);
- Method list = q.getClass().getMethod("list", emptyClassArg);
- result = (List) list.invoke(q, emptyObjectArg);
- iterator = result.iterator();
- Method getReturnTypes = q.getClass().getMethod("getReturnTypes",
emptyClassArg);
- this.queryReturnTypes = (Object[]) getReturnTypes.invoke(q, emptyObjectArg);
- } catch (Exception e) {
- throw new OdaException(e.getLocalizedMessage());
- }
- }
-
- public Iterator getIterator() {
- return iterator;
- }
-
- public List getResult() {
- return result;
- }
-
- public Object getResult(int rstcol) throws OdaException {
- Object obj = this.currentRow;
- Object value = null;
- try {
- if (checkEntityType(queryReturnTypes)) {
- String checkClass = ((HibernateResultSetMetaData) getMetaData())
- .getColumnClass(rstcol);
- Object metadata = getClassMetadata(checkClass);
- if (metadata == null) {
- metadata = getClassMetadata(obj.getClass());
- }
- String className = "org.hibernate.EntityMode";
- Class pojo = Activator.classForName(className, getClass());
- Field pojoField = pojo.getField("POJO");
- Object POJO = pojoField.get(null);
- Class[] parameterTypes = new Class[] {Object.class,String.class, POJO.getClass()};
- Method getPropertyValue = metadata.getClass().getMethod("getPropertyValue",
parameterTypes);
- Object[] args = new Object[] {obj,getMetaData().getColumnName(rstcol),POJO};
- value = getPropertyValue.invoke(metadata, args);
- } else {
- if (getMetaData().getColumnCount() == 1) {
- value = obj;
- } else {
- Object[] values = (Object[]) obj;
- value = values[rstcol - 1];
- }
- }
- } catch (Exception e) {
- throw new OdaException(e.getLocalizedMessage());
- }
- return (value);
- }
-
- public void next() {
- currentRow = getIterator().next();
- }
-
- private IResultSetMetaData getMetaData() throws OdaException {
- return query.getMetaData();
- }
-}