Class Jet

All Implemented Interfaces:
Removable, Storable, Cloneable

public class Jet extends DataJet implements Storable, Removable
A concrete entension of DataJet that implements Storable and Removable and can be used by composition or inheritance. Jet provides methods for all DataJet operations (create, read, update, and delete). Jet can be extended to create other DataJet classes, and combined with SqlBuilder to return database records in many different ways.

Jet, like all classes that extend DataJet, must 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, Jet 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.

When working with Jet by composition, initialize the class by either calling a static jetSet method, or by instantiating the object with a constructor that also initializes the DataJet. When extending Jet, it is usually a good idea to create a new jetSet method that encapsulates the initialization information, and explicitly call that method in the default constructor.

The examples below show how to work with Jet by composition.

To create a new record, follow this example:

//Example: Creating a new record
String connectionString = [insert connection url];
String table = "my_table";
String[] fields = new String[]{"id", "field1", "field2"};
JetSet jetSet = new JetSet(connectionString, table, fields);
Jet dj = new Jet(jetSet);
dj.setValue(1, "new value 1");
dj.setValue(2, "new value 2");
dj.store();
To load an existing record and then delete it, follow this example:
//Example: Load an existing record, then delete it
String connectionString = [insert connection url];
String table = "my_table";
String[] fields = new String[]{"id", "field1", "field2"};
JetSet jetSet = new JetSet(connectionString, table, fields);
Jet dj = Jet.load(1, jetSet); //load record with id = 1;
System.out.println(dj.getValue(1)); //display a field from the record
dj.remove(); //deletes the record from the database
The following listing shows how to create a basic class that extends Jet:
import anderix.datajets.*;

class MyDataJet extends Jet {

        public static JetSet jetSet() {
                String driver = [insert database driver];
                String connectionString = [insert connection url];
                String table = "my_table";
                String[] fields = new String[]{"id", "field1", "field2"};                       
                return new JetSet(driver, connectionString, table, fields);
        }
        
        public MyDataJet() {
                super(jetSet());
        }
        
