> List of tutorials for developing a Fat-Client

Index of Basic knowledge for developing Fat-Clients with Java

Code for Base-Class for a Data-Base-Access (DBA) Object - Fat-Client-Development

* For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

  • The owner of this web-site (www.javascout.biz) is not responsible for the content of web-sites linked within this document or other documents of www.javascout.biz.

  • If this document or other documents of this web-site (www.javascout.biz) infringes your rights or you think that rights of others (third parties) are infringed, please inform the author.
    An e-mail can be sent by clicking onto the 'hungry mailbox' in the upper right corner.

Last revision of this document:
2006-07-24

This is document contains the code for Class JSBS_DBA.
For easy 'cut and paste' ;-)

For an overview of the idea of Data-Base-Access Objects please refer to Using Business Objects to handle data-storage and -retrieval .
For an explanation how the variables in this object contribute to produce a change-history, please refer to Common Attributes for all database-tables .

package js_base.dba;

import java.sql.*;

/**
 
*
 * @author
kurt@javascout.biz
 * @date 2006-06-22
 *
 * @description
 *  Base-Class for Data-Base-Access (DBA) Objects.
 *  This class can be inherited by DBA Objects designed for a dedicated database-table.
 *
 *  The variables in this class coincide with the variables
 *  fo
r the Business Objects base class (JSBS-BO)
.
 *  Please refer to this class for a detailled description of the variables
 
*
 * @change-log
 * when         who               why
 * --------------------------------------------------------
 *
 */

public class JSBS_DBA {
/*
 * CONSTANTS with attribute-names (of the database-table" and
 * 
attribute-strings for SELECT/INSERT and UPDATE.
 * --------------------
 * For a detailled description of each attribute please refer to the VARIABLES */
/* ObjectID */
    public final static String CONST_ObjectID = "ObjectID";
/* DataSetID */
    public final static String
CONST_DataSetID = "DataSetID";
/* The name of the user (if available within the application) who inserted
 * the first database-record with the 'user-key'. */
    public final static String
CONST_CreatedBy = "CreatedBy";
/* System-time when the first database-record with the 'user-key' was inserted. */
    
public final static String CONST_CreatedAt = "CreatedAt";
/* The name of the user (if available within the application) who made
 * a change of an attribute of the database-record. */
    public final static
String CONST_ChangedBy = "ChangedBy";
/* System-time when the last change to the database-record was made. */
    public final static String CONST_ChangedAt = "ChangedAt";
/* Date, from that on (at 0.00 h /midnight) the data in the database-record is valid. */
    public final static String CONST_ValidFrom = "ValidFrom";
/* Date, until that (at 24.00 h /midnight) the data in the database-record is valid. */
    public final static String CONST_ValidTill = "ValidTill";
/*
 * String with all common attributes;
 * can be used when accessing database-tables for SELECT or INSERT. */
    public final static String CONST_COMMON_ATTRIBUTES_LIST =
        
CONST_ObjectID + ", "
+
        CONST_DataSetID + ", " +
        CONST_CreatedBy + ", " +
        CONST_CreatedAt + ", " +
        CONST_ChangedBy + ", " +
        CONST_ChangedAt + ", " +
        CONST_ValidFrom + ", " +
        
CONST_ValidTill;
/*
 * String with all common attributes to be used for UPDATE database-records. */
    public final static String
CONST_COMMON_ATTRIBUTES_LIST_FOR_UPDATE =
        
CONST_ObjectID + " = ?, "
+
        CONST_DataSetID + " = ?, " +
        CONST_CreatedBy + " = ?, " +
        CONST_CreatedAt + " = ?, " +
        CONST_ChangedBy + " = ?, " +
        CONST_ChangedAt + " = ?, " +
        CONST_ValidFrom + " = ?, " +
        CONST_ValidTill + " = ?, ";
/*
 * VARIABLES reflecting the attributes of the table
.
 * -------------------- */
/* ObjectID contains the 'Surrogate' that was the primary-key of the database-record
 * at the time when a record with a new 'user-key' (individually define for each tatabase-table)
 * was initially inserted. */
    
public double ObjectID;
/*
 * DataSetID contains the 'Surrogate' that is the primary-key of the database-record
 * which is actually valid. */
    
public double DataSetID;
/*
 * The name of the user (if available within the application) who inserted the
 * first database-record with this 'user-key'. */
    
public String CreatedBy;
/*
 * TimeStamp – Date/Time (down to 1/1000 second) when the first database-record
 * with this 'user-key' was inserted into the database. */
    
public Timestamp CreatedAt;
/*
 * The name of the user (if available within the application) who made
 * the last change of an attribute of the database-record. */
    
public String ChangedBy;
/*
 * TimeStamp – Date/Time (down to 1/1000 second) when the
 * last change of an attribute was written to the database. */
    
public Timestamp ChangedAt;
/*
 * Date, from that on (at 00:00 h / midnight) the data in this database-record is valid. */
    
public Date ValidFrom;
/*
 * Date, until that (at 24:00 h / midnight) the data in this database-record is valid. */
    public Date ValidTill;
/*
 * String with the Error-Message (from the database-system) when the DB-operation fails. */
    public String
ErrorMsg
= "";
/*
 * METHODS
 * -------------------- */

/*
 * Method to transfer the values from the SQL-ResultSet (a class within the
 *  package java.sql that is filled by a SELECT) to the variables of this class.
*/

    public void getSQLResultSetForCommonAttributes(ResultSet parmSQLResultSet)
    throws
SQLException {
      this.ObjectID = parmSQLResultSet.getDouble(CONST_ObjectID);

      
this.DataSetID = parmSQLResultSet.getDouble(CONST_DataSetID);
      this.CreatedBy = parmSQLResultSet.getString(CONST_CreatedBy);
      this.CreatedAt = parmSQLResultSet.getTimestamp(CONST_CreatedAt);
      this.ChangedBy = parmSQLResultSet.getString(CONST_ChangedBy);
      this.ChangedAt = parmSQLResultSet.getTimestamp(CONST_ChangedAt);
      this.ValidFrom = parmSQLResultSet.getDate(CONST_ValidFrom);
      this.ValidTill = parmSQLResultSet.getDate(CONST_ValidTill);
    }
/*
 * Method to transfer the values from the variables of this class to the PreparedStatement
 * (a class within the package java.sql that contains the SQL-Statement and the new values
 * for the attributes before a INSERT or UPDATE is called). */

    
public void setSQLStatementWithCommonAttributes(PreparedStatement parmSQLStatement)
    throws
SQLException {
      parmSQLStatement.setDouble(1, ObjectID);

      parmSQLStatement.setDouble(2, DataSetID);
      parmSQLStatement.setString(3, CreatedBy);
      parmSQLStatement.setTimestamp(4, CreatedAt);
      parmSQLStatement.setString(5, ChangedBy);
      parmSQLStatement.setTimestamp(6, ChangedAt);
      parmSQLStatement.setDate(7, ValidFrom);
      parmSQLStatement.setDate(8, ValidTill);
    }

}