My favorites | Sign in
Project Logo
                
People details
Project owners:
  martinelli.diego

jFluent is a little and simple library that provides a fluent layer over the java.util, java.lang and JDBC packages.

The library is in ALPHA stage, so if you want the very last version just check out the sources from the repository.

Now you can operate on lists and strings like that:

import static com.jfluent.builders.BuilderFacade.*;
import com.jfluent.base.*;

public class FluentSimpleTest {
  public static void main(String[] args) {
    string("o hai!")
      .append(" ")
      .append(
        list("i", "can", "has", "cheezburger", "plz", "?")
          .map(new Function<String, String>() {
            public String apply(String element) {
              return element + " ";
            }
          })
          .get())
      .append("\n")
      .append(
        list(range('A', 'Z'))
          .reverse()
          .filter(new Predicate<Character>() {
            public boolean apply(Character c) {
              return c > 'M';
            }
          })
          .join(","))
      .println(System.out);
  }
}

Output:

o hai! i can has cheezburger plz ? 
Z,Y,X,W,V,U,T,S,R,Q,P,O,N

Also, a fluent approach over jdbc is possible:

import static com.jfluent.builders.BuilderFacade.*;
import com.jfluent.db.base.Handle;
import java.util.List;

public final class DBFluentTest {
  public static void main(String[] args) throws Exception {
    Handle<List> empList = param();
    
    withConnection(JDBC_URI_HERE)
      .username("scott")
      .password("tiger")
      .loadOracleDriver()
      .doThis(
        procedure("package1.open_cur_emp")  // call this procedure
          .outRS(empList, EmpBean.class)    // put the resultset into a list of beans
          .in(nullObj(Integer.class)));     // passing a null integer as input
    
    for (Object o : empList.value()) {
      EmpBean e = (EmpBean)o;
      // do something with your list of entity beans
    }
  }
}

For more info on fluent interfaces and DSLs, the work in progress book by Martin Fowler is a good starting point. It can be found here: http://martinfowler.com/dslwip/

I'd like to hear opinions and suggestions for improvements! Contact me at martinelli.diego at gmail.com









Hosted by Google Code