valchkou / cassandra-driver-mapping

JPA addon for DataStax Java Driver for Cassandra
58 stars 24 forks source link

Apply mapping session to Iterator #39

Closed mgrinolds closed 9 years ago

mgrinolds commented 9 years ago

Hi Eugene,

I have an application where I need to retrieve many columns at once (~10,000), and I'd like to start processing the first returned results before the entire batch comes. Right now, though if I want to apply your mapping session, I have to call: List getFromResultSet(Class clazz, ResultSet rs), which has to loop through the results before returning the List.

I was wondering if you could augment the mapper by adding a call like:

Iterator getIteratorFromResultSet(Class clazz, ResultSet rs) which would just apply a transformation to the rs.iterator() which converts the Row into T upon iteration. Thanks! -Mike
valchkou commented 9 years ago

Hi Mike, I added new API methods which allow you to convert a Row or Collection of Rows into Entity or List of Entities respectively. Just reload 2.1.2 from maven central. Now you can do something like this

        ResultSet rs = session.execute("SELECT * FROM table");  
        Iterator<Row> it = rs.iterator();
        while (it.hasNext()) {
            Entity obj = mapper.getFromRow(Entity.class, it.next());
        }

see unittest for complete sample. search for "getFromRow" Basically as you already have resultSet you may want to keep full control over it provided by datastax and just utilize the mapper purely for mapping/converting purposes. I don't use this feature myself yet and can't judge how well it covers your use case.

If you may have better ideas on design for your request please go share it with me. I am very open to extend API with something handy.

-Eugene

mgrinolds commented 9 years ago

Thanks Eugene - that will work perfectly!