Thursday, May 26, 2011

Best Start-up: Severalnines - at EuroCloud Sweden Award

Severalnines is proud to announce that it won the Best Startup prize at the EuroCloud Sweden Award in Stockholm this week. The company was chosen out of a number of promising startups targeting the emerging cloud computing market.

The jury noted that “Severalnines have a compelling idea to cloud-enable any customer-preferred database in mission-critical setups. Together with a simple-to-use configurator they put the user in control.”

We are quite honored and proud to receive the Best Startup award. Through our flagship product ClusterControl™, it is our objective to make complex database tasks easy and even enjoyable for our users, and above all, to make sure our users can realise the performance, high–availability and cost efficiencies that cloud computing promises.

Articles on the award can be found here:
EuroCloud Announcement (in english)
IDG article (in english)

Wednesday, April 13, 2011

Getting started with Cluster/J - index search and table scans

This post follows the previous post, so set up the environment as described there.
In this example we will perform a full table scan (select * from my_data2) and an index scan (select * from my_data2 where userid=1).

The complete code is here from Severalnines.

Performing a full table scan (no search criteria)
Make sure you have records in the table my_data2.
To perform reads by primary key, we can just use Session::find(..), but here we will do a full table scan.
QueryBuilder qb = s.getQueryBuilder();

/*
* Run the query:
*/
List resultList = query.getResultList();
int count=0;

/*
* Loop over the results
*/

List resultList = query.getResultList();
int count=0;
for (MyData2 result: resultList) {
System.out.println(result.getFriendId());
count++;
}
That is it, if you run the example code, you will see the output.
Done reading X records in Y mssd

Performing a Index scan (search on part of the Primary Key)

The following snippet shows how to setup a EQUAL-filter:
/*
* We want to compare userid=1 (select * from my_data2 where userid=2)
*/
QueryBuilder qb = s.getQueryBuilder();
QueryDomainType dobj = qb.createQueryDefinition(MyData2.class);
/*
* Create a filter, we call this filter 'user_id_filter'
*/

PredicateOperand param = dobj.param("user_id_filter");
/*
* Set the column database column you want to filter on.
* Note: The setting dobj.get("userId") is really strange.
* In the table the column in the database is called userid, and in MyData2.
* The documentation of Cluster/J is very bad here, but
* the getter/setter are getUserId/setUserId, and you have to
* take the word after the get/set (in this case UserId) and change the first
* letter to lower case :(
*/
PredicateOperand column = dobj.get("userId");

/**
* Perform an equal compare
* we want to compare userid=1
*/

Predicate compare=column.equal(param);
dobj.where(compare);

Query query = s.createQuery(dobj);

/*
* Bind the search value to the filter
*/
query.setParameter("user_id_filter", new Long(1));

/*
* Run the query:
*/
List resultList = query.getResultList();
int count=0;

/*
* Loop over the results
*/
for (MyData2 result: resultList) {
System.out.println(result.getFriendId());
count++;
}
That is it for this time. I hope the clusterj documention will become better.