/** * Creates a new object of the same class as this object. * @return a clone of this instance. * @exception CloneNotSupportedException if the object's class does not support the <code>Cloneable</code> interface. * @see java.lang.Cloneable */ public Object clone() throws CloneNotSupportedException { BaseField field = new TimeField(null, m_strFieldName, m_iMaxLength, m_strFieldDesc, null); field.setRecord(m_record); // Set table without adding to table field list return field; } /**
/** * Given this date, return the best Starting date and time. If none, * just return the date that was passed in. */ public Date getStartDate(Date date) { Date dateEtd = ((TimeField)this.getField(Product.ETD)).getDateTime(); if (dateEtd == null) return date; Calendar calendar = Converter.gCalendar; calendar.setTime(dateEtd); int iHour = calendar.get(Calendar.HOUR_OF_DAY); int iMinute = calendar.get(Calendar.MINUTE); int iSecond = calendar.get(Calendar.SECOND); int iMillisecond = calendar.get(Calendar.MILLISECOND); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, iHour); calendar.set(Calendar.MINUTE, iMinute); calendar.set(Calendar.SECOND, iSecond); calendar.set(Calendar.MILLISECOND, iMillisecond); date = calendar.getTime(); return date; } /**
/** * Get this field in SQL format. * For dates, I use the DateConverter.binaryToString SQL formats (ie., XX/XX/XX). * @return The date formatted as a SQL string. */ public String getSQLString() { return DateConverter.binaryToString(this.getData(), DBConstants.SQL_TIME_FORMAT); } /**
/** * Move the physical binary data to this SQL parameter row. * @param resultset The resultset to get the SQL data from. * @param iColumn the column in the resultset that has my data. * @exception SQLException From SQL calls. */ public void moveSQLToField(ResultSet resultset, int iColumn) throws SQLException { java.util.Date dateResult = resultset.getTime(iColumn); if (resultset.wasNull()) this.setString(Constants.BLANK, false, DBConstants.READ_MOVE); // Null value else this.setValue((double)dateResult.getTime(), false, DBConstants.READ_MOVE); } /**
/** * Change the date and time of day. * @param date The date to set (only time portion is used). * @param bDisplayOption Display changed fields if true. * @param iMoveMode The move mode. * @return The error code (or NORMAL_RETURN). */ public int setDateTime(java.util.Date date, boolean bDisplayOption, int moveMode) { if (date != null) { m_calendar.setTime(date); m_calendar.set(Calendar.YEAR, DBConstants.FIRST_YEAR); m_calendar.set(Calendar.MONTH, Calendar.JANUARY); m_calendar.set(Calendar.DATE, 1); date = m_calendar.getTime(); return this.setValue(date.getTime(), bDisplayOption, moveMode); } else return this.setData(null, bDisplayOption, moveMode); } /**
/** * Move the physical binary data to this SQL parameter row. * @param statement The SQL prepare statement. * @param iType the type of SQL statement. * @param iParamColumn The column in the prepared statement to set the data. * @exception SQLException From SQL calls. */ public void getSQLFromField(PreparedStatement statement, int iType, int iParamColumn) throws SQLException { if (this.isNull()) { if ((!this.isNullable()) || (iType == DBConstants.SQL_SELECT_TYPE) || (DBConstants.FALSE.equals(this.getRecord().getTable().getDatabase().getProperties().get(SQLParams.NULL_TIMESTAMP_SUPPORTED)))) // HACK for Access { // Access does not allow you to pass a null for a timestamp (must pass a 0) java.sql.Timestamp sqlDate = new java.sql.Timestamp(0); statement.setTimestamp(iParamColumn, sqlDate); } else statement.setNull(iParamColumn, Types.TIME); } else { java.sql.Time sqlTime = new java.sql.Time((long)this.getValue()); statement.setTime(iParamColumn, sqlTime); } } /**
/** * Constructor. * @param record The parent record. * @param strName The field name. * @param iDataLength The maximum string length (pass -1 for default). * @param strDesc The string description (usually pass null, to use the resource file desc). * @param strDefault The default value (if object, this value is the default value, if string, the string is the default). */ public TimeField(Record record, String strName, int iDataLength, String strDesc, Object strDefault) { this(); this.init(record, strName, iDataLength, strDesc, strDefault); } /**
/** * Convert this string to this field's binary data format. * @param tempString A string to be converted to this field's binary data. * @return The physical data converted from this string (must be the raw data class). */ public Object stringToBinary(String tempString) throws Exception { java.util.Date dateOld = new java.util.Date((long)this.getValue()); // Save current time return DateConverter.stringToBinary(tempString, dateOld, DBConstants.TIME_ONLY_FORMAT); } /**
/** * Move the physical binary data to this SQL parameter row. * @param statement The SQL prepare statement. * @param iType the type of SQL statement. * @param iParamColumn The column in the prepared statement to set the data. * @exception SQLException From SQL calls. */ public void getSQLFromField(PreparedStatement statement, int iType, int iParamColumn) throws SQLException { if (this.isNull()) { if ((!this.isNullable()) || (iType == DBConstants.SQL_SELECT_TYPE) || (DBConstants.FALSE.equals(this.getRecord().getTable().getDatabase().getProperties().get(SQLParams.NULL_TIMESTAMP_SUPPORTED)))) // HACK for Access { // Access does not allow you to pass a null for a timestamp (must pass a 0) java.sql.Timestamp sqlDate = new java.sql.Timestamp(0); statement.setTimestamp(iParamColumn, sqlDate); } else statement.setNull(iParamColumn, Types.TIME); } else { java.sql.Time sqlTime = new java.sql.Time((long)this.getValue()); statement.setTime(iParamColumn, sqlTime); } } /**
/** * Move the physical binary data to this SQL parameter row. * @param resultset The resultset to get the SQL data from. * @param iColumn the column in the resultset that has my data. * @exception SQLException From SQL calls. */ public void moveSQLToField(ResultSet resultset, int iColumn) throws SQLException { java.util.Date dateResult = resultset.getTime(iColumn); if (resultset.wasNull()) this.setString(Constants.BLANK, false, DBConstants.READ_MOVE); // Null value else this.setValue((double)dateResult.getTime(), false, DBConstants.READ_MOVE); } /**
/** * Change the date and time of day. * @param date The date to set (only time portion is used). * @param bDisplayOption Display changed fields if true. * @param iMoveMode The move mode. * @return The error code (or NORMAL_RETURN). */ public int setDateTime(java.util.Date date, boolean bDisplayOption, int moveMode) { if (date != null) { m_calendar.setTime(date); m_calendar.set(Calendar.YEAR, DBConstants.FIRST_YEAR); m_calendar.set(Calendar.MONTH, Calendar.JANUARY); m_calendar.set(Calendar.DATE, 1); date = m_calendar.getTime(); return this.setValue(date.getTime(), bDisplayOption, moveMode); } else return this.setData(null, bDisplayOption, moveMode); } /**
/** * Constructor. * @param record The parent record. * @param strName The field name. * @param iDataLength The maximum string length (pass -1 for default). * @param strDesc The string description (usually pass null, to use the resource file desc). * @param strDefault The default value (if object, this value is the default value, if string, the string is the default). */ public TimeField(Record record, String strName, int iDataLength, String strDesc, Object strDefault) { this(); this.init(record, strName, iDataLength, strDesc, strDefault); } /**
/** * Convert this string to this field's binary data format. * @param tempString A string to be converted to this field's binary data. * @return The physical data converted from this string (must be the raw data class). */ public Object stringToBinary(String tempString) throws Exception { java.util.Date dateOld = new java.util.Date((long)this.getValue()); // Save current time return DateConverter.stringToBinary(tempString, dateOld, DBConstants.TIME_ONLY_FORMAT); } /**
/** * Creates a new object of the same class as this object. * @return a clone of this instance. * @exception CloneNotSupportedException if the object's class does not support the <code>Cloneable</code> interface. * @see java.lang.Cloneable */ public Object clone() throws CloneNotSupportedException { BaseField field = new TimeField(null, m_strFieldName, m_iMaxLength, m_strFieldDesc, null); field.setRecord(m_record); // Set table without adding to table field list return field; } /**
/** * Move the physical binary data to this SQL parameter row. * @param statement The SQL prepare statement. * @param iType the type of SQL statement. * @param iParamColumn The column in the prepared statement to set the data. * @exception SQLException From SQL calls. */ public void getSQLFromField(PreparedStatement statement, int iType, int iParamColumn) throws SQLException { if (this.isNull()) { if ((!this.isNullable()) || (iType == DBConstants.SQL_SELECT_TYPE) || (DBConstants.FALSE.equals(this.getRecord().getTable().getDatabase().getProperties().get(SQLParams.NULL_TIMESTAMP_SUPPORTED)))) // HACK for Access { // Access does not allow you to pass a null for a timestamp (must pass a 0) java.sql.Timestamp sqlDate = new java.sql.Timestamp(0); statement.setTimestamp(iParamColumn, sqlDate); } else statement.setNull(iParamColumn, Types.TIME); } else { java.sql.Time sqlTime = new java.sql.Time((long)this.getValue()); statement.setTime(iParamColumn, sqlTime); } } /**
/** * Move the physical binary data to this SQL parameter row. * @param resultset The resultset to get the SQL data from. * @param iColumn the column in the resultset that has my data. * @exception SQLException From SQL calls. */ public void moveSQLToField(ResultSet resultset, int iColumn) throws SQLException { java.util.Date dateResult = resultset.getTime(iColumn); if (resultset.wasNull()) this.setString(Constants.BLANK, false, DBConstants.READ_MOVE); // Null value else this.setValue((double)dateResult.getTime(), false, DBConstants.READ_MOVE); } /**
/** * Change the date and time of day. * @param date The date to set (only time portion is used). * @param bDisplayOption Display changed fields if true. * @param iMoveMode The move mode. * @return The error code (or NORMAL_RETURN). */ public int setDateTime(java.util.Date date, boolean bDisplayOption, int moveMode) { if (date != null) { m_calendar.setTime(date); m_calendar.set(Calendar.YEAR, DBConstants.FIRST_YEAR); m_calendar.set(Calendar.MONTH, Calendar.JANUARY); m_calendar.set(Calendar.DATE, 1); date = m_calendar.getTime(); return this.setValue(date.getTime(), bDisplayOption, moveMode); } else return this.setData(null, bDisplayOption, moveMode); } /**
/** * Given this date, return the best Starting date and time. If none, * just return the date that was passed in. */ public Date getStartDate(Date date) { Date dateEtd = ((TimeField)this.getField(Product.ETD)).getDateTime(); if (dateEtd == null) return date; Calendar calendar = Converter.gCalendar; calendar.setTime(dateEtd); int iHour = calendar.get(Calendar.HOUR_OF_DAY); int iMinute = calendar.get(Calendar.MINUTE); int iSecond = calendar.get(Calendar.SECOND); int iMillisecond = calendar.get(Calendar.MILLISECOND); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, iHour); calendar.set(Calendar.MINUTE, iMinute); calendar.set(Calendar.SECOND, iSecond); calendar.set(Calendar.MILLISECOND, iMillisecond); date = calendar.getTime(); return date; } /**
/** * Get this field in SQL format. * For dates, I use the DateConverter.binaryToString SQL formats (ie., XX/XX/XX). * @return The date formatted as a SQL string. */ public String getSQLString() { return DateConverter.binaryToString(this.getData(), DBConstants.SQL_TIME_FORMAT); } /**
/** * Constructor. * @param record The parent record. * @param strName The field name. * @param iDataLength The maximum string length (pass -1 for default). * @param strDesc The string description (usually pass null, to use the resource file desc). * @param strDefault The default value (if object, this value is the default value, if string, the string is the default). */ public TimeField(Record record, String strName, int iDataLength, String strDesc, Object strDefault) { this(); this.init(record, strName, iDataLength, strDesc, strDefault); } /**