incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Ellis <jbel...@gmail.com>
Subject Re: Data persistency
Date Wed, 17 Jun 2009 21:01:21 GMT
You're using internal APIs.  Don't do that unless you know what you're doing. :)

The client API is in Cassandra.Client.

We have some sample code here: http://wiki.apache.org/cassandra/ClientExamples

(although none in Java yet, it should still be pretty clear.)

-Jonathan

On Wed, Jun 17, 2009 at 3:54 PM, Ivan Chang<ivan.chang@medigy.com> wrote:
> I tried to insert and retrieve data from a standalone Java program.  While I
> am able to insert and retrieve the correct data from within the Java
> session.  After I terminate the session, and rerun only the data retrieval
> part, the previous inserted data does not exist anymore, throwing a null
> exception.  Here's the code:
>
>         // Get storage-config file location
>
> System.out.println("storage-config="+DatabaseDescriptor.getConfigFileName());
>
>         // Insert some data with key "partner1"
>         RowMutation rm = new RowMutation("Table1", "partner1");
>         ColumnFamily cf = new ColumnFamily("Standard1", "Standard");
>         long now = Calendar.getInstance().getTimeInMillis();
>         System.out.println(now);
>         cf.addColumn("firstname", "John1".getBytes(), now);
>         cf.addColumn("lastname", "Doe1".getBytes(), now);
>         rm.add(cf);
>         try {
>             rm.apply();
>         } catch (Exception e) {
>         }
>
>         // Retrieve data for key "partner1"
>         Table table = Table.open("Table1");
>
>         try {
>             Row result = table.getRow("partner1", "Standard1");
>             System.out.println(result.toString());
>             ColumnFamily cres = result.getColumnFamily("Standard1");
>             Map cols = cres.getColumns();
>             System.out.println(cols.size());
>             Set c = cols.keySet();
>             Iterator it = c.iterator();
>             while (it.hasNext()) {
>                 String cn = (String) it.next();
>                 System.out.println(cn);
>                 System.out.println(new String(cres.getColumn(cn).value()));
>             }
>         } catch (Exception e) {
>             System.out.println("Ex: " + e.getMessage());
>         }
>
> the print out from above is
>
> storage-config=~/Cassandra/trunk/conf/storage-conf.xml
> 1245270260114
> Row(partner1 [ColumnFamily(Standard1 [firstname:false:5@1245270260114,
> lastname:false:4@1245270260114]))]
> 2
> lastname
> Doe1
> firstname
> John1
>
> However, when I commented out the insert part of the above code and try
> retrieve data again by rerunning the main code, I got an exception:
>
> Row(partner1 [)]
> Ex: null
>
> So the data doesn't seem to persist across sessions.
>
> Could someone explain what's wrong with the code?
>
> Thanks,
> Ivan
>

Mime
View raw message