Академический Документы
Профессиональный Документы
Культура Документы
Features
AcornDB provides an enterprise-class Java-based data management solution. You use
AcornDB through a series of Java APIs. All you need to get started is to add a single jar
file to your application’s classpath. AcornDB offers the following major features:
Database records.
All database records are organized as simple key/data pairs. Both keys and data can
be anything from primitive Java types to the most complex of Java objects.
Transactions.
Transactions allow you to treat one or more operations on one or more databases as a
single unit of work. AcornDB transactions offer the application developer
recoverability, atomicity, and isolation for your database operations.
Indexes.
AcornDB allows you to easily create and maintain additional indices for your data
through the use of databases. In this way, you can obtain rapid access to your data
through the use of an alternative key.
In-memory cache.
The cache allows for high speed database access for both read and writes operations
by avoiding unnecessary disk I/O. The cache will grow on demand up to a pre-
configured maximum size. To improve your application’s performance immediately
after startup time, you can preload your cache in order to avoid disk I/O for
production requests of your data.
-1–
Transaction Benefits
Atomicity
States that database modifications must follow an “all or nothing” rule. Each
transaction “atomic.” If one part of the transaction fails, the entire transaction fails. It
is critical that the database maintain the atomic nature of transactions.
Consistency
States that only valid data will be written to the database. If, for some reason, a
transaction is executed that violates the database’s consistency rules, the entire
transaction will be rolled back and the database will be restored to a state consistent
with those rules. On the other hand, if a transaction successfully executes, it will take
the database from one state that is consistent with the rules to another state that is also
consistent with the rules.
Isolation
Requires that multiple transactions occurring at the same time not impact each other’s
execution. For example, if user issues a transaction against a database at the same time
that other user issues different transactions, both transactions should operate on the
database in an isolated manner.
Durability
Ensures that any transaction committed to the database will not be lost. Durability is
ensured through the use of database backups and transaction logs that facilitate the
restoration of committed transactions in spite of any subsequent software or hardware
failures.
`
-2–
Or alternative usage is
After executing this commands in current directory user should find the directory
FirstTest which should holds two files FirstTest.dbx (is a data file)
and FirstTest.log (is physical log file).
Create tree
Now storage is opened and we can create the tree. The AcornDB provide several types of
persistent trees but we will start from ITxTree<K,V>. This type of transactional simple tree which
provide users multi-threading, multi-transactional access to persistent tree.
`
-3–
For example:
The AcornDB can store any object which implement Serializable interface, for
example Data object can looks like:
public Data()
{
}
public Data(int id, byte[] buffer)
{
this.id = id;
this.buffer = buffer;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public byte[] getBuffer()
{
return buffer;
}
public void setBuffer(byte[] buffer)
{
this.buffer = buffer;
}
public String toString()
{
return "[id = " + id + " ]";
}
}
`
-4–
Now we can store our Data objects in persistent store, to do this we should call for put () method
and for read should call get () method
Third parameter in put and second in get is transaction id and now it is null that means auto
commit transaction (each object will be saved on disk automatically). In case user want manage
the transaction it should create transaction for example
//create transaction
Transaction tnx = testTree.startTransaction();
// write object
testTree.put((Integer)data.getId(), data, null);
//close transaction
testTree.commit(tnx);
`
-5–
try
{
StoreDB db = StoreDB.getStore( "FirstTest", null );
ITxTree<Integer, Data> testTree = db.getTxTree(
Data.class.getName(),
true);
`
-6–
public Data()
{
}
public Data(int id, String name, String family, int age, byte[] data)
{
_id = id;
_name = name;
_family = family;
_age = age;
_data = data;
}
public byte[] getData() {return _data;}
public void setData(byte[] data) {_data = data;}
return buff.toString();
}
`
-7–
try
{
Properties props = new Properties();
StoreDB db = StoreDB.getStore("QueryByExample",props);
// Get ITable instance
ITable<Data> table = db.getTable(Data.class.getName(), true);
tnx = table.startTransaction();
String query = "_id <20 or _age = 30 order by _id desc";
result = table.getAll(null);
while(res.hasNext())
System.out.println("--> " +
result.remove(Transaction.NoTnx));
}
catch (Exception e)
{
e.printStackTrace();
}
`
-8–
Also ITable API provides several get methods that supply same SQL possibility, like build
static and dynamic SQL expressions.
In-memory cache
In case user decided use AcornDB as in-memory database he should change properties’
default values, for example
`
-9–
0. This License applies to any program or other work which contains a notice placed by the
copyright holder saying it may be distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based on the Program" means
either the Program or any derivative work under copyright law: that is to say, a work
containing the Program or a portion of it, either verbatim or with modifications and/or
translated into another language. (Hereinafter, translation is included without limitation in the
term "modification".) Each licensee is addressed as "you". Activities other than copying,
distribution and modification are not covered by this License; they are outside its scope. The act
of running the Program is not restricted, and the output from the Program is covered only if its
contents constitute a work based on the Program (independent of having been made by running the
Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it,
in any medium, provided that you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to
this License and to the absence of any warranty; and give any other recipients of the Program a
copy of this License along with the Program. You may charge a fee for the physical act of
transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
`
- 10 –
`
- 11 –
`
- 12 –