        public MyDataJet load(int idToLoad) throws DataJetException {
                return (MyDataJet)load(idToLoad, new MyDataJet(), jetSet()); //call load method from DataJet
        }
}
The above DataJet will be able to create, read, update and delete records. For example:
//Example: create new record
MyDataJet dj = new MyDataJet();
dj.setValue(1, "new value 1");
dj.setValue(2, "new value 2");
dj.store();
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Jet(int id, JetSet jetSet)
    Constructor that sets the id for Jet to use.
    Jet(JetSet jetSet)
    Constructor that accepts a JetSet.
  • Method Summary

    Modifier and Type
    Method
    Description
    getValue(int fieldIndex)
    Returns the value of a field.
    getValueAsObject(int fieldIndex)
    Returns the value of a field.
    static Jet[]
    loadAll(JetSet jetSet)
    Loads an array of all Jets from the database.
    static Jet[]
    loadBySql(SqlBuilder sql, JetSet jetSet)
    Loads an array of Jets based on a SqlBuilder object.
    static Jet[]
    loadBySql(String sql, JetSet jetSet)
    Loads an array of Jets based on an SQL statement.
    static Jet
    loadJet(int id, JetSet jetSet)
    Loads a Jet with identity field equal to id from the database.
    void
    Removes the current Jet from the database.
    void
    setValue(int fieldIndex, boolean newvalue)
    Sets the value of a field.
    void
    setValue(int fieldIndex, byte newvalue)
    Sets the value of a field.
    void
    setValue(int fieldIndex, double newvalue)
    Sets the value of a field.
    void
    setValue(int fieldIndex, float newvalue)
    Sets the value of a field.
    void
    setValue(int fieldIndex, int newvalue)
    Sets the value of a field.
    void
    setValue(int fieldIndex, long newvalue)
    Sets the value of a field.
    void
    setValue(int fieldIndex, short newvalue)
    Sets the value of a field.
    void
    setValue(int fieldIndex, Datum newvalue)
    Sets the value of a field.
    void
    setValue(int fieldIndex, Object newvalue)
    Sets the value of a field.
    void
    Stores the current Jet in the database.

    Methods inherited from class anderix.datajets.DataJet

    clone, getId, getIdAsDatum

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Jet

      public Jet(int id, JetSet jetSet)
      Constructor that sets the id for Jet to use. Please note that this creation method does not load the record into the DataJet from the database. Use the static loadJet method for this, or override DataJet.load.
      Parameters:
      id - integer representing the identity field value
      jetSet - JetSet containing properties for the DataJet
      See Also:
    • Jet

      public Jet(JetSet jetSet)
      Constructor that accepts a JetSet.
      Parameters:
      jetSet - JetSet containing properties for the DataJet
  • Method Details

    • setValue

      public void setValue(int fieldIndex, int newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - int value to set the field to
    • setValue

      public void setValue(int fieldIndex, boolean newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - boolean value to set the field to
    • setValue

      public void setValue(int fieldIndex, short newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - short value to set the field to
    • setValue

      public void setValue(int fieldIndex, long newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - long value to set the field to
    • setValue

      public void setValue(int fieldIndex, float newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - float value to set the field to
    • setValue

      public void setValue(int fieldIndex, double newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - double value to set the field to
    • setValue

      public void setValue(int fieldIndex, byte newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - byte value to set the field to
    • setValue

      public void setValue(int fieldIndex, Object newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - Object value to set the field to
    • setValue

      public void setValue(int fieldIndex, Datum newvalue)
      Sets the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      newvalue - Datum value to set the field to
      See Also:
    • getValue

      public Datum getValue(int fieldIndex)
      Returns the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      Returns:
      Datum representation of the current value.
      See Also:
    • getValueAsObject

      public Object getValueAsObject(int fieldIndex)
      Returns the value of a field.
      Parameters:
      fieldIndex - zero-based ordinal position of field in fieldList (defined when initializing the DataJet)
      Returns:
      Object representation of the current value
    • loadJet

      public static Jet loadJet(int id, JetSet jetSet) throws DataJetException
      Loads a Jet with identity field equal to id from the database.
      Parameters:
      id - the unique value of the identity field
      jetSet - JetSet containing properties for the DataJet
      Returns:
      Jet containing data from the database
      Throws:
      DataJetException - if the connection to the database can not be established or if the DataJet has not been initialized
    • loadBySql

      public static Jet[] loadBySql(SqlBuilder sql, JetSet jetSet) throws DataJetException
      Loads an array of Jets based on a SqlBuilder object.
      Parameters:
      sql - SqlBuilder defining the records to load.
      jetSet - JetSet containing properties for the DataJet
      Returns:
      array of Jet objects representing all records in the database
      Throws:
      DataJetException - if the connection to the database can not be established or if the DataJet has not been initialized
    • loadBySql

      public static Jet[] loadBySql(String sql, JetSet jetSet) throws DataJetException
      Loads an array of Jets based on an SQL statement.
      Parameters:
      sql - String containing SQL specifying the records to load.
      jetSet - JetSet containing properties for the DataJet
      Returns:
      array of Jet objects representing all records in the database
      Throws:
      DataJetException - if the connection to the database can not be established or if the DataJet has not been initialized
    • loadAll

      public static Jet[] loadAll(JetSet jetSet) throws DataJetException
      Loads an array of all Jets from the database.
      Parameters:
      jetSet - JetSet containing properties for the DataJet
      Returns:
      array of Jet objects representing all records in the database
      Throws:
      DataJetException - if the connection to the database can not be established or if the DataJet has not been initialized
    • store

      public void store() throws DataJetException
      Stores the current Jet in the database. This method can be used to add a new Jet or to update an existing one.
      Specified by:
      store in interface Storable
      Throws:
      DataJetException - if the connection to the database can not be established or if the DataJet has not been initialized
      See Also:
      • DataJet.store(java.sql.Connection)
    • remove

      public void remove() throws DataJetException
      Removes the current Jet from the database.
      Specified by:
      remove in interface Removable
      Throws:
      DataJetException - if the connection to the database can not be established if the DataJet has not been initialized
      See Also:
      • DataJet.remove(java.sql.Connection)