ch.hsr.bieridee.utils
Class DBUtil

java.lang.Object
  extended by ch.hsr.bieridee.utils.DBUtil

public final class DBUtil
extends java.lang.Object

Utility to work with the neo4J graph-db.


Method Summary
static void addToRatingIndex(org.neo4j.graphdb.Node node, BeerModel beerModel, UserModel userModel)
           
static void addToTimeLine(org.neo4j.graphdb.Node node)
          Adds a new Action to the Timeline.
static org.neo4j.graphdb.Node createNode(java.lang.String type)
           
static org.neo4j.graphdb.Relationship createRelationship(org.neo4j.graphdb.Node startNode, org.neo4j.graphdb.RelationshipType relType, org.neo4j.graphdb.Node endNode)
          Creates a bidirectional relationship between the given Nodes.
static void deleteRelationship(org.neo4j.graphdb.Node startNode, RelType hasBeertype, org.neo4j.graphdb.Node endNode, org.neo4j.graphdb.Direction direction)
           
static boolean doesUserExist(java.lang.String username)
          Checks whether a usernode is existing or not.
static org.neo4j.graphdb.Node getActiveUserRatingForBeer(long beerId, java.lang.String username)
           
static java.util.List<java.lang.String> getAllBrands()
           
static org.neo4j.graphdb.Node getBeerByBarcode(java.lang.String barcode)
          Gets a neo4j beer node by the barcode.
static org.neo4j.graphdb.Node getBeerByName(java.lang.String name)
          Gets a neo4j beer node by the name of the beer.
static java.util.List<org.neo4j.graphdb.Node> getBeerNodeList()
          Gets a list of all beer nodes from the database.
static java.util.List<org.neo4j.graphdb.Node> getBeerNodeList(int items, int skip)
           
static java.util.List<org.neo4j.graphdb.Node> getBeerNodeList(long tagId)
          Gets a list of all tags with the given tag.
static java.util.List<org.neo4j.graphdb.Node> getBeerNodeList(long tagId, int items, int skip)
           
static java.util.List<org.neo4j.graphdb.Node> getBeersRatedByUser(java.lang.String username)
           
static java.util.List<org.neo4j.graphdb.Node> getBeertypeNodeList()
          Gets a list of all beertype nodes from the database.
static java.util.List<org.neo4j.graphdb.Node> getBreweryNodeList()
          Gets a list of all brewery nodes from the database.
static java.util.List<org.neo4j.graphdb.Node> getBreweryNodeList(int items, int skip)
           
static java.util.List<org.neo4j.graphdb.Node> getBreweryNodeList(java.lang.String brewerySize)
          Gets a list of all brewery nodes filtered by size.
static java.util.List<org.neo4j.graphdb.Node> getBreweryNodeList(java.lang.String brewerySize, int items, int skip)
           
static java.util.List<org.neo4j.graphdb.Node> getConsumptionsByBeer(long beerId)
          Gets a list of all consuptions nodes for the given beer.
static java.util.List<org.neo4j.graphdb.Node> getConsumptionsForUserByBeer(java.lang.String username, long beerId)
          Gets a list of consumption nodes for the user and the beer.
static org.neo4j.graphdb.Node getNodeByBarcode(java.lang.String code)
          Gets a beer node by barcode.
static org.neo4j.graphdb.Node getNodeById(long id)
          Gets the neo4j node by the absolute node id.
static org.neo4j.graphdb.Node getOrCreateBarcodeNode(java.lang.String code)
          Get or create a barcode.
static org.neo4j.graphdb.Node getOrCreateBarcodeNode(java.lang.String code, java.lang.String format)
          Get or create a barcode.
static org.neo4j.graphdb.Node getTagByName(java.lang.String name)
          Gets a neo4j tag node by the name of the tag.
static java.util.List<org.neo4j.graphdb.Node> getTagNodeList()
           
static java.util.List<org.neo4j.graphdb.Node> getTimeLine(int maxNumberOfItems, int skipCount)
           
static java.util.List<org.neo4j.graphdb.Node> getTimeLineForUser(java.lang.String username, int maxNumberOfItems, int skipCount)
           
static org.neo4j.graphdb.Node getUnknownNode(java.lang.String type)
          Gets the "Unknown-Node" for a specific type.
static org.neo4j.graphdb.Node getUserByName(java.lang.String name)
          Gets a neo4j node by the username of the user.
static java.util.List<org.neo4j.graphdb.Node> getUserNodeList()
          Gets a list of all user nodes from the database.
static void setDB(org.neo4j.kernel.EmbeddedGraphDatabase db)
           
static void setProperty(org.neo4j.graphdb.Node node, java.lang.String key, java.lang.Object value)
          Adds or updates the given property with the given value on the given node.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setDB

public static void setDB(org.neo4j.kernel.EmbeddedGraphDatabase db)

getNodeById

public static org.neo4j.graphdb.Node getNodeById(long id)
Gets the neo4j node by the absolute node id.

Parameters:
id - The id of the neo4j node
Returns:
The node with the given id

getBeerNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBeerNodeList()
Gets a list of all beer nodes from the database.

Returns:
List all existing beernodes.

getBeerNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBeerNodeList(int items,
                                                                     int skip)

getBeerNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBeerNodeList(long tagId)
Gets a list of all tags with the given tag.

Parameters:
tagId - Id of a Tag which is used as a filter.
Returns:
a List of Beers matching the given Tag name.

getBeerNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBeerNodeList(long tagId,
                                                                     int items,
                                                                     int skip)

getBeertypeNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBeertypeNodeList()
Gets a list of all beertype nodes from the database.

Returns:
List of all existing beertype nodes.

getBreweryNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBreweryNodeList()
Gets a list of all brewery nodes from the database.

Returns:
List of all existing brewery nodes.

getBreweryNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBreweryNodeList(int items,
                                                                        int skip)

getBreweryNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBreweryNodeList(java.lang.String brewerySize)
Gets a list of all brewery nodes filtered by size.

Parameters:
brewerySize - Brewery size which is used as a filter.
Returns:
a List of Beers matching the given Tag name

getBreweryNodeList

public static java.util.List<org.neo4j.graphdb.Node> getBreweryNodeList(java.lang.String brewerySize,
                                                                        int items,
                                                                        int skip)

getUserNodeList

public static java.util.List<org.neo4j.graphdb.Node> getUserNodeList()
Gets a list of all user nodes from the database.

Returns:
List of all existing user nodes.

getTagNodeList

public static java.util.List<org.neo4j.graphdb.Node> getTagNodeList()

getBeerByName

public static org.neo4j.graphdb.Node getBeerByName(java.lang.String name)
Gets a neo4j beer node by the name of the beer.

Parameters:
name - The name (name property) of the beer
Returns:
The beer with the given name or null if not found

getBeerByBarcode

public static org.neo4j.graphdb.Node getBeerByBarcode(java.lang.String barcode)
Gets a neo4j beer node by the barcode.

Parameters:
barcode - A barcode of the beer
Returns:
The beer associated with the given barcode or null if not found

getTagByName

public static org.neo4j.graphdb.Node getTagByName(java.lang.String name)
Gets a neo4j tag node by the name of the tag.

Parameters:
name - The name (name property) of the tag
Returns:
The tag with the given name or null if not found

getUserByName

public static org.neo4j.graphdb.Node getUserByName(java.lang.String name)
Gets a neo4j node by the username of the user.

Parameters:
name - Username
Returns:
The node

createRelationship

public static org.neo4j.graphdb.Relationship createRelationship(org.neo4j.graphdb.Node startNode,
                                                                org.neo4j.graphdb.RelationshipType relType,
                                                                org.neo4j.graphdb.Node endNode)
Creates a bidirectional relationship between the given Nodes.

Parameters:
startNode - Start Node of the Relationship.
relType - Type of the Relation to be created.
endNode - End Node of the Relationship.
Returns:
The newly created Relationship

createNode

public static org.neo4j.graphdb.Node createNode(java.lang.String type)
Parameters:
type - String with type
Returns:
created Node in the Database

setProperty

public static void setProperty(org.neo4j.graphdb.Node node,
                               java.lang.String key,
                               java.lang.Object value)
Adds or updates the given property with the given value on the given node.

Parameters:
node - Node on which the property is set.
key - Key of the Property
value - Value of the Property,

doesUserExist

public static boolean doesUserExist(java.lang.String username)
Checks whether a usernode is existing or not.

Parameters:
username - Username of the user to be checked
Returns:
True if the user node exists, false otherwise

getTimeLineForUser

public static java.util.List<org.neo4j.graphdb.Node> getTimeLineForUser(java.lang.String username,
                                                                        int maxNumberOfItems,
                                                                        int skipCount)
Parameters:
username - Username used to filter the timeline.
maxNumberOfItems - number of max. Items (actions) returned. Pass 0 for all Items.
skipCount - Number of elements to be skipped for paging.
Returns:
Chronological list of actions filtered by Username.

getTimeLine

public static java.util.List<org.neo4j.graphdb.Node> getTimeLine(int maxNumberOfItems,
                                                                 int skipCount)
Parameters:
maxNumberOfItems - number of max. Items (actions) returned. Pass 0 for all Items.
skipCount - Number of Elements to be skipped for paging.
Returns:
Chronological list of all actions (Ratings and Consumptions).

addToTimeLine

public static void addToTimeLine(org.neo4j.graphdb.Node node)
Adds a new Action to the Timeline.

Parameters:
node - the action node to be added.

getActiveUserRatingForBeer

public static org.neo4j.graphdb.Node getActiveUserRatingForBeer(long beerId,
                                                                java.lang.String username)
Parameters:
beerId - ID of the beer.
username - Username of the user.
Returns:
The most recent rating for the given beer of the given user.

addToRatingIndex

public static void addToRatingIndex(org.neo4j.graphdb.Node node,
                                    BeerModel beerModel,
                                    UserModel userModel)
Parameters:
node - Rating node.
beerModel - BeerModel rated by the rating
userModel - UserModel that rates the beer.

getConsumptionsByBeer

public static java.util.List<org.neo4j.graphdb.Node> getConsumptionsByBeer(long beerId)
Gets a list of all consuptions nodes for the given beer.

Parameters:
beerId - The id of the beer
Returns:
List of consumption nodes

getConsumptionsForUserByBeer

public static java.util.List<org.neo4j.graphdb.Node> getConsumptionsForUserByBeer(java.lang.String username,
                                                                                  long beerId)
Gets a list of consumption nodes for the user and the beer. The result is a list of all consumptions of a user for the given beer.

Parameters:
username - The user
beerId - The beer
Returns:
The node list

getBeersRatedByUser

public static java.util.List<org.neo4j.graphdb.Node> getBeersRatedByUser(java.lang.String username)
Parameters:
username - username of the user
Returns:
List containing the beer nodes the user rated

getAllBrands

public static java.util.List<java.lang.String> getAllBrands()

getUnknownNode

public static org.neo4j.graphdb.Node getUnknownNode(java.lang.String type)
Gets the "Unknown-Node" for a specific type.

Parameters:
type - Nodetype
Returns:
The "Unknown-Node"

getNodeByBarcode

public static org.neo4j.graphdb.Node getNodeByBarcode(java.lang.String code)
Gets a beer node by barcode.

Parameters:
code - The barcode
Returns:
The beer node

getOrCreateBarcodeNode

public static org.neo4j.graphdb.Node getOrCreateBarcodeNode(java.lang.String code)
Get or create a barcode.

Parameters:
code - The barcode
Returns:
Barcode node

getOrCreateBarcodeNode

public static org.neo4j.graphdb.Node getOrCreateBarcodeNode(java.lang.String code,
                                                            java.lang.String format)
Get or create a barcode.

Parameters:
code - The barcode value
format - The barcode format
Returns:
Barcode node

deleteRelationship

public static void deleteRelationship(org.neo4j.graphdb.Node startNode,
                                      RelType hasBeertype,
                                      org.neo4j.graphdb.Node endNode,
                                      org.neo4j.graphdb.Direction direction)
Parameters:
startNode - Start node
hasBeertype - Relationship type (edge)
endNode - end node
direction - Direction in which the node is connected to node2 via RelType. From the point of view of first node.