anderix.datajets
Class DataJet

java.lang.Object
  extended by anderix.datajets.DataJet
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
GenericDataJet

public abstract class DataJet
extends java.lang.Object
implements java.lang.Cloneable

The base class for all DataJets. DataJet provides protected methods for all basic database operations (create, read, update, and delete), but it exposes very little of that functionality publicly. To create a useful class, write new methods that expose the functionality.

To use DataJet's methods, the class must first be initialized with connection, table and field information. The connection information can be supplied as driver and connection string, or as an object that implements ConnectionGenerator. Table and fields must both be defined. If any of this initialization information is missing or incorrect, DataJet will throw exceptions when calling its various methods -- ConnectionException if the connection information is incorrect and DataJetException if the table or field information is incorrect. The following listing shows how to create a basic class that extends DataJet and provides methods for loading all records in the database:

import com.datajets.*;

class MyDataJet extends DataJet {
        public static JetSet jetSet() {
                return new JetSet( [insert database driver],
                        [insert connection url], 
                        "my_table",
                        new String[]{"id", "field1", "field2"}
                );
        }

        public MyDataJet() {
                super(jetSet());
        }

        public String getField1() {
                return getFieldValue(1).toString();
        }

        public int getField2() {
                return getFieldValue(2).toInt();
        }

        public static MyDataJet[] loadAll() throws DataJetException {
                MyDataJet[] dj = new MyDataJet[]{new MyDataJet()};
                JetSet jset = jetSet();
                SqlBuilder sql = new SqlBuilder(jset.getTable(), jset.getFieldList());
                return (MyDataJet[])MyDataJet.loadMultiple(sql, dj, jset);
        }
}
The above DataJet will be able to read all records from the database. For example:
//Example: read all records from the database
MyDataJet[] jets = MyDataJet.loadAll();
for ( int i = 0; i < jets.length; i++ ) {
        System.out.println( jets[i].getField1() + " " + jets[i].getField2() );
}

See Also:
GenericDataJet, Storable, Removable

Method Summary
 java.lang.Object clone()
          Returns a clone of the DataJet.
 int getId()
          Returns the value of the identity field for the currently-loaded DataJet.
 Datum getIdAsDatum()
          Returns the value of the identity field for the currently-loaded DataJet as a Datum.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getId

public int getId()
Returns the value of the identity field for the currently-loaded DataJet. If no record is loaded, getId returns zero (0);

Returns:
int value of identity field

getIdAsDatum

public Datum getIdAsDatum()
Returns the value of the identity field for the currently-loaded DataJet as a Datum. If no record is loaded, getId returns null;

Returns:
int value of identity field

clone

public java.lang.Object clone()
Returns a clone of the DataJet.

Overrides:
clone in class java.lang.Object
Returns:
Object containing clone of the DataJet