Files
HRMS/hrmsEjb/org/apache/commons/beanutils/converters/SqlTimestampConverter.java
2025-07-28 13:56:49 +05:30

43 lines
1.1 KiB
Java

package org.apache.commons.beanutils.converters;
import java.sql.Timestamp;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
public final class SqlTimestampConverter implements Converter {
private Object defaultValue;
private boolean useDefault;
public SqlTimestampConverter() {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = null;
this.useDefault = false;
}
public SqlTimestampConverter(Object defaultValue) {
this.defaultValue = null;
this.useDefault = true;
this.defaultValue = defaultValue;
this.useDefault = true;
}
public Object convert(Class type, Object value) {
if (value == null) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException("No value specified");
}
if (value instanceof Timestamp)
return value;
try {
return Timestamp.valueOf(value.toString());
} catch (Exception e) {
if (this.useDefault)
return this.defaultValue;
throw new ConversionException(e);
}
}
}