开发者

Is there anything like .NET DataView/ DataSet for Java, where I can snapshot some data and then perform queries on it?

Context

In our application, we snapshot data from a database using a query that is entered by a super user, and then we save the data from that snapshotting using XML. If I was using .NET, I would use a DataSet (+ DataTables) and DataViews, which are pretty good for that purpose. But I am in the Java world, and my impulse choice was to store the snapshotted data using XML (this can be easily changed at this phase of the project).

Question 1

Is there anything that allows you to snapshot data without having to create its structure first for the Java platform, like a DataSet would do for .NET, and that would allow to perform queries on that data later? I thought about storing it in the database or using Apache Lucene, but for both approaches I would have to manage the database structure, which I would prefer not doing.

Question 2

Supposed you have the following XML:

<data>
<record>
   <user>ravi</user>
   <age>32</age>
   <city>calgary</city>
</record>
<record>
   <user>spiderman</user>
   <age>68</age>
   <city>new york</city>
</record>
</data>

And, on that data, I would execute the following query:开发者_开发知识库

age > 50 or city = 'new york'

The result of that operation would be a subset of the original XML only with the records that match the conditions in the query.

Thanks!


There is something a bit similar called a RowSet, which is part of the JDBC spec. You can get data and cache them in a CacheRowSet that you can manipulate or even update later. Seems like there is also a FilteredRowSet, so that you can create view that shows only the data you want.

This looks relatively similar to ADO.NET DataView and DataSet. Note also that RowSet are not popular in Javaland.

A few more pointers:

  • A small introduction: http://onjava.com/pub/a/onjava/2004/06/23/cachedrowset.html
  • Early access reference implementation: http://java.sun.com/developer/earlyAccess/jdbc/jdbc-- rowset.html
  • JDBC API and Implementations: http://java.sun.com/products/jdbc/download.html#rowset1_0_1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