?? value.java
字號:
catch (Exception e)
{
throw new DataSetException("Bad conversion: " + e.toString());
}
}
/**
* Get the value as a asShort
*
* @return a short
* @exception DataSetException
*/
public short asShort() throws DataSetException
{
try
{
if (isNull())
return 0;
else if (isShort())
return ((Short) valueObject).shortValue();
else if (isString())
return Integer.valueOf((String) valueObject).shortValue();
else if (isInt())
return ((Integer) valueObject).shortValue();
else if (isLong())
return ((Long) valueObject).shortValue();
else if (isDouble())
return ((Double) valueObject).shortValue();
else if (isFloat())
return ((Float) valueObject).shortValue();
else if (isBigDecimal())
return ((BigDecimal) valueObject).shortValue();
else
return Integer.valueOf(asString()).shortValue();
}
catch (Exception e)
{
throw new DataSetException("Bad conversion: " + e.toString());
}
}
/**
* Returns the string representation of this object
*
* @return a string
*/
public String asString()
{
if (isNull())
return null;
else if (isString())
return (String) valueObject;
else if (isBytes ())
return new String ((byte[])valueObject);
else
return valueObject.toString();
}
/**
* Get the value as a asTime
*
* @return a Time
* @exception DataSetException
*/
public Time asTime() throws DataSetException
{
try
{
if (isNull())
return null;
else if (isTime())
return (Time) valueObject;
Calendar cal = Calendar.getInstance();
if (isTimestamp())
{
cal.setTime ((Timestamp) valueObject);
return new Time(cal.get(Calendar.HOUR),
cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
}
else if (isUtilDate())
{
cal.setTime ((java.util.Date) valueObject);
return new Time(cal.get(Calendar.HOUR),
cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
}
else if (isString())
return Time.valueOf((String) valueObject);
else
return Time.valueOf(asString());
}
catch (IllegalArgumentException a)
{
throw new DataSetException("Bad date value - Java Time Objects cannot be earlier than 1/1/70");
}
catch (Exception b)
{
throw new DataSetException("Bad conversion: " + b.toString());
}
}
/**
* Get the value as a asTimestamp
*
* @return a Timestamp
* @exception DataSetException
*/
public Timestamp asTimestamp() throws DataSetException
{
try
{
if (isNull())
return null;
else if (isTimestamp())
return (Timestamp) valueObject;
Calendar cal = Calendar.getInstance();
if (isTime())
{
cal.setTime ((Time) valueObject);
return new Timestamp(cal.getTime().getTime());
}
else if (isUtilDate())
{
cal.setTime ((java.util.Date) valueObject);
return new Timestamp(cal.getTime().getTime());
}
else if (isString())
return Timestamp.valueOf((String) valueObject);
else
return Timestamp.valueOf(asString());
}
catch (IllegalArgumentException a)
{
throw new DataSetException("Bad date value - Java Timestamp Objects cannot be earlier than 1/1/70");
}
catch (Exception b)
{
throw new DataSetException("Bad conversion: " + b.toString());
}
}
/**
* Get the value as a asUtilDate
*
* @return a java.util.Date
* @exception DataSetException
*/
public java.util.Date asUtilDate() throws DataSetException
{
try
{
if (isNull())
return null;
else if (isUtilDate ())
return (java.util.Date) valueObject;
else
return null;
}
catch (IllegalArgumentException a)
{
throw new DataSetException("Bad date value - Java java.util.Date Objects cannot be earlier than 1/1/70");
}
catch (Exception b)
{
throw new DataSetException("Bad conversion: " + b.toString());
}
}
/**
* Gets the columnNumber which this value represents.
*
* @return an int
*/
int columnNumber()
{
return this.columnNumber;
}
/**
* Gets the object from this Value
*
* @return the object from this Value
*/
Object getValue ()
{
return this.valueObject;
}
/**
* Is the value a isBigDecimal
*
* @return true if BigDecimal
*/
public boolean isBigDecimal()
{
return valueObject instanceof BigDecimal;
}
/**
* Is the value a isBoolean
*
* @return true if is Boolean
*/
public boolean isBoolean()
{
return valueObject instanceof Boolean;
}
/**
* Is the value a isByte
*
* @return true if is Byte
*/
public boolean isByte()
{
return valueObject instanceof Byte;
}
/**
* Is the value a isBytes
*
* @return true if is byte[]
*/
public boolean isBytes()
{
return valueObject instanceof byte[];
}
/**
* Is the value a isDate
*
* @return true if is java.sql.Date
*/
public boolean isDate()
{
return valueObject instanceof java.sql.Date;
}
/**
* Is the value a isDouble
*
* @return true if is Double
*/
public boolean isDouble()
{
return valueObject instanceof Double;
}
/**
* Is the value a isFloat
*
* @return true if is Float
*/
public boolean isFloat()
{
return valueObject instanceof Float;
}
/**
* Is the value a isInt
*
* @return true if is Integer
*/
public boolean isInt()
{
return valueObject instanceof Integer;
}
/**
* Is the value a isLong
*
* @return true if is Long
*/
public boolean isLong()
{
return valueObject instanceof Long;
}
/**
* Is the value a isNull
*
* @return true if is null
*/
public boolean isNull()
{
return valueObject == null;
}
/**
* Is the value a isShort
*
* @return true if is Short
*/
public boolean isShort()
{
return valueObject instanceof Short;
}
/**
* Is the value a isString
*
* @return true if is String
*/
public boolean isString()
{
return valueObject instanceof String;
}
/**
* Is the value a isTime
*
* @return true if is java.sql.Time
*/
public boolean isTime()
{
return valueObject instanceof java.sql.Time;
}
/**
* Is the value a isTimestamp
*
* @return true if is java.sql.Timestamp
*/
public boolean isTimestamp()
{
return valueObject instanceof java.sql.Timestamp;
}
/**
* Is the value a isUtilDate
*
* @return true if is java.util.Date
*/
public boolean isUtilDate()
{
return valueObject instanceof java.util.Date;
}
/**
* This is used in Record in order to do a saveWithInsert/Update/Delete
*
* @param stmt
* @param stmtNumber
* @exception DataSetException
* @exception ConnectionException
*/
void setPreparedStatementValue (PreparedStatement stmt,
int stmtNumber) throws DataSetException, ConnectionException
{
try
{
if (isNull ())
{
stmt.setNull (stmtNumber, type ());
return;
}
switch (type())
{
case Types.BIT:
stmt.setBoolean (stmtNumber, this.asBoolean());
break;
case Types.TINYINT:
stmt.setByte (stmtNumber, this.asByte());
break;
case Types.BIGINT:
stmt.setLong (stmtNumber, this.asLong());
break;
case Types.SMALLINT:
stmt.setShort (stmtNumber, this.asShort());
break;
case Types.INTEGER:
stmt.setInt (stmtNumber, this.asInt());
break;
case Types.REAL:
stmt.setFloat (stmtNumber, this.asFloat());
break;
case Types.FLOAT:
case Types.DOUBLE:
stmt.setDouble (stmtNumber, this.asDouble());
break;
case Types.NUMERIC:
case Types.DECIMAL:
stmt.setBigDecimal (stmtNumber, this.asBigDecimal());
break;
case Types.LONGVARBINARY:
case Types.VARBINARY:
case Types.BINARY:
stmt.setBytes (stmtNumber, this.asBytes());
break;
case Types.LONGVARCHAR:
case Types.CHAR:
case Types.VARCHAR:
case Types.OTHER:
stmt.setString (stmtNumber, this.asString());
break;
case Types.DATE:
stmt.setDate (stmtNumber, this.asDate());
break;
case Types.TIME:
stmt.setTime (stmtNumber, this.asTime());
break;
case Types.TIMESTAMP:
stmt.setTimestamp (stmtNumber, this.asTimestamp());
break;
case Types.NULL:
stmt.setNull (stmtNumber, 0);
break;
default:
stmt.setString (stmtNumber, this.asString());
break;
}
}
catch (SQLException sqle)
{
throw new ConnectionException (sqle);
}
}
/**
* Sets the value of this object
*
* @param value
*/
void setValue (Object value)
{
this.valueObject = value;
}
/**
* Returns the string representation of this object
*
* @return a string
*/
public String toString()
{
return this.asString();
}
/**
* Return the type of this value
*
* @return the type of this value
*/
public int type()
{
return this.type;
}
/**
* Clones the object
*
* @return a clone of this object
*/
public Object clone ()
{
Value newVal = new Value ();
newVal.valueObject = this.valueObject;
newVal.columnNumber = this.columnNumber;
newVal.type = this.type;
return newVal;
}
/**
* Compares whether the two values are identical
*
* @return boolean
*/
public boolean equals (Object obj)
{
if (obj == null)
return false;
if (obj instanceof Value)
{
Value val = (Value)obj;
return this.valueObject.equals (val.valueObject);
}
return this.valueObject.equals (obj);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -