How to use CachedRowSet in Google App Engine?

I am using Google App Engine (endpoints) to create a simple API service.

I am currently trying to make my database queries faster and more efficient, so I decided to double check where I call ResultSet and Connections and close them.

However I want to use CachedRowSet

, and it almost seems impossible given that when I try to access CachedRowSetImpl()

, the logger returns:

java.lang.NoClassDefFoundError: com.sun.rowset.CachedRowSetImpl is a restricted class. See Google App Engine Developer Guide for more details.

So, I did some research and the Google App Engine Ads Whitelist includes:

javax.sql.rowset.CachedRowSet

but not

com.sun.rowset.CachedRowSetImpl

Is that the point? How can I initialize / use CachedRowSet

otherwise?

My code:

public ResultSet getRecordsWhereInt(String table, String where, int condition) throws SQLException {

   c = DatabaseConnect();

   preStatement = c.prepareStatement("SELECT * FROM " + table + " WHERE " + where + " = ?");

   preStatement.setInt(1, condition);

   CachedRowSet rowset = new CachedRowSetImpl();

   rowset.populate(preStatement.executeQuery());

   c.close();

   return rowset;

}

      

Any help would be / guidance would be appreciated.

Update 1 (09/06/2015):
After researching further I found that you can implement the functionality of CachedRowSetImpl usingRowSetProvider.newFactory().createCachedRowSet();

However, Google has also limited its use RowSetProvider()

.

This left me with only one other white library RowSetFactory

. So I made my own, implementing the RowSetFactory as per Oracle Implementation :

public class CachedRowSetFactory implements RowSetFactory {


    public CachedRowSet createCachedRowSet() throws SQLException {
        return new CachedRowSetImpl();
    }

    public FilteredRowSet createFilteredRowSet() throws SQLException {
        return null;
    }

    public JdbcRowSet createJdbcRowSet() throws SQLException {
        return null;
    }

    public JoinRowSet createJoinRowSet() throws SQLException {
        return null;
    }

    public WebRowSet createWebRowSet() throws SQLException {
        return null;
    }
}

      

And then I used it like this:

CachedRowSet crs = new CachedRowSetFactory().createCachedRowSet();

      

However, even this fails. The above example returns a Null Pointer exception when I try to populate it with a working result set. I am assuming that the factory implementation is not 100% accurate or that I am missing something obvious.

Update 2 (11/06/2015):
I tried to reprogram my own implementation of CachedRowSetImpl and RowSetProvider, duplicating some libraries manually and eliminating libraries not covered in Whitelist App Engines. Failed. I know I need to give it up, but I decided to make this work.

+3


source to share


1 answer


CahecRowSet is an interface, so obviously it's a whitelist.

CachedRowSet interface

I am assuming you are connecting a Google CloudSQL instance.

from the javadoc:



A CachedRowSet object is a container for rows of data that cache its rows in memory, allowing you to work without having to connect to a data source.

What you are trying to do doesn't make sense IMO. AppEngine does not maintain state between different requests, and certainly not when your app is automatically scaled up and new instances are deployed.

Why don't you cache your results in Memcache, this will persist across subsequent requests and different instances.

+1


source







All Articles