Steal this link!SourceForge.net Logo

WARNING: If you downloaded: moleculej_1.zip
please visit sourceForge.net & download: moleculej_FirstRelease_R1.zip
The moleculej_1.zip was kind of a pre-release. 
Yes I blew it; when you release a project on sourceForge.net they promote it on the main home page.
Everyone who downloaded moleculej_1.zip got a bunch of crap that didn't work; yes a nightmare!

LINKS


The download includes the code, built classes, JavaDoc, a netBeans 5.x GUI Example project and more.

You are at: www.datavirtue.com

If you are a Java programmer and would like to take part in moleculeJ enhancement please contact software@datavirtue.com.

Changes      Development Plans        Highlights        Examples        Limitations


Introduction

Story

moleculeJ is a super-small sub-relational database engine for Java developers.  DbEngine.java has built-in helper methods to return a sorted (TableSorter.java) or non-sorted TableModel for use in JTables.    You don't have to jump through SQL hoops to develop a small to medium scale desktop application.  If you need network data capabilities you should use Derby or Cloudscape 10.

...or RMI?

This database engine was used to develop a significant business application before I released it on Source Forge.

Below you will find code snippets from the netBeans 5.x GUI Example project included with the release download.

MPL 1.1 - You are free to modify and include this in any of your projects under the MPL 1.1 license.
MPL 1.1-PC.txt
    MPL 1.1-UNI.txt
 

Suggestions are welcome.

Post Questions Here: http://sourceforge.net/forum/?group_id=183825

THE OR THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 

Development Plans
 

Advanced text file (.CSV) processing engine (java.util.regex).

Optimize private methods for speed and flexibility (regex).

Develop a way to generate or "compile" .sch files so they can be created dynamically. (regex)

Standard XML output or XML schema/translation mechanism for relations between tables. (?)(regex?)

...?????

 


moleculeJ is developed sporadically in line with my other projects.  New features are added or amended when needed; mostly on the fly. 

Enjoy.

 

Highlights
 

Only two small classes needed for a raw data engine.

Easy to change in the midst of a project, adding features or revising private methods for speed.

Simple to-the-point methods prevent any learning curve.

Developed and tested to handle over 40000 records per table, four times more than Microsoft Access 2000. (fairly quick :)

Schemas (tables/files) and "Data Systems" (Databases) are created with simple text files.

It is possible to dynamically load and unload schemas and or chain DbEngine instances.

Schema and Data System design possibilities are endless, great for experimental data scenarios on the desktop.

Good to test or experiment with threads and RMI.

You can wrap the DbEngine with a command parser (regex) class to handle just the SQL you need for a project.

Easy to create complex small business applications for the desktop.

Sub-Relational Design: Relations are established in the business logic code and or objects.

Good way to teach OOP and Java fundamentals to new students.  (It gives them something interesting to work on instead of text book exercises.)

No need to change old data when adding features, simply create a new table, add interface components, insert CRUD of new table into business logic using a key from the "parent" table as a reference.  Leave your user's old data alone and avoid messy conversions.

Fun to play with and test.

 

 Files needed to construct a Data System

.dsf file and any number of .sch files called by the .dsf


DbEngine db = new DbEngine ("main.dsf");

[main.dsf]
1 <---------------------- how many schemas to load
data/invoice.sch <----------------- The schema (relative path)
 


See Code Examples below for alternate usage with just .sch file


[invoice.sch]                                  (table)
invoice <---------------------- name of the .db data file
data/ <--------------- The path of the .db file
11 <-------------How many fields will be loaded
INUMBER
TXT
8
DATE
TXT
10
CUSTOMER <--------- Field name
TXT <-----------Field Type
200 <----------------------------field size (if applicable)
SHIPPING
NUM
0
MESSAGE
TXT
160
TAX_1
NUM
0
TAX_2
NUM
0
PAID
YESNO
1
VOID
YESNO
1
GRAND
NUM
0
CUSTKEY
INT
0
----------------
 

 

Code Snips from GUI Example
 

private DbEngine db = new DbEngine (); //construct a data engine
private Object [] dataOut = new Object [4]; //create an Object array to hold a record

 


    

db.loadSchema("zip.sch"); //Provide access to one data file(table).
                          //You can call this as many times as you like.
                          //Hopefully with a different file each time!

db.csvImport("zip", new java.io.File ("zipcodes.csv"));//Hope they match
 


private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {

db.close(); // Clean up; tell the DbEngine your done.
          
System.exit(0);

}




private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {

if ((Integer) dataOut[0] == 0) return; //sorry

//dataOut[0] is already set when a record is retreived
dataOut[1] = new String (zipfield.getText());
dataOut[2] = new String (cityField.getText());
dataOut[3] = new String (stateField.getText());

db.saveRecord("zip", dataOut, false);
//            table, Object[], bool unique
                                          //unique is not implemented

}
 



private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {

if (zipfield.getText().length() < 5) return; //sorry

ArrayList al = new ArrayList ();

//search for all occurances of text in zipfield
al = db.search("zip", 1, zipfield.getText(), false);
   //                col     search string    substring(yes/no)

//al now contains a list of keys (Integer) to the records in the db matching the search.
 

// Or it is null?

if (al != null){

//get the first record found
dataOut = db.getRecord("zip", (Integer) al.get(0));

cityField.setText((String)dataOut[2]);
stateField.setText((String) dataOut[3]);



}else {// no search results


}
 

Limitations

No special fields yet.  No image fields, no auto-increment (except key) fields. Only stores Java Integer, Float, Boolean and String data.

If you change a field's properties in the .sch file all the data becomes inaccessible; delete the corresponding .db file and let the system start a new one.  You must practice good database design!

Error handling prevents any type of data corruption but leaves much to be desired.

Path addressing scheme needs revised (not easy or it would be done by now) for more flexibility.

csvEx/Import() methods could be improved for better performance.

No join methods or other such complications; presentation by logic is handled through the application where everyone can see what is going on.

 

 

moleculeJ stores data, that is it.  Data accessed through your basic CRUD methods with a Java flavor and additional helper methods.  The "sub-relational" aspect is the ability to relate the tables through code as all methods are designed for this type of use.
 

 

Story
 

Several years ago I was studying Java; actually I became obsessed.  Anyway, as I was studying I needed a project to focus my attention while learning the language. It is a big help to develop a small narrow purposed application to get you up to speed while learning a new language. 

Furthermore, I spent a year developing this data engine for java.  After I deemed it ready for use and wider testing I used it to develop single screen utilities that needed access to large amounts of data; like a zip code finder.  Through this testing I found the little engine to be extremely reliable. (To date [01-18-07] I have not had a single data anomaly or corruption of any kind.)

During this stage I tested it with a 40K row zip code file.  I isolated many common performance problems inherent to file based data systems and optimized the general access of data.

After I was happy with the performance at this point I started the application I had been mulling over for a long time (Nevitium).  During this project several changes were made to further increase the speed at which you can get to the data and organize it.  All the while I was resisting the temptation to implement bloat features, joins, cascaded deletes, indexing, or transactions.  (Transactions are easy to implement without further modification.)  One thing I did add was the ability to address rows by byte location (apposed to just key) (searches can return byte locations or keys and in turn rows can be accessed either way; however this still requires a manual search; to index it you would have to implement a mark/pack system instead of the current instant delete process)

As I finished this freeware project (Nevitium) I felt the need to release something open source so I decided to release the db engine I created as moleculeJ.  One of the reasons I did this is because I want new programmers to be able to examine the core of a data engine so they are not intimidated by SQL servers and such.  When I was a young lad this greatly interested me.

 

Change Log
[Feb-01-2007] (not uploaded yet)
Changed String storage from Unicode byte representation to ASCII bytes (top 8 bits discarded) [RAF.writeBytes(String s)].  In other words it now stores strings in half the space as the original release.  This not only makes it lighter but faster as well.
 

[Feb-08-2007]
currently making a jar but i don't have time so it will be while.

email: seanka@datavirtue.com for a recent version until I upload the new release (jar file) to sourceForge.net