Skip to content

Instantly share code, notes, and snippets.

@aweiland
Created April 1, 2016 13:04
Show Gist options
  • Save aweiland/a5ad1472ed79e3514a11ce87e3844b79 to your computer and use it in GitHub Desktop.
Save aweiland/a5ad1472ed79e3514a11ce87e3844b79 to your computer and use it in GitHub Desktop.
import com.rethinkdb.RethinkDB;
import com.rethinkdb.net.Connection;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import java.util.concurrent.TimeoutException;
public class RethinkDBFactoryBean extends AbstractFactoryBean<Connection> {
private final Connection conn;
private static final RethinkDB r = RethinkDB.r;
public RethinkDBFactoryBean(String host, Integer port) throws TimeoutException {
conn = r.connection().hostname(host).port(port).connect();
}
public RethinkDBFactoryBean(String host, String port) throws TimeoutException {
this(host, Integer.valueOf(port));
}
@Override
public Class<?> getObjectType() {
return Connection.class;
}
@Override
protected Connection createInstance() throws Exception {
return conn;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment