diff --git a/src/main/java/com/falkordb/Driver.java b/src/main/java/com/falkordb/Driver.java index 8f94c61..90bf55e 100644 --- a/src/main/java/com/falkordb/Driver.java +++ b/src/main/java/com/falkordb/Driver.java @@ -3,13 +3,15 @@ import java.io.Closeable; import redis.clients.jedis.Jedis; + /** * An interface which aligned to FalkorDB Driver interface */ -public interface Driver extends Closeable{ +public interface Driver extends Closeable { /** * Returns a selected Graph + * * @param graphId Graph name * @return a selected Graph */ @@ -17,6 +19,7 @@ public interface Driver extends Closeable{ /** * Returns a underline connection to the database + * * @return a underline connection to the database */ Jedis getConnection(); diff --git a/src/main/java/com/falkordb/FalkorDB.java b/src/main/java/com/falkordb/FalkorDB.java index 5cd1dc5..eab1914 100644 --- a/src/main/java/com/falkordb/FalkorDB.java +++ b/src/main/java/com/falkordb/FalkorDB.java @@ -1,5 +1,7 @@ package com.falkordb; +import java.net.URI; + import com.falkordb.impl.api.DriverImpl; /** @@ -7,23 +9,49 @@ */ final public class FalkorDB { - private FalkorDB() {} + private FalkorDB() { + } /** * Creates a new driver instance + * * @return a new driver instance */ - public static Driver driver (){ - return new DriverImpl(); + public static Driver driver() { + return driver("localhost", 6379); } /** * Creates a new driver instance + * * @param host host name * @param port port number * @return a new driver instance */ - public static Driver driver (String host, int port){ + public static Driver driver(String host, int port) { return new DriverImpl(host, port); } + + /** + * Creates a new driver instance + * + * @param host host name + * @param port port number + * @param user username + * @param password password + * @return a new driver instance + */ + public static Driver driver(String host, int port, String user, final String password) { + return new DriverImpl(host, port, user, password); + } + + /** + * Creates a new driver instance + * + * @param uri server uri + * @return a new driver instance + */ + public static Driver driver(URI uri) { + return new DriverImpl(uri); + } } diff --git a/src/main/java/com/falkordb/impl/api/DriverImpl.java b/src/main/java/com/falkordb/impl/api/DriverImpl.java index 70c60c7..ffaca9e 100644 --- a/src/main/java/com/falkordb/impl/api/DriverImpl.java +++ b/src/main/java/com/falkordb/impl/api/DriverImpl.java @@ -1,5 +1,7 @@ package com.falkordb.impl.api; +import java.net.URI; + import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.util.Pool; @@ -9,20 +11,34 @@ public class DriverImpl implements com.falkordb.Driver { private final Pool pool; /** - * Creates a client running on the local machine + * Creates a client running on the specific host/post + * + * @param host Server host + * @param port Server port */ - public DriverImpl() { - this("localhost", 6379); + public DriverImpl(String host, int port) { + this.pool = new JedisPool(host, port); } /** * Creates a client running on the specific host/post * - * @param host Redis host - * @param port Redis port + * @param host Server host + * @param port Server port + * @param user username + * @param password password */ - public DriverImpl(String host, int port) { - this.pool = new JedisPool(host, port); + public DriverImpl(String host, int port, String user, final String password) { + this.pool = new JedisPool(host, port, user, password); + } + + /** + * Creates a client using the specific uri + * + * @param uri server uri + */ + public DriverImpl(URI uri) { + this.pool = new JedisPool(uri); } @Override