logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

Experimental JSR 169 patch and build instructions: msg#00258

apache.db.derby.devel

Subject: Experimental JSR 169 patch and build instructions

I've managed to get Derby running with a simple test in
J2ME/CDC/Foundation/JSR 169. As promised here are the instructions and
patches to allow early testing.

1) Obtain a J2ME/CDC/Foundation environment with JSR 169 libraries.
I used IBM's WCTME 5.7 (I'm employeed by IBM).
http://www.ibm.com/software/wireless/wctme/

I also found through google another J2ME CDC environment by Emsertec.
I have no experience with it.
http://www.esmertec.com/company/downloads/Jbed_CDC.pdf

2) Setup to compile Derby as documented in BUILDING.txt,
Ensure your Derby trunk is updated to at least revision 154375.

3) Apply the experimental_jsr_169.patch attached to this email.
This is not to be committed into the Derby code, it is just
experimental code.

4) Copy your working Derby ant.properties for derby to a new file,
jsr169.properties

5) Edit jsr169.properties to add setting the variable compile.classpath
to only include the J2ME/CDC/Foundation classes and JSR 169 classes. Eg.
for my WCTME 5.7 setup I added this single line to jsr169.properties.

compile.classpath=C:/_work/p4/djdt1/wctme5.7/ive/lib/jclFoundation10/classes.zip;C:/_work/p4/djdt1/wctme5.7/ive/lib/jdbc.jar

6) Execute these ant commands to build, note that the 'ant engine' using
the jsr169.properites will hit errors, just ignore them.

ant -propertyfile jsr169.properties engine
ant
ant buildjars

8) Now derby.jar should work on J2ME/CDC/Foundation/JSR 169. It should
also work correctly, without any of the limitations below on J2SE.

9) You can compile the attached simple application SimpleAppJSR169.java
that shows how to connect to Derby using the EmbeddedSimpleDataSource.
This can be compiled in a standard JDK, nothing is special about the class.

10) Running the SimpleAppJSR169 with it and derby.jar available in your
classpath should now succeed. This is how I did this for WCTME 5.7.

javac -d . -classpath c:/_work/svn/trunk/jars/insane/derby.jar
SimpleAppJSR169.java

cp="c:/_work/svn/trunk/jars/insane/derby.jar;."

export JAVA_HOME=${wctme}/ive
${wctme}/ive/bin/j9 -jcl:foun10 -Xbootclasspath/a:${jsr169} -cp ${cp}
org.apache.derby.tools.sysinfo

${wctme}/ive/bin/j9 -jcl:foun10 -Xbootclasspath/a:${jsr169} -cp ${cp}
SimpleAppJSR169


** LIMITATIONS **

This is an experimental version only. Triggers and diagnostic virtual
tables will not work. DECIMAL support is implemented by double and thus
is not precise, and may not even work :-). The only testing that has
occurred is running SimpleAppJSR169.

For the intended final functionality I'm working on, please see the
functional spec in Derby-97

http://issues.apache.org/jira/browse/DERBY-97

Any feedback is greatly appreciated.
Dan.

import java.sql.Connection;

/*
* (C) Copyright IBM Corp. 2001, 2004.
*
* The source code for this program is not published or otherwise divested
* of its trade secrets, irrespective of what has been deposited with the
* U.S. Copyright Office.
*/
import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;

import java.util.Properties;


/**
* This sample program is a minimal JDBC application showing
* JDBC access to Derby.
*
* Instructions for how to run this program are
* given in <A HREF=example.html>example.html</A>.
*
* Derby applications can run against Derby running in an embedded
* or a client/server framework. When Derby runs in an embedded framework,
* the Derby application and Derby run in the same JVM. The application
* starts up the Derby engine. When Derby runs in a client/server framework,
* the application runs in a different JVM from Derby. The application only
needs
* to start the client driver, and the connectivity framework provides network
connections.
* (The server must already be running.)
*
* <p>When you run this application, give one of the following arguments:
* * embedded (default, if none specified)
* * jccjdbcclient (if Derby is running embedded in the JCC Server framework)
*
* @author janet
*/
public class SimpleAppJSR169
{
public static void main(String[] args)
{
new SimpleAppJSR169().go(args);
}

void go(String[] args)
{

System.out.println("SimpleAppJSR169 starting in embedded mode.");

try
{
org.apache.derby.jdbc.EmbeddedSimpleDataSource derbyDS =
new org.apache.derby.jdbc.EmbeddedSimpleDataSource();

derbyDS.setUser("user1");
derbyDS.setPassword("password1");
derbyDS.setDatabaseName("derbyDB");
derbyDS.setCreateDatabase("create");

Connection conn = derbyDS.getConnection();

System.out.println("Connected to and created database derbyDB");

conn.setAutoCommit(false);

/*
Creating a statement lets us issue commands against
the connection.
*/
Statement s = conn.createStatement();

/*
We create a table, add a few rows, and update one.
*/
s.execute("create table derbyDB(num int, addr varchar(40))");
System.out.println("Created table derbyDB");
PreparedStatement ps = conn.prepareStatement("insert into derbyDB
values (?, ?)");

ps.setInt(1, 1956);
ps.setString(2, "Webster St.");
ps.execute();
System.out.println("Inserted 1956 Webster");

ps.setInt(1, 1910);
ps.setString(2, "Union St.");
ps.execute();
System.out.println("Inserted 1910 Union");
ps.close();


s.execute(
"update derbyDB set num=180, addr='Grand Ave.' where num=1956");
System.out.println("Updated 1956 Webster to 180 Grand");

s.execute(
"update derbyDB set num=300, addr='Lakeshore Ave.' where
num=180");
System.out.println("Updated 180 Grand to 300 Lakeshore");

/*
We select the rows and verify the results.
*/
ResultSet rs = s.executeQuery(
"SELECT num, addr FROM derbyDB ORDER BY num");

if (!rs.next())
{
throw new Exception("Wrong number of rows");
}

if (rs.getInt(1) != 300)
{
throw new Exception("Wrong row returned");
}

if (!rs.next())
{
throw new Exception("Wrong number of rows");
}

if (rs.getInt(1) != 1910)
{
throw new Exception("Wrong row returned");
}

if (rs.next())
{
throw new Exception("Wrong number of rows");
}

System.out.println("Verified the rows");

s.execute("drop table derbyDB");
System.out.println("Dropped table derbyDB");

/*
We release the result and statement resources.
*/
rs.close();
s.close();
System.out.println("Closed result set and statement");

/*
We end the transaction and the connection.
*/
conn.commit();
conn.close();
System.out.println("Committed transaction and closed connection");

/*
In embedded mode, an application should shut down Derby.
If the application fails to shut down Derby explicitly,
the Derby does not perform a checkpoint when the JVM shuts down,
which means
that the next connection will be slower.
Explicitly shutting down Derby with the URL is preferred.
This style of shutdown will always throw an "exception".
*/
boolean gotSQLExc = false;

try
{
derbyDS.setCreateDatabase(null);
derbyDS.setShutdownDatabase("shutdown");
derbyDS.getConnection();
}
catch (SQLException se)
{
gotSQLExc = true;
}

if (!gotSQLExc)
{
System.out.println("Database did not shut down normally");
}
else
{
System.out.println("Database shut down normally");
}
}
catch (Throwable e)
{
System.out.println("exception thrown:");

if (e instanceof SQLException)
{
printSQLError((SQLException) e);
}
else
{
e.printStackTrace();
}
}

System.out.println("SimpleAppJSR169 finished");
}

static void printSQLError(SQLException e)
{
while (e != null)
{
System.out.println(e.toString());
e = e.getNextException();
}
}
}

Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
===================================================================
--- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (revision
154375)
+++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (working copy)
@@ -76,7 +76,7 @@
* @author ames
*/

-public abstract class EmbedResultSet extends ConnectionChild
+public class EmbedResultSet extends ConnectionChild
implements java.sql.ResultSet, Comparable {

// cursor movement
Index: java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
===================================================================
--- java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
(revision 154375)
+++ java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
(working copy)
@@ -45,7 +45,7 @@
*
* @author ames
*/
-public abstract class EmbedCallableStatement extends EmbedPreparedStatement
+public class EmbedCallableStatement extends EmbedPreparedStatement
implements CallableStatement
{
/*
Index: java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
===================================================================
--- java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(revision 154375)
+++ java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(working copy)
@@ -75,7 +75,7 @@
<LI> JSR169
</UL>
*/
-public abstract class EmbedPreparedStatement
+public class EmbedPreparedStatement
extends EmbedStatement
implements java.sql.PreparedStatement
{
Index: java/engine/org/apache/derby/jdbc/Driver169.java
===================================================================
--- java/engine/org/apache/derby/jdbc/Driver169.java (revision 154375)
+++ java/engine/org/apache/derby/jdbc/Driver169.java (working copy)
@@ -24,7 +24,8 @@
import org.apache.derby.iapi.sql.ResultSet;

import org.apache.derby.impl.jdbc.*;
-
+import org.apache.derby.iapi.services.info.JVMInfo;
+import org.apache.derby.iapi.services.monitor.ModuleSupportable;
import java.sql.Connection;
import java.sql.SQLException;

@@ -41,21 +42,28 @@
@author djd
*/

-public abstract class Driver169 extends InternalDriver {
+public class Driver169 extends InternalDriver
+ implements ModuleSupportable {

public Driver169() {
}
-
+
+ /* (non-Javadoc)
+ * @see
org.apache.derby.iapi.services.monitor.ModuleSupportable#canSupport(java.util.Properties)
+ */
+ public boolean canSupport(Properties properties) {
+ return JVMInfo.J2ME;
+ }
/*
Methods to be overloaded in sub-implementations such as
a tracing driver.
*/
- protected abstract EmbedConnection getNewEmbedConnection(String url,
Properties info)
- throws SQLException ;
-// {
+ protected EmbedConnection getNewEmbedConnection(String url, Properties
info)
+ throws SQLException
+ {
// make a new local connection with a new transaction resource
-// return new EmbedConnection(this, url, info);
-// }
+ return new EmbedConnection30(this, url, info);
+ }


/**
@@ -66,27 +74,19 @@
* @return A nested connection object.
*
*/
- public abstract Connection getNewNestedConnection(EmbedConnection conn);
+ public Connection getNewNestedConnection(EmbedConnection conn)
+ {
+ return new EmbedConnection30(conn);
+ }

/*
** methods to be overridden by subimplementations wishing to insert
** their classes into the mix.
*/
-
- public java.sql.Statement newEmbedStatement(
- EmbedConnection conn,
- boolean forMetaData,
- int resultSetType,
- int resultSetConcurrency,
- int resultSetHoldability)
- {
- return new EmbedStatement(conn, forMetaData, resultSetType,
resultSetConcurrency,
- resultSetHoldability);
- }
/**
@exception SQLException if fails to create statement
*/
- public abstract java.sql.PreparedStatement newEmbedPreparedStatement(
+ public java.sql.PreparedStatement newEmbedPreparedStatement(
EmbedConnection conn,
String stmt,
boolean forMetaData,
@@ -96,36 +96,46 @@
int autoGeneratedKeys,
int[] columnIndexes,
String[] columnNames)
- throws SQLException;
-// {
-// return new EmbedPreparedStatement(conn,stmt,forMetaData,
resultSetType,
-// resultSetConcurrency, resultSetHoldability, autoGeneratedKeys,
columnIndexes,
-// columnNames);
-// }
+ throws SQLException
+
+ {
+ // return null;
+
+ return new EmbedPreparedStatement(conn,stmt,forMetaData,
resultSetType,
+ resultSetConcurrency, resultSetHoldability, autoGeneratedKeys,
columnIndexes,
+ columnNames);
+
+ }
+
/**
@exception SQLException if fails to create statement
*/
- public abstract java.sql.CallableStatement newEmbedCallableStatement(
+ public java.sql.CallableStatement newEmbedCallableStatement(
EmbedConnection conn,
String stmt,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
- throws SQLException;
-// {
-// return new EmbedCallableStatement(conn,stmt, resultSetType,
-// resultSetConcurrency, resultSetHoldability);
-// }
+ throws SQLException
+ {
+ //return null;

+ return new EmbedCallableStatement(conn,stmt, resultSetType,
+ resultSetConcurrency, resultSetHoldability);

- public abstract EmbedResultSet
- newEmbedResultSet(EmbedConnection conn, ResultSet results,
boolean forMetaData, EmbedStatement statement, boolean isAtomic) throws
SQLException;
-// {
-// return new EmbedResultSet(conn, results, forMetaData,
statement, isAtomic, false);
-// }
+ }


+ public EmbedResultSet
+ newEmbedResultSet(EmbedConnection conn, ResultSet results,
+ boolean forMetaData, EmbedStatement statement,
boolean isAtomic) throws SQLException

+ {
+ //return null;
+ return new EmbedResultSet(conn, results, forMetaData,
statement, isAtomic);
+ }
+
+
}


Index: java/engine/org/apache/derby/modules.properties
===================================================================
--- java/engine/org/apache/derby/modules.properties (revision 154375)
+++ java/engine/org/apache/derby/modules.properties (working copy)
@@ -293,3 +293,10 @@
derby.env.dvfJ2=2
derby.env.classes.dvfJ2=java.math.BigDecimal
cloudscape.config.dvfJ2=derby
+
+#J2ME
+
+derby.module.dvfJ2ME=org.apache.derby.iapi.types.CDCDataValueFactory
+cloudscape.config.dvfJ2ME=derby
+derby.module.jdbcJ2ME=org.apache.derby.jdbc.Driver169
+cloudscape.config.jdbcJ2ME=derby
<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo