uris = resource.getURIs();
...repeat for-loop as with DogmaConnections
In order to make permanent changes to the database, it must be committed or closed (and reopened for use).
Otherwise changes won't show on queries. These operations are implemented as methods in the ResourceBase
class.
The ResourceBase is implemented as a singleton. There can only be one ResourceBase in use.
- Author:
- bjorkgre
Method Summary |
void |
addConnection(iConnection connection)
adds a connection to the database. |
void |
addLastView(java.util.Vector<DogmaResource> vector)
Adds "LAST_VIEW" - tags to each resource in resultvector. |
void |
addResource(iResource resource)
addResource adds a new Resource into the Database. |
void |
addResourceVector(java.util.Vector<DogmaResource> resourceVector)
Adds the contents of a resourcevector to the resourcebase. |
void |
addTag(DogmaResource r)
addTag adds all new tags found in the given resource to the database. |
void |
addTag(java.util.Vector<DogmaResource> vector,
java.lang.String tag)
Adds a given tag to the vector of resources. |
void |
addURI(iURI uri)
|
void |
cleanLastView()
Removes "LAST_VIEW" - tags |
void |
close()
Closes the database connection. |
void |
commit()
Commits the current database, making changes permanent. |
boolean |
containsConnection(iConnection connection)
containsConnections checks if the connection given exists and if so, returns true. |
boolean |
containsResource(iResource resource)
containsResource checks if the resource given exists in the database and if so, returns true, otherwise
returns false. |
boolean |
containsURI(iURI uri)
containsURI checks if the URI given exists and if so, returns true. |
void |
doCleanUp()
Removes resources with canoname null or canoname as empty string |
void |
finalize()
|
int |
fromConnections(iResource r)
Returns the number of connections that start from given resource. |
java.util.Vector |
getByTag(java.lang.String tag)
Returns resources that have the tag |
java.util.Vector |
getConnections(int from,
boolean to)
|
java.util.Vector |
getConnections(iResource search)
|
static ResourceBase |
getInstance()
getInstance returns the ResourceBase instance. |
java.util.Vector<DogmaResource> |
getLastView()
Gets the resources with the tag "LAST_VIEW" -- a faster implementation |
DogmaResource |
getResource(java.lang.String canoname)
|
DogmaResource |
getResourceForGuess(java.lang.String canoname)
Returns a DogmaResource for quess. |
java.util.Vector<DogmaResource> |
getResourceForGuess(java.lang.String[] canonames)
Returns a Vector of Dogmaresources for quess. |
java.util.Stack<java.lang.Integer> |
getResourceIds(java.util.Vector<DogmaResource> vector)
Returns the id's of the resources in the resourcevector. |
java.util.Vector |
getResources(iResource search)
|
java.util.Vector<DogmaResource> |
getResources(java.util.Stack<java.lang.Integer> resourceIds)
Gets the resources and all their data to the given id's |
java.util.Vector<DogmaResource> |
getResources(java.util.Stack<java.lang.Integer> resourceIds,
boolean returnConnections,
boolean returnUris,
boolean returnTags)
Gets the resources and the needed data to the given id's. |
int |
getTagId(java.lang.String tag)
Gets the id of a tag in resourceBase. |
java.util.Vector |
getURIs(iResource search)
|
java.util.Vector |
getURIs(iURI search)
|
java.util.Stack<java.lang.Integer> |
idQuery(java.lang.String query)
Runs any query that asks for "id" and parses the id's to the stack. |
java.util.Stack<java.lang.Integer> |
idQueryByTags(java.lang.String[] tags)
Returns the resource id's for resources that are matching the
tags |
void |
open()
Reopens the database connection. |
void |
setDebuggingLevel(boolean debug)
Sets the ResourceBase debugging level. |
java.lang.String |
simpleQuery(java.lang.String query)
Runs a simple INSERT, UPDATE or DELETE query in the database. |
java.util.Vector |
sqlQuery(java.lang.String query)
sqlQuery performs an SQL query given as a String parameter and returns the results as a Vector of
resources, connections or URIs. |
int |
toConnections(iResource r)
Returns the number of connections that end to given resource. |
int |
totalConnections(iResource r)
Returns the number of connections that end to given resource. |
void |
updateConnectionCount()
updateConnectionCount checks up all references and updates the fields connectionto,
connectionfrom and connectiontotal in each resource in the database. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
getInstance
public static ResourceBase getInstance()
- getInstance returns the ResourceBase instance.
- Returns:
setDebuggingLevel
public void setDebuggingLevel(boolean debug)
- Sets the ResourceBase debugging level.
- Parameters:
debug
-
commit
public void commit()
- Commits the current database, making changes permanent. This is mainly meant for web or server
databases, it does not work on files.
close
public void close()
- Closes the database connection. This method is the only way to ensure that the information will persist
in the database file.
open
public void open()
- Reopens the database connection. To open a completely new database, a new ResourceBase object is needed.
fromConnections
public int fromConnections(iResource r)
- Returns the number of connections that start from given resource.
- Parameters:
resource
-
- Returns:
toConnections
public int toConnections(iResource r)
- Returns the number of connections that end to given resource.
- Parameters:
resource
-
- Returns:
totalConnections
public int totalConnections(iResource r)
- Returns the number of connections that end to given resource.
- Parameters:
r
-
- Returns:
updateConnectionCount
public void updateConnectionCount()
- updateConnectionCount checks up all references and updates the fields connectionto,
connectionfrom and connectiontotal in each resource in the database.
containsResource
public boolean containsResource(iResource resource)
- containsResource checks if the resource given exists in the database and if so, returns true, otherwise
returns false.
- Parameters:
resource
-
- Returns:
containsConnection
public boolean containsConnection(iConnection connection)
- containsConnections checks if the connection given exists and if so, returns true. Otherwise,
returns false.
- Parameters:
connection
-
- Returns:
containsURI
public boolean containsURI(iURI uri)
- containsURI checks if the URI given exists and if so, returns true. Otherwise,
returns false.
- Parameters:
uri
-
- Returns:
addResource
public void addResource(iResource resource)
- addResource adds a new Resource into the Database. If the resource however already exists,
it is updated.
- Parameters:
resource
- the resource to be added into the database.
addTag
public void addTag(DogmaResource r)
- addTag adds all new tags found in the given resource to the database. It also adds the resource id
to the tagtores reference table, which makes it possible to fetch the resource in question from
the database.
- Parameters:
r
-
addConnection
public void addConnection(iConnection connection)
- adds a connection to the database. Take note that adding a resource to the database does not add
any of the resource's connections or URI so they will have to be added separately. As with resources,
if the connection exists, will commit.
- Parameters:
connection
-
addURI
public void addURI(iURI uri)
- Parameters:
uri
-
getResources
public java.util.Vector getResources(iResource search)
- Parameters:
search
-
- Returns:
getByTag
public java.util.Vector getByTag(java.lang.String tag)
- Returns resources that have the tag
- Parameters:
tag
-
- Returns:
getResource
public DogmaResource getResource(java.lang.String canoname)
- Parameters:
canoname
-
- Returns:
getConnections
public java.util.Vector getConnections(iResource search)
- Parameters:
search
-
- Returns:
getConnections
public java.util.Vector getConnections(int from,
boolean to)
- Parameters:
from
- to
-
- Returns:
getURIs
public java.util.Vector getURIs(iURI search)
- Parameters:
search
-
- Returns:
getURIs
public java.util.Vector getURIs(iResource search)
- Parameters:
search
-
- Returns:
sqlQuery
public java.util.Vector sqlQuery(java.lang.String query)
- sqlQuery performs an SQL query given as a String parameter and returns the results as a Vector of
resources, connections or URIs. The result given by the query is sent to a ResourceFactory object
and from which all resources, connection or URIs associated with the search.
- Parameters:
query
-
- Returns:
addResourceVector
public void addResourceVector(java.util.Vector<DogmaResource> resourceVector)
- Adds the contents of a resourcevector to the resourcebase.
- Parameters:
resourceVector
-
simpleQuery
public java.lang.String simpleQuery(java.lang.String query)
- Runs a simple INSERT, UPDATE or DELETE query in the database.
- Parameters:
query
-
- Returns:
getResources
public java.util.Vector<DogmaResource> getResources(java.util.Stack<java.lang.Integer> resourceIds)
- Gets the resources and all their data to the given id's
getResources
public java.util.Vector<DogmaResource> getResources(java.util.Stack<java.lang.Integer> resourceIds,
boolean returnConnections,
boolean returnUris,
boolean returnTags)
- Gets the resources and the needed data to the given id's.
if returnConnections is false, no connections are added
if returnUris is false, no uris are added
if returnTags is false, no tags are added
getLastView
public java.util.Vector<DogmaResource> getLastView()
- Gets the resources with the tag "LAST_VIEW" -- a faster implementation
getResourceIds
public java.util.Stack<java.lang.Integer> getResourceIds(java.util.Vector<DogmaResource> vector)
- Returns the id's of the resources in the resourcevector.
The query is made based on the canonames of the resources.
- Parameters:
vector
-
- Returns:
addLastView
public void addLastView(java.util.Vector<DogmaResource> vector)
- Adds "LAST_VIEW" - tags to each resource in resultvector.
addTag
public void addTag(java.util.Vector<DogmaResource> vector,
java.lang.String tag)
- Adds a given tag to the vector of resources.
- Parameters:
vector
-
getResourceForGuess
public DogmaResource getResourceForGuess(java.lang.String canoname)
- Returns a DogmaResource for quess. (Without uris and tags).
- Parameters:
canoname
-
- Returns:
getResourceForGuess
public java.util.Vector<DogmaResource> getResourceForGuess(java.lang.String[] canonames)
- Returns a Vector of Dogmaresources for quess. (Without uris and tags).
- Parameters:
canoname
-
- Returns:
idQuery
public java.util.Stack<java.lang.Integer> idQuery(java.lang.String query)
- Runs any query that asks for "id" and parses the id's to the stack.
- Parameters:
query
-
- Returns:
idQueryByTags
public java.util.Stack<java.lang.Integer> idQueryByTags(java.lang.String[] tags)
- Returns the resource id's for resources that are matching the
tags
getTagId
public int getTagId(java.lang.String tag)
- Gets the id of a tag in resourceBase. If the tag isn't in resourcebase, it is
added and the id of the added tag is returned.
- Parameters:
tag
- - the tag we are searching
- Returns:
- returns the id of the tag,
returns -1 if the given tag is null or the length of the tag is 0.
cleanLastView
public void cleanLastView()
- Removes "LAST_VIEW" - tags
doCleanUp
public void doCleanUp()
- Removes resources with canoname null or canoname as empty string
finalize
public void finalize()
- Overrides:
finalize
in class java.lang.Object