Author: snjeza
Date: 2008-05-16 16:29:20 -0400 (Fri, 16 May 2008)
New Revision: 8158
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/.classpath
trunk/birt/plugins/org.jboss.tools.birt.oda/.project
trunk/birt/plugins/org.jboss.tools.birt.oda/META-INF/
trunk/birt/plugins/org.jboss.tools.birt.oda/META-INF/MANIFEST.MF
trunk/birt/plugins/org.jboss.tools.birt.oda/build.properties
trunk/birt/plugins/org.jboss.tools.birt.oda/plugin.properties
trunk/birt/plugins/org.jboss.tools.birt.oda/plugin.xml
trunk/birt/plugins/org.jboss.tools.birt.oda/src/
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/Activator.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/DataTypes.java
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/HibernateDataSetMetaData.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateDriver.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateParameterMetaData.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateQuery.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateResultSet.java
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateResultSetMetaData.java
Log:
Initial import.
Added: trunk/birt/plugins/org.jboss.tools.birt.oda/.classpath
===================================================================
--- trunk/birt/plugins/org.jboss.tools.birt.oda/.classpath (rev
0)
+++ trunk/birt/plugins/org.jboss.tools.birt.oda/.classpath 2008-05-16 20:29:20 UTC (rev
8158)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/birt/plugins/org.jboss.tools.birt.oda/.project
===================================================================
--- trunk/birt/plugins/org.jboss.tools.birt.oda/.project (rev 0)
+++ trunk/birt/plugins/org.jboss.tools.birt.oda/.project 2008-05-16 20:29:20 UTC (rev
8158)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.birt.oda</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/birt/plugins/org.jboss.tools.birt.oda/META-INF/MANIFEST.MF
===================================================================
--- trunk/birt/plugins/org.jboss.tools.birt.oda/META-INF/MANIFEST.MF
(rev 0)
+++ trunk/birt/plugins/org.jboss.tools.birt.oda/META-INF/MANIFEST.MF 2008-05-16 20:29:20
UTC (rev 8158)
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %plugin.name
+Bundle-SymbolicName: org.jboss.tools.birt.oda;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .
+Bundle-Activator: org.jboss.tools.birt.oda.Activator
+Bundle-Vendor: RedHat, Inc.
+Bundle-Localization: plugin
+Export-Package: org.jboss.tools.birt.oda.impl
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.datatools.connectivity.oda;bundle-version="[3.1.0,4.0.0)",
+
org.eclipse.datatools.connectivity.oda.profile;bundle-version="[3.0.4,4.0.0)",
+ org.hibernate.eclipse.console;visibility:=reexport,
+ org.hibernate.eclipse;visibility:=reexport
+Eclipse-LazyStart: true
Added: trunk/birt/plugins/org.jboss.tools.birt.oda/build.properties
===================================================================
--- trunk/birt/plugins/org.jboss.tools.birt.oda/build.properties
(rev 0)
+++ trunk/birt/plugins/org.jboss.tools.birt.oda/build.properties 2008-05-16 20:29:20 UTC
(rev 8158)
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ plugin.properties
Added: trunk/birt/plugins/org.jboss.tools.birt.oda/plugin.properties
===================================================================
--- trunk/birt/plugins/org.jboss.tools.birt.oda/plugin.properties
(rev 0)
+++ trunk/birt/plugins/org.jboss.tools.birt.oda/plugin.properties 2008-05-16 20:29:20 UTC
(rev 8158)
@@ -0,0 +1,13 @@
+###############################################################################
+# Plug-in Configuration
+#
+oda.data.source.id=org.jboss.tools.birt.oda
+#
+###############################################################################
+# NLS String
+###############################################################################
+#
+plugin.name=Hibernate Data Source ODA Runtime Driver
+data.source.name=Hibernate Data Source
+data.set.name=Hibernate Data Set
+connection.profile.name=Hibernate Data Source Connection Profile
Added: trunk/birt/plugins/org.jboss.tools.birt.oda/plugin.xml
===================================================================
--- trunk/birt/plugins/org.jboss.tools.birt.oda/plugin.xml (rev
0)
+++ trunk/birt/plugins/org.jboss.tools.birt.oda/plugin.xml 2008-05-16 20:29:20 UTC (rev
8158)
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+ <extension
+ id="%oda.data.source.id"
+ point="org.eclipse.datatools.connectivity.oda.dataSource">
+ <dataSource
+ driverClass="org.jboss.tools.birt.oda.impl.HibernateDriver"
+ defaultDisplayName="%data.source.name"
+ setThreadContextClassLoader="false"
+ odaVersion="3.1"
+ id="%oda.data.source.id">
+ <properties>
+ <property
+ name="configuration"
+ allowsEmptyValueAsNull="true"
+ defaultDisplayName="Configuration"
+ type="string"
+ isEncryptable="false">
+ </property>
+ <property
+ allowsEmptyValueAsNull="true"
+ defaultDisplayName="Max results"
+ defaultValue="100"
+ isEncryptable="false"
+ name="maxRows"
+ type="string">
+ </property>
+ </properties>
+ </dataSource>
+ <dataSet
+ defaultDisplayName="%data.set.name"
+ id="org.jboss.tools.birt.oda.dataSet">
+ <dataTypeMapping
+ nativeDataTypeCode="1"
+ odaScalarDataType="String"
+ nativeDataType="String">
+ </dataTypeMapping>
+ <dataTypeMapping
+ nativeDataTypeCode="4"
+ odaScalarDataType="Integer"
+ nativeDataType="Integer">
+ </dataTypeMapping>
+ <dataTypeMapping
+ nativeDataTypeCode="8"
+ odaScalarDataType="Double"
+ nativeDataType="Double">
+ </dataTypeMapping>
+ <dataTypeMapping
+ nativeDataTypeCode="3"
+ odaScalarDataType="Decimal"
+ nativeDataType="BigDecimal">
+ </dataTypeMapping>
+ <dataTypeMapping
+ nativeDataTypeCode="91"
+ odaScalarDataType="Date"
+ nativeDataType="Date">
+ </dataTypeMapping>
+ <dataTypeMapping
+ nativeDataTypeCode="92"
+ odaScalarDataType="Time"
+ nativeDataType="Time">
+ </dataTypeMapping>
+ <dataTypeMapping
+ nativeDataTypeCode="93"
+ odaScalarDataType="Timestamp"
+ nativeDataType="Timestamp">
+ </dataTypeMapping>
+ <dataTypeMapping
+ nativeDataTypeCode="16"
+ odaScalarDataType="Boolean"
+ nativeDataType="Boolean">
+ </dataTypeMapping>
+ </dataSet>
+ </extension>
+ <!--
+ <extension
+ point="org.eclipse.datatools.connectivity.connectionProfile">
+ <category
+ name="%data.source.name"
+
parentCategory="org.eclipse.datatools.connectivity.oda.profileCategory"
+ id="%oda.data.source.id">
+ </category>
+ <connectionProfile
+
pingFactory="org.eclipse.datatools.connectivity.oda.profile.OdaConnectionFactory"
+ name="%connection.profile.name"
+ category="%oda.data.source.id"
+ id="%oda.data.source.id">
+ </connectionProfile>
+ <connectionFactory
+ name="ODA Connection Factory"
+ profile="%oda.data.source.id"
+
class="org.eclipse.datatools.connectivity.oda.profile.OdaConnectionFactory"
+ id="org.eclipse.datatools.connectivity.oda.IConnection">
+ </connectionFactory>
+ </extension>
+ -->
+
+</plugin>
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/Activator.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/Activator.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/Activator.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ ******************************************************************************/
+package org.jboss.tools.birt.oda;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ *
+ * @author snjeza
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.birt.oda";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/DataTypes.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/DataTypes.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/DataTypes.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Actuate Corporation.
+ * 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:
+ * Actuate Corporation - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.birt.oda.impl;
+
+
+import java.sql.Types;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.datatools.connectivity.oda.OdaException;
+
+/**
+ * This class hosts the information of data types that are supported by flat
+ * file driver
+ */
+
+public final class DataTypes
+{
+
+ public static final String UNKNOWN = "UNKNOWN";
+ public static final int INT = Types.INTEGER;
+ public static final int LONG = Types.INTEGER;
+ public static final int SHORT = Types.INTEGER;
+ public static final int DOUBLE = Types.DOUBLE;
+ public static final int STRING = Types.VARCHAR;
+ public static final int DATE = Types.DATE;
+ public static final int TIME = Types.TIME;
+ public static final int TIMESTAMP = Types.TIMESTAMP;
+ public static final int BLOB = Types.BLOB;
+ public static final int BIGDECIMAL = Types.NUMERIC;
+ public static final int NULL = Types.NULL;
+
+ private static Map<String,Integer> typeStringIntPair = new
HashMap<String,Integer>();
+
+ static
+ {
+ typeStringIntPair.put( "INTEGER", new Integer( INT ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "INT", new Integer( INT ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "LONG", new Integer( INT ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "SHORT", new Integer( INT ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "DOUBLE", new Integer( DOUBLE ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "STRING", new Integer( STRING ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "DATE", new Integer( DATE ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "TIME", new Integer( TIME ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "TIMESTAMP", new Integer( TIMESTAMP ) );
//$NON-NLS-1$
+ typeStringIntPair.put( "BLOB", new Integer( BLOB ) ); //$NON-NLS-1$
+ typeStringIntPair.put( "BIGDECIMAL", new Integer( BIGDECIMAL ) );
//$NON-NLS-1$
+ typeStringIntPair.put( "BIG_DECIMAL", new Integer( BIGDECIMAL ) );
//$NON-NLS-1$
+ typeStringIntPair.put( "BIG_INTEGER", new Integer( INT ) );
//$NON-NLS-1$
+ typeStringIntPair.put( "NULL", new Integer ( NULL ) );
+ typeStringIntPair.put( UNKNOWN, new Integer ( STRING ) );
+
+ }
+
+ /**
+ * Return the int which stands for the type specified by input argument
+ *
+ * @param typeName
+ * the String value of a Type
+ * @return the int which stands for the type specified by input typeName
+ * @throws OdaException
+ * Once the input argument is not a valid type name
+ */
+ public static int getType( String typeName ) throws OdaException
+ {
+ String name = typeName.trim( ).toUpperCase( );
+ while (name.indexOf(".") > 0) {
+ name = name.substring(name.indexOf(".")+1);
+ }
+ if ( typeStringIntPair.containsKey( name ) )
+ return ( (Integer) typeStringIntPair.get( name ) ).intValue( );
+ throw new OdaException( "Invalid type name : " + typeName);
+ }
+
+ /**
+ * Evaluate whether an input String is a valid type that is supported by driver
+ *
+ * @param typeName
+ * @return
+ */
+ public static boolean isValidType( String typeName )
+ {
+ String name = typeName.trim().toUpperCase();
+ boolean valid = typeStringIntPair.containsKey( name );
+ if (valid) {
+ return true;
+ }
+ while (name.indexOf(".") > 0) {
+ name = name.substring(name.indexOf(".")+1);
+ }
+ return typeStringIntPair.containsKey( name );
+ }
+
+ private DataTypes( )
+ {
+ }
+}
\ No newline at end of file
Added:
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
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateConnection.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ ******************************************************************************/
+package org.jboss.tools.birt.oda.impl;
+
+import java.util.Properties;
+
+import org.eclipse.datatools.connectivity.oda.IConnection;
+import org.eclipse.datatools.connectivity.oda.IDataSetMetaData;
+import org.eclipse.datatools.connectivity.oda.IQuery;
+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;
+
+/**
+ * Implementation class of IConnection for an ODA runtime driver.
+ *
+ * @author snjeza
+ */
+public class HibernateConnection implements IConnection
+{
+ public static final String MAX_ROWS = "maxRows";
+ public static final String CONFIGURATION = "configuration";
+ private boolean isOpen = false;
+ private ConsoleConfiguration consoleConfiguration;
+ private SessionFactory sessionFactory;
+ private Integer maxRows = -1;
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IConnection#open(java.util.Properties)
+ */
+ public void open( Properties connProperties ) throws OdaException
+ {
+ String configurationName = connProperties.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;
+ }
+ }
+ isOpen = (consoleConfiguration != null);
+ 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 + "'");
+ }
+ String maxRowString = connProperties.getProperty(MAX_ROWS);
+ try {
+ maxRows = new Integer(maxRowString);
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IConnection#setAppContext(java.lang.Object)
+ */
+ public void setAppContext( Object context ) throws OdaException
+ {
+ // do nothing; assumes no support for pass-through context
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IConnection#close()
+ */
+ public void close() throws OdaException
+ {
+ consoleConfiguration = null;
+ sessionFactory = null;
+ isOpen = false;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IConnection#isOpen()
+ */
+ public boolean isOpen() throws OdaException
+ {
+ return isOpen;
+ }
+
+ /*
+ * @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 );
+ }
+
+ /*
+ * @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
+ return new HibernateQuery(this);
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IConnection#getMaxQueries()
+ */
+ 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
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IConnection#rollback()
+ */
+ public void rollback() throws OdaException
+ {
+ // do nothing; assumes no transaction support needed
+ }
+
+ public Integer getMaxRows() {
+ return maxRows;
+ }
+
+ public SessionFactory getSessionFactory() {
+ return sessionFactory;
+ }
+
+}
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateDataSetMetaData.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateDataSetMetaData.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateDataSetMetaData.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ ******************************************************************************/
+
+package org.jboss.tools.birt.oda.impl;
+
+import org.eclipse.datatools.connectivity.oda.IConnection;
+import org.eclipse.datatools.connectivity.oda.IDataSetMetaData;
+import org.eclipse.datatools.connectivity.oda.IResultSet;
+import org.eclipse.datatools.connectivity.oda.OdaException;
+
+/**
+ * Implementation class of IDataSetMetaData for an ODA runtime driver.
+ *
+ * @author snjeza
+ */
+public class HibernateDataSetMetaData implements IDataSetMetaData
+{
+ private IConnection connection;
+
+ HibernateDataSetMetaData( IConnection connection )
+ {
+ this.connection = connection;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IDataSetMetaData#getConnection()
+ */
+ public IConnection getConnection() throws OdaException
+ {
+ return connection;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#getDataSourceObjects(java.lang.String,
java.lang.String, java.lang.String, java.lang.String)
+ */
+ public IResultSet getDataSourceObjects( String catalog, String schema, String object,
String version ) throws OdaException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#getDataSourceMajorVersion()
+ */
+ public int getDataSourceMajorVersion() throws OdaException
+ {
+ return 1;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#getDataSourceMinorVersion()
+ */
+ public int getDataSourceMinorVersion() throws OdaException
+ {
+ return 0;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#getDataSourceProductName()
+ */
+ public String getDataSourceProductName() throws OdaException
+ {
+ return "Hibernate Data Source";
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#getDataSourceProductVersion()
+ */
+ public String getDataSourceProductVersion() throws OdaException
+ {
+ return Integer.toString( getDataSourceMajorVersion() ) + "." +
//$NON-NLS-1$
+ Integer.toString( getDataSourceMinorVersion() );
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IDataSetMetaData#getSQLStateType()
+ */
+ public int getSQLStateType() throws OdaException
+ {
+ return IDataSetMetaData.sqlStateSQL99;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#supportsMultipleResultSets()
+ */
+ public boolean supportsMultipleResultSets() throws OdaException
+ {
+ return false;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#supportsMultipleOpenResults()
+ */
+ public boolean supportsMultipleOpenResults() throws OdaException
+ {
+ return false;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#supportsNamedResultSets()
+ */
+ public boolean supportsNamedResultSets() throws OdaException
+ {
+ return false;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDataSetMetaData#supportsNamedParameters()
+ */
+ public boolean supportsNamedParameters() throws OdaException
+ {
+ return false;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IDataSetMetaData#supportsInParameters()
+ */
+ public boolean supportsInParameters() throws OdaException
+ {
+ return true;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IDataSetMetaData#supportsOutParameters()
+ */
+ public boolean supportsOutParameters() throws OdaException
+ {
+ return false;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IDataSetMetaData#getSortMode()
+ */
+ public int getSortMode()
+ {
+ return IDataSetMetaData.sortModeNone;
+ }
+
+}
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateDriver.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateDriver.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateDriver.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ ******************************************************************************/
+package org.jboss.tools.birt.oda.impl;
+
+import org.eclipse.datatools.connectivity.oda.IConnection;
+import org.eclipse.datatools.connectivity.oda.IDriver;
+import org.eclipse.datatools.connectivity.oda.LogConfiguration;
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.eclipse.datatools.connectivity.oda.util.manifest.DataTypeMapping;
+import org.eclipse.datatools.connectivity.oda.util.manifest.ExtensionManifest;
+import org.eclipse.datatools.connectivity.oda.util.manifest.ManifestExplorer;
+
+/**
+ * Implementation class of IDriver for an ODA runtime driver.
+ *
+ * @author snjeza
+ *
+ */
+public class HibernateDriver implements IDriver
+{
+ static String ODA_DATA_SOURCE_ID = "org.jboss.tools.birt.oda";
//$NON-NLS-1$
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IDriver#getConnection(java.lang.String)
+ */
+ public IConnection getConnection( String dataSourceType ) throws OdaException
+ {
+ // assumes that this driver supports only one type of data source,
+ // ignores the specified dataSourceType
+ return new HibernateConnection();
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IDriver#setLogConfiguration(org.eclipse.datatools.connectivity.oda.LogConfiguration)
+ */
+ public void setLogConfiguration( LogConfiguration logConfig ) throws OdaException
+ {
+ // do nothing; assumes simple driver has no logging
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IDriver#getMaxConnections()
+ */
+ public int getMaxConnections() throws OdaException
+ {
+ return 0; // no limit
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IDriver#setAppContext(java.lang.Object)
+ */
+ public void setAppContext( Object context ) throws OdaException
+ {
+ // do nothing; assumes no support for pass-through context
+ }
+
+ /**
+ * Returns the object that represents this extension's manifest.
+ * @throws OdaException
+ */
+ static ExtensionManifest getManifest()
+ throws OdaException
+ {
+ return ManifestExplorer.getInstance()
+ .getExtensionManifest( ODA_DATA_SOURCE_ID );
+ }
+
+ /**
+ * Returns the native data type name of the specified code, as
+ * defined in this data source extension's manifest.
+ * @param nativeTypeCode the native data type code
+ * @return corresponding native data type name
+ * @throws OdaException if lookup fails
+ */
+ static String getNativeDataTypeName( int nativeDataTypeCode )
+ throws OdaException
+ {
+ DataTypeMapping typeMapping =
+ getManifest().getDataSetType( null )
+ .getDataTypeMapping( nativeDataTypeCode );
+ if( typeMapping != null )
+ return typeMapping.getNativeType();
+ return "Non-defined";
+ }
+
+}
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateParameterMetaData.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateParameterMetaData.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateParameterMetaData.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ ******************************************************************************/
+
+package org.jboss.tools.birt.oda.impl;
+
+import org.eclipse.datatools.connectivity.oda.IParameterMetaData;
+import org.eclipse.datatools.connectivity.oda.OdaException;
+
+/**
+ * Implementation class of IParameterMetaData for an ODA runtime driver.
+ *
+ * @author snjeza
+ */
+public class HibernateParameterMetaData implements IParameterMetaData
+{
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IParameterMetaData#getParameterCount()
+ */
+ public int getParameterCount() throws OdaException
+ {
+ return 0;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IParameterMetaData#getParameterMode(int)
+ */
+ public int getParameterMode( int param ) throws OdaException
+ {
+ return IParameterMetaData.parameterModeIn;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.datatools.connectivity.oda.IParameterMetaData#getParameterName(int)
+ */
+ public String getParameterName( int param ) throws OdaException
+ {
+ return null; // name is not available
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IParameterMetaData#getParameterType(int)
+ */
+ public int getParameterType( int param ) throws OdaException
+ {
+ return java.sql.Types.CHAR; // as defined in data set extension manifest
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IParameterMetaData#getParameterTypeName(int)
+ */
+ public String getParameterTypeName( int param ) throws OdaException
+ {
+ int nativeTypeCode = getParameterType( param );
+ return HibernateDriver.getNativeDataTypeName( nativeTypeCode );
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IParameterMetaData#getPrecision(int)
+ */
+ public int getPrecision( int param ) throws OdaException
+ {
+ return -1;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IParameterMetaData#getScale(int)
+ */
+ public int getScale( int param ) throws OdaException
+ {
+ return -1;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IParameterMetaData#isNullable(int)
+ */
+ public int isNullable( int param ) throws OdaException
+ {
+ return IParameterMetaData.parameterNullableUnknown;
+ }
+
+}
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateQuery.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateQuery.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateQuery.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,430 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ ******************************************************************************/
+package org.jboss.tools.birt.oda.impl;
+
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.datatools.connectivity.oda.IParameterMetaData;
+import org.eclipse.datatools.connectivity.oda.IResultSet;
+import org.eclipse.datatools.connectivity.oda.IResultSetMetaData;
+import org.eclipse.datatools.connectivity.oda.IQuery;
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.eclipse.datatools.connectivity.oda.SortSpec;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.type.Type;
+
+/**
+ * Implementation class of IQuery for an ODA runtime driver.
+ *
+ * @author snjeza
+ */
+public class HibernateQuery implements IQuery
+{
+ private Integer _maxRows;
+ private HibernateConnection connection;
+ private HibernateResultSetMetaData resultSetMetaData;
+ private String queryText;
+
+ public HibernateQuery(HibernateConnection connection) {
+ this.connection = connection;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#prepare(java.lang.String)
+ */
+ public void 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 = connection.getSessionFactory().openSession();
+ Query query = session.createQuery(queryText);
+ int maxRows = connection.getMaxRows();
+ if (maxRows > 0) {
+ query.setFirstResult(0);
+ query.setMaxResults(maxRows);
+ }
+ _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('.', ':');
+ }
+
+ this.resultSetMetaData = 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 = connection.getSessionFactory();
+ String[] properties = sf.getClassMetadata(className).getPropertyNames();
+ return( properties);
+ }
+
+ private String getHibernatePropTypes(String className, String property){
+ SessionFactory sf = connection.getSessionFactory();
+ Type hibClassProps = sf.getClassMetadata(className).getPropertyType(property);
+ return(hibClassProps.getName());
+
+ }
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setAppContext(java.lang.Object)
+ */
+ public void setAppContext( Object context ) throws OdaException
+ {
+ // do nothing; assumes no support for pass-through context
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#close()
+ */
+ public void close() throws OdaException
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#getMetaData()
+ */
+ public IResultSetMetaData getMetaData() throws OdaException
+ {
+ return this.resultSetMetaData;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#executeQuery()
+ */
+ public IResultSet executeQuery() throws OdaException
+ {
+ try {
+ return new HibernateResultSet(this);
+ } catch (Exception e) {
+ throw new OdaException(e.getLocalizedMessage());
+ }
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setProperty(java.lang.String,
java.lang.String)
+ */
+ public void setProperty( String name, String value ) throws OdaException
+ {
+ // do nothing; assumes no data set query property
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setMaxRows(int)
+ */
+ public void setMaxRows( int max ) throws OdaException
+ {
+ _maxRows = max;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#getMaxRows()
+ */
+ public int getMaxRows() throws OdaException
+ {
+ return _maxRows;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#clearInParameters()
+ */
+ public void clearInParameters() throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setInt(java.lang.String, int)
+ */
+ public void setInt( String parameterName, int value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setInt(int, int)
+ */
+ public void setInt( int parameterId, int value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setDouble(java.lang.String,
double)
+ */
+ public void setDouble( String parameterName, double value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setDouble(int, double)
+ */
+ public void setDouble( int parameterId, double value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setBigDecimal(java.lang.String,
java.math.BigDecimal)
+ */
+ public void setBigDecimal( String parameterName, BigDecimal value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setBigDecimal(int,
java.math.BigDecimal)
+ */
+ public void setBigDecimal( int parameterId, BigDecimal value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setString(java.lang.String,
java.lang.String)
+ */
+ public void setString( String parameterName, String value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setString(int, java.lang.String)
+ */
+ public void setString( int parameterId, String value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setDate(java.lang.String,
java.sql.Date)
+ */
+ public void setDate( String parameterName, Date value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setDate(int, java.sql.Date)
+ */
+ public void setDate( int parameterId, Date value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setTime(java.lang.String,
java.sql.Time)
+ */
+ public void setTime( String parameterName, Time value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setTime(int, java.sql.Time)
+ */
+ public void setTime( int parameterId, Time value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setTimestamp(java.lang.String,
java.sql.Timestamp)
+ */
+ public void setTimestamp( String parameterName, Timestamp value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setTimestamp(int,
java.sql.Timestamp)
+ */
+ public void setTimestamp( int parameterId, Timestamp value ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setBoolean(java.lang.String,
boolean)
+ */
+ public void setBoolean( String parameterName, boolean value )
+ throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setBoolean(int, boolean)
+ */
+ public void setBoolean( int parameterId, boolean value )
+ throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setNull(java.lang.String)
+ */
+ public void setNull( String parameterName ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#setNull(int)
+ */
+ public void setNull( int parameterId ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to input parameter
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#findInParameter(java.lang.String)
+ */
+ public int findInParameter( String parameterName ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to named input parameter
+ return 0;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#getParameterMetaData()
+ */
+ public IParameterMetaData getParameterMetaData() throws OdaException
+ {
+ /* TODO Auto-generated method stub
+ * Replace with implementation to return an instance
+ * based on this prepared query.
+ */
+ return new HibernateParameterMetaData();
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IQuery#setSortSpec(org.eclipse.datatools.connectivity.oda.SortSpec)
+ */
+ public void setSortSpec( SortSpec sortBy ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to sorting, assumes not supported
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IQuery#getSortSpec()
+ */
+ public SortSpec getSortSpec() throws OdaException
+ {
+ // TODO Auto-generated method stub
+ // only applies to sorting
+ return null;
+ }
+
+ public HibernateConnection getConnection() {
+ return connection;
+ }
+
+ public String getQueryText() {
+ return queryText;
+ }
+
+}
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateResultSet.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateResultSet.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateResultSet.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,418 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ ******************************************************************************/
+
+package org.jboss.tools.birt.oda.impl;
+
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.datatools.connectivity.oda.IBlob;
+import org.eclipse.datatools.connectivity.oda.IClob;
+import org.eclipse.datatools.connectivity.oda.IResultSet;
+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.SessionFactory;
+import org.hibernate.classic.Session;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.type.Type;
+
+/**
+ * Implementation class of IResultSet for an ODA runtime driver.
+ *
+ * @author snjeza
+ */
+public class HibernateResultSet implements IResultSet {
+ private int _maxRows;
+ private HibernateQuery query;
+ private List result;
+ private Iterator iterator;
+ private Object currentRow;
+ private int rowNumber = -1;
+ private boolean wasNull;
+ private Type[] queryReturnTypes;
+ private static DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
+ private Session session;
+
+ public HibernateResultSet(HibernateQuery query) throws OdaException {
+ this.query = query;
+ try {
+ _maxRows = query.getMaxRows();
+ } catch (OdaException e) {
+ // ignore
+ }
+ try {
+ session = query.getConnection().getSessionFactory().openSession();
+ Query q = session.createQuery(query.getQueryText());
+ result = q.list();
+ iterator = result.iterator();
+ this.queryReturnTypes = q.getReturnTypes();
+ } catch (HibernateException e) {
+ throw new OdaException(e.getLocalizedMessage());
+ }
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getMetaData()
+ */
+ public IResultSetMetaData getMetaData() throws OdaException {
+ return query.getMetaData();
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#setMaxRows(int)
+ */
+ public void setMaxRows(int max) throws OdaException {
+ _maxRows = max;
+ }
+
+ /**
+ * Returns the maximum number of rows that can be fetched from this result
+ * set.
+ *
+ * @return the maximum number of rows to fetch.
+ */
+ protected int getMaxRows() {
+ return _maxRows;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#next()
+ */
+ public boolean next() throws OdaException {
+ if (iterator.hasNext()) {
+ currentRow = iterator.next();
+ rowNumber++;
+ return true;
+ }
+ return false;
+
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#close()
+ */
+ public void close() throws OdaException {
+ if (result != null)
+ result.clear();
+ if (session != null)
+ session.close();
+ result = null;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getRow()
+ */
+ public int getRow() throws OdaException {
+ testFetchStarted();
+ return rowNumber + 1;
+ }
+
+ private 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 = query.getConnection().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);
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getString(int)
+ */
+ public String getString(int index) throws OdaException {
+ String result;
+ testFetchStarted();
+ Object rObj = getResult(index);
+ if (rObj == null) {
+ result = null;
+ } else {
+ result = rObj.toString();
+ }
+ this.wasNull = (result == null);
+ return result;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getString(java.lang.String)
+ */
+ public String getString(String columnName) throws OdaException {
+ return getString(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getInt(int)
+ */
+ public int getInt(int index) throws OdaException {
+ int result;
+ testFetchStarted();
+ Object rObj = getResult(index);
+ if (rObj == null) {
+ result = 0;
+ this.wasNull = true;
+ } else {
+ this.wasNull = false;
+ if (rObj instanceof Integer)
+ result = ((Integer) rObj).intValue();
+ else if (rObj instanceof Long)
+ result = ((Long) rObj).intValue();
+ else if (rObj instanceof Short)
+ result = ((Short) rObj).intValue();
+ else
+ throw new RuntimeException("The " + rObj.getClass() + " data type is
not valid.");
+ }
+
+ return result;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getInt(java.lang.String)
+ */
+ public int getInt(String columnName) throws OdaException {
+ return getInt(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getDouble(int)
+ */
+ public double getDouble(int index) throws OdaException {
+ double result;
+ testFetchStarted();
+ Object rObj = getResult(index);
+ if (rObj == null) {
+ result = 0;
+ this.wasNull = true;
+ } else {
+ this.wasNull = false;
+ result = ((Double) rObj).doubleValue();
+ }
+
+ return result;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getDouble(java.lang.String)
+ */
+ public double getDouble(String columnName) throws OdaException {
+ return getDouble(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getBigDecimal(int)
+ */
+ public BigDecimal getBigDecimal(int index) throws OdaException {
+ BigDecimal result;
+ testFetchStarted();
+ Object rObj = getResult(index);
+ if (rObj == null) {
+ result = new BigDecimal(0);
+ this.wasNull = true;
+ } else {
+ this.wasNull = false;
+ result = (BigDecimal) rObj;
+ }
+
+ return result;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IResultSet#getBigDecimal(java.lang.String)
+ */
+ public BigDecimal getBigDecimal(String columnName) throws OdaException {
+ return getBigDecimal(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getDate(int)
+ */
+ public Date getDate(int index) throws OdaException {
+ Date result = null;
+ testFetchStarted();
+ Object rObj = getResult(index);
+ if (rObj == null) {
+ this.wasNull = true;
+ } else {
+ this.wasNull = false;
+ if (rObj instanceof String) {
+ try {
+ result = new Date(dateFormat.parse((String) rObj).getTime());
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ } else {
+ result = (Date) rObj;
+ }
+ }
+
+ return result;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getDate(java.lang.String)
+ */
+ public Date getDate(String columnName) throws OdaException {
+ return getDate(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getTime(int)
+ */
+ public Time getTime(int index) throws OdaException {
+ Time result = null;
+ testFetchStarted();
+ Object rObj = getResult(index);
+ if (rObj == null) {
+ this.wasNull = true;
+ } else {
+ this.wasNull = false;
+ result = (Time) rObj;
+ }
+ return result;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getTime(java.lang.String)
+ */
+ public Time getTime(String columnName) throws OdaException {
+ return getTime(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getTimestamp(int)
+ */
+ public Timestamp getTimestamp(int index) throws OdaException {
+ Timestamp result = null;
+ testFetchStarted();
+ Object rObj = getResult(index);
+ if (rObj == null) {
+ this.wasNull = true;
+ } else {
+ this.wasNull = false;
+ result = (Timestamp) rObj;
+ }
+ return result;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IResultSet#getTimestamp(java.lang.String)
+ */
+ public Timestamp getTimestamp(String columnName) throws OdaException {
+ return getTimestamp(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getBlob(int)
+ */
+ public IBlob getBlob(int index) throws OdaException {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getBlob(java.lang.String)
+ */
+ public IBlob getBlob(String columnName) throws OdaException {
+ return getBlob(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getClob(int)
+ */
+ public IClob getClob(int index) throws OdaException {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getClob(java.lang.String)
+ */
+ public IClob getClob(String columnName) throws OdaException {
+ return getClob(findColumn(columnName));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getBoolean(int)
+ */
+ public boolean getBoolean(int index) throws OdaException {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#getBoolean(java.lang.String)
+ */
+ public boolean getBoolean(String columnName) throws OdaException {
+ return getBoolean(findColumn(columnName));
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#wasNull()
+ */
+ public boolean wasNull() throws OdaException {
+ return wasNull;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSet#findColumn(java.lang.String)
+ */
+ public int findColumn(String columnName) throws OdaException {
+ // TODO replace with data source specific implementation
+
+ // hard-coded for demo purpose
+ int columnId = 1; // dummy column id
+ if (columnName == null || columnName.length() == 0)
+ return columnId;
+ String lastChar = columnName.substring(columnName.length() - 1, 1);
+ try {
+ columnId = Integer.parseInt(lastChar);
+ } catch (NumberFormatException e) {
+ // ignore, use dummy column id
+ }
+ return columnId;
+ }
+
+ private void testFetchStarted() throws OdaException {
+ if (rowNumber < 0)
+ throw new OdaException("Cursor has not been initialized");
+ }
+
+}
Added:
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateResultSetMetaData.java
===================================================================
---
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateResultSetMetaData.java
(rev 0)
+++
trunk/birt/plugins/org.jboss.tools.birt.oda/src/org/jboss/tools/birt/oda/impl/HibernateResultSetMetaData.java 2008-05-16
20:29:20 UTC (rev 8158)
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ ******************************************************************************/
+
+package org.jboss.tools.birt.oda.impl;
+
+import java.util.StringTokenizer;
+
+import org.eclipse.datatools.connectivity.oda.IResultSetMetaData;
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.hibernate.Query;
+import org.hibernate.type.Type;
+
+/**
+ * Implementation class of IResultSetMetaData for an ODA runtime driver.
+ *
+ * @author snjeza
+ */
+public class HibernateResultSetMetaData implements IResultSetMetaData
+{
+
+ private String[] columnName = null;
+ private String[] columnType = null;
+ private String[] columnLabel = null;
+ private String[] columnClass = null;
+ private HibernateQuery query;
+
+ HibernateResultSetMetaData( String[] cName, String[] cType, String[] cLabel, String[]
cClass )
+ throws OdaException
+ {
+ if ( cName == null )
+ throw new OdaException( "Argument cannot be null" );
+ this.columnName = cName;
+ this.columnType = cType;
+ this.columnLabel = cLabel;
+ this.columnClass = cClass;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSetMetaData#getColumnCount()
+ */
+ public int getColumnCount() throws OdaException
+ {
+ return columnName.length;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSetMetaData#getColumnName(int)
+ */
+ public String getColumnName( int index ) throws OdaException
+ {
+ assertIndexValid( index );
+ String name = this.columnName[index - 1].trim( );
+ if (name.indexOf(" ") > 0) {
+ StringTokenizer tokenizer = new StringTokenizer(name," ");
+ String prettyName = null;
+ while (tokenizer.hasMoreTokens()) {
+ prettyName = tokenizer.nextToken();
+ }
+ if (prettyName != null) {
+ name = prettyName;
+ }
+ }
+ return name;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSetMetaData#getColumnLabel(int)
+ */
+ public String getColumnLabel( int index ) throws OdaException
+ {
+ assertIndexValid( index );
+ //"null" in lower case is the mark of "null value". We should not
use
+ // "equalsIgnoreCase"
+ //here for "null" is not a keyword so that we cannot prevent user from
+ // using "null" as labels of
+ //certain columns.
+ if ( this.columnLabel == null
+ || this.columnLabel[index - 1].equals( "null" ) ) //$NON-NLS-1$
+ return this.getColumnName( index );
+
+ return this.columnLabel[index - 1].trim( );
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSetMetaData#getColumnType(int)
+ */
+ public int getColumnType( int index ) throws OdaException
+ {
+ assertIndexValid( index );
+ //get the integer value of the data type specified
+ return (this.columnType[index - 1] == null)? DataTypes.NULL : DataTypes.getType(
columnType[index - 1] ) ;
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IResultSetMetaData#getColumnTypeName(int)
+ */
+ public String getColumnTypeName( int index ) throws OdaException
+ {
+ int nativeTypeCode = getColumnType( index );
+ return HibernateDriver.getNativeDataTypeName( nativeTypeCode );
+ }
+
+ /*
+ * @see
org.eclipse.datatools.connectivity.oda.IResultSetMetaData#getColumnDisplayLength(int)
+ */
+ public int getColumnDisplayLength( int index ) throws OdaException
+ {
+ // TODO replace with data source specific implementation
+ return 8;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSetMetaData#getPrecision(int)
+ */
+ public int getPrecision( int index ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ return -1;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSetMetaData#getScale(int)
+ */
+ public int getScale( int index ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ return -1;
+ }
+
+ /*
+ * @see org.eclipse.datatools.connectivity.oda.IResultSetMetaData#isNullable(int)
+ */
+ public int isNullable( int index ) throws OdaException
+ {
+ // TODO Auto-generated method stub
+ return IResultSetMetaData.columnNullableUnknown;
+ }
+
+ /**
+ * Evaluate whether the value of an index is valid
+ *
+ * @param index
+ * the value of an index
+ * @throws OdaException
+ * if the value is
+ */
+ private void assertIndexValid( int index ) throws OdaException
+ {
+ if ( index > getColumnCount( ) || index < 1 )
+ throw new OdaException( "Invalid index " + index );
+ }
+
+ public String getColumnClass( int index ) throws OdaException
+ {
+ assertIndexValid( index );
+ return ( this.columnClass[index - 1] ) ;
+ }
+}