Skip to content

Commit

Permalink
Merge pull request #16 from FalkorDB/jdoc
Browse files Browse the repository at this point in the history
add more factories
  • Loading branch information
gkorland authored Dec 12, 2023
2 parents b145207 + 1e23c56 commit 88bb7d6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/falkordb/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
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
*/
GraphContextGenerator graph(String graphId);

/**
* Returns a underline connection to the database
*
* @return a underline connection to the database
*/
Jedis getConnection();
Expand Down
36 changes: 32 additions & 4 deletions src/main/java/com/falkordb/FalkorDB.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,57 @@
package com.falkordb;

import java.net.URI;

import com.falkordb.impl.api.DriverImpl;

/**
* FalkorDB driver factory
*/
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);
}
}
30 changes: 23 additions & 7 deletions src/main/java/com/falkordb/impl/api/DriverImpl.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,20 +11,34 @@ public class DriverImpl implements com.falkordb.Driver {
private final Pool<Jedis> 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
Expand Down

0 comments on commit 88bb7d6

Please sign in to comment.