public class XMLDB extends Object
XMLDB
is the main database access class.
It allows you to create new database in given file, open database from
given file, add, delete and retrieve data and data lists. All data or data
lists are stored in database nodes. There are three possible kinds of nodes
for each database:
root
' is used.node
' is used.node
' element name and this
can't be changed.All node1 nodes and subnodes can contains any number of
data associated with keys. With some keys there ca be more than one value
assigned. Such kind of data are called data lists.
Although element name for subnode can not be defined it is actually not
important. Because user database doesn't use subnode element names. He doesn't
even use neiher root node element name nor node1 element
name. database user uses node name what is quite different
from node element name. Let see example below:
<node name='roster'/>
In this example node element name is node and
node name is roster.
database users (actually developers) use only node names.
If you want to access subnode on some level you need to give full path to
this subnode. For example, let's assume we have following database:
<node name='tigase'> <node name='server'> </node> <node name='xmpp'> </node> </node>
If you need to access 'server
' subnode you need to call method
with '/tigase/server
' as subnode path and for subnode
'xmpp
' proper subnode path is of course
'/tigase/xmpp
'. If you skip subnode path or give
null
as a parameter you will be accessing data on node1
level. You can not access or save data on root node level.
Created: Tue Oct 26 15:27:33 2004
Constructor and Description |
---|
XMLDB(String db_file)
Creates XMLDB object with desired filename, if file modes is enabled then
appropriate saver thread is created as well.
|
Modifier and Type | Method and Description |
---|---|
void |
addNode1(String node1_id)
Adds new node
|
static XMLDB |
createDB(String db_file,
String root_name,
String node1_name)
Factory method creating and setting up XMLDB
|
DBElement |
findNode1(String node1_id)
Return Element corresponding to the node name
|
List<String> |
getAllNode1s()
Retrieve list of nodes
|
long |
getAllNode1sCount()
Retrieve number of nodes
|
Object |
getData(String node1_id,
String key)
Retrieve value of given node
|
Object |
getData(String node1_id,
String subnode,
String key)
Retrieve value of given node under specific path
|
Object |
getData(String node1_id,
String subnode,
String key,
Object def)
Retrieve value of given node under specific path
|
double |
getDataDouble(String node1_id,
String subnode,
String key,
double def)
Retrieve value of given node under specific path
|
double[] |
getDataDoubleList(String node1_id,
String subnode,
String key)
Retrieve values of given node under specific path
|
int |
getDataInt(String node1_id,
String subnode,
String key,
int def)
Retrieve value of given node under specific path
|
int[] |
getDataIntList(String node1_id,
String subnode,
String key)
Retrieve values of given node under specific path
|
String[] |
getDataList(String node1_id,
String subnode,
String key)
Retrieve values of given node under specific path
|
String |
getDBFileName()
Retrieves filename
|
String[] |
getKeys(String node1_id)
Retrieve list of keys under root
|
String[] |
getKeys(String node1_id,
String subnode)
Retrieve list of keys under specific path
|
protected DBElement |
getNode(String node1_id,
String subnode,
boolean auto_create)
Retrieves the node of the given name at specific path
|
protected DBElement |
getNode1(String node1_id) |
String[] |
getSubnodes(String node1_id)
Retrieve list of subnodes under root
|
String[] |
getSubnodes(String node1_id,
String subnode)
Retrieve list of subnodes under specific path
|
protected void |
loadDB()
Loads XML from file
|
void |
removeData(String node1_id,
String key)
Removes data of specific key from node of given name under root element
|
void |
removeData(String node1_id,
String subnode,
String key)
Removes data of specific key from node of given name under given path
|
void |
removeNode1(String node1_id)
Removes the node
|
void |
removeSubnode(String node1_id,
String subnode)
Removes node of given name under given path
|
protected void |
saveDB()
Saves XML to file
|
void |
setData(String node1_id,
String key,
Object value)
Sets data for the given node at root
|
void |
setData(String node1_id,
String subnode,
String key,
Object value)
Sets data for the given node at given path
|
protected void |
setupNewDB(String db_file,
String root_name,
String node1_name)
Creates basic Elements of the XMLDB
|
void |
sync()
Performs synchronization with the file
|
String |
toString() |
public XMLDB(String db_file) throws IOException, XMLDBException
db_file
- indicates path to the file on disk to/from which write/read;
if parameter starts with "memory://" then memory mode
(without actual file usage) is enabledIOException
XMLDBException
public static XMLDB createDB(String db_file, String root_name, String node1_name)
db_file
- indicates path to the file on disk to/from which write/read;
if parameter starts with "memory://" then memory mode
(without actual file usage) is enabledroot_name
- name of the root elementnode1_name
- name of the nodepublic String getDBFileName()
protected void setupNewDB(String db_file, String root_name, String node1_name)
db_file
- indicates path to the file on disk to/from which write/read;
if parameter starts with "memory://" then memory mode
(without actual file usage) is enabledroot_name
- name of the root elementnode1_name
- name of the nodeprotected void loadDB() throws IOException, XMLDBException
IOException
XMLDBException
protected void saveDB()
public final long getAllNode1sCount()
public final DBElement findNode1(String node1_id)
node1_id
- node nameprotected final DBElement getNode1(String node1_id) throws NodeNotFoundException
node1_id
- NodeNotFoundException
public void addNode1(String node1_id) throws NodeExistsException
node1_id
- name of the node to addNodeExistsException
public void removeNode1(String node1_id) throws NodeNotFoundException
node1_id
- name of the node to removeNodeNotFoundException
protected final DBElement getNode(String node1_id, String subnode, boolean auto_create) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodeauto_create
- whether to create path if it's missingNodeNotFoundException
public void setData(String node1_id, String subnode, String key, Object value) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- under which save the datavalue
- actual value to be savedNodeNotFoundException
public void setData(String node1_id, String key, Object value) throws NodeNotFoundException
node1_id
- name of the nodekey
- under which save the datavalue
- actual value to be savedNodeNotFoundException
public String[] getDataList(String node1_id, String subnode, String key) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- under which read the dataNodeNotFoundException
public int[] getDataIntList(String node1_id, String subnode, String key) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- under which read the dataNodeNotFoundException
public double[] getDataDoubleList(String node1_id, String subnode, String key) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- under which read the dataNodeNotFoundException
public Object getData(String node1_id, String subnode, String key, Object def) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- under which read the datadef
- default value if nothing is storedNodeNotFoundException
public int getDataInt(String node1_id, String subnode, String key, int def) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- under which read the datadef
- default value if nothing is storedNodeNotFoundException
public double getDataDouble(String node1_id, String subnode, String key, double def) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- under which read the datadef
- default value if nothing is storedNodeNotFoundException
public Object getData(String node1_id, String subnode, String key) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- under which read the dataNodeNotFoundException
public Object getData(String node1_id, String key) throws NodeNotFoundException
node1_id
- name of the nodekey
- under which read the dataNodeNotFoundException
public String[] getSubnodes(String node1_id, String subnode) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodeNodeNotFoundException
public String[] getSubnodes(String node1_id) throws NodeNotFoundException
node1_id
- name of the nodeNodeNotFoundException
public String[] getKeys(String node1_id, String subnode) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodeNodeNotFoundException
public String[] getKeys(String node1_id) throws NodeNotFoundException
node1_id
- name of the nodeNodeNotFoundException
public void removeData(String node1_id, String subnode, String key) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodekey
- name of the keyNodeNotFoundException
public void removeData(String node1_id, String key) throws NodeNotFoundException
node1_id
- name of the nodekey
- name of the keyNodeNotFoundException
public void removeSubnode(String node1_id, String subnode) throws NodeNotFoundException
node1_id
- name of the nodesubnode
- path to the nodeNodeNotFoundException
public void sync() throws IOException
IOException
Copyright © 2018 "Tigase, Inc.". All rights reserved.