|
GettingStarted
Getting started with hs4j
Featured IntroductionHS4J is a practical HandlerSocket client for java.HandlerSocket is a MySql plugin developed by akira higuchi to make MySql as a NoSQL storage. New a clientimport com.google.code.hs4j.HSClient; import com.google.code.hs4j.impl.HSClientImpl; HSClient hsClient = new HSClientImpl(new InetSocketAddress(9999)); HSFClient is a main class to talk with handlersocket,it's thread-safe. HS4J also could be configured a connection pool: //100-connections pool HSClient hsClient = new HSClientImpl(new InetSocketAddress(9999),100); Open Indeximport com.google.code.hs4j.IndexSession;
IndexSession session = hsClient.openIndexSession(db, table,
"PRIMARY", columns);The IndexSession represent an opened-index with a auto-generated indexid and it's thread-safe too.You can special a indexid: IndexSession session = hsClient.openIndexSession(indexid,db, table, "PRIMARY", columns); Find dataimport java.sql.ResultSet;
final String[] keys = { "dennis", "killme2008@gmail.com" };
ResultSet rs = session.find(keys);
while(rs.next()){
String name=rs.getString(1);
String mail=rs.getString(2);
}
The result returned as a java.sql.ResultSet. Insert Datathis.session.insert(new String[] { "0", "dennis",
"killme2008@gmail.com", "27", "2010-11-28 13:24:00" })But ModifyStatement is recommended ModifyStatement stmt = this.session.createStatement();
stmt.setInt(1, 0);
stmt.setString(2, "dennis");
stmt.setString(3, "killme2008@gmail.com");
stmt.setInt(4, 27);
stmt.setString(5, "2010-11-28 13:24:00");
boolean result=stmt.insert();
Update dataimport com.google.code.hs4j.FindOperator;
int result=session.update(keys, new String[] { "1", "dennis",
"test@163.com", "109" }, FindOperator.EQ);And also you can use ModifyStatement: stmt = this.session.createStatement(); stmt.setInt(1, 1); stmt.setString(2, "dennis"); stmt.setString(3, "test@163.com"); stmt.setInt(4, 109); int result=stmt.update(keys, FindOperator.EQ); Delete data int result= session.delete(new String[] { "dennis" },
FindOperator.EQ)More infoHS4J will heal a connection when it was disconnected by networking error or other exception,and when it was reconnected successfully then all opened-index will reopen on new connection. HS4J is a new client,and it maybe has some bugs that i don't know,please email me,thanks. |
Nice work!