Class DataJet

java.lang.Object
anderix.datajets.DataJet
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
Jet

public abstract class DataJet extends Object implements 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 connection string, 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 anderix.datajets.*;

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

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

        public int getField2() {
                return getValue(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:
  • Method Details

    • 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 Object clone()
      Returns a clone of the DataJet.
      Returns:
      Object containing clone of the DataJet