You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by ha...@apache.org on 2001/11/14 03:24:43 UTC
cvs commit: jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl DateColumn.java TimeColumn.java TimestampColumn.java
hammant 01/11/13 18:24:42
Added: apps/db/src/java/org/apache/avalon/db/data/impl
DateColumn.java TimeColumn.java
TimestampColumn.java
Log:
more types
Revision Changes Path
1.1 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/DateColumn.java
Index: DateColumn.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.db.data.impl;
import org.apache.avalon.db.data.ValidationException;
import java.sql.Date;
/**
* Class DateColumn
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class DateColumn extends AbstractColumn {
/**
* Constructor DateColumn
* @param name
*/
public DateColumn(String name) {
super(name,"date", Date.class.getName());
}
public void test(Object obj) throws ValidationException {
try {
Date t;
if (obj instanceof String) {
t = Date.valueOf((String) obj);
} else if (obj instanceof Date) {
// all OK
} else {
throw new ValidationException("Date object named " + mName + " not recognised as String or Date");
}
} catch (IllegalArgumentException iae) {
throw new ValidationException("Date " + mName + " is not a valid format (" + obj + ")");
}
}
public Object convertFromString(String str) throws ValidationException {
test(str);
try {
return Date.valueOf((String) str);
} catch (IllegalArgumentException nfe) {
throw new ValidationException("Date object named " + mName + " not recognised as String or Date");
}
}
}
1.1 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/TimeColumn.java
Index: TimeColumn.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.db.data.impl;
import org.apache.avalon.db.data.ValidationException;
import java.sql.Time;
/**
* Class TimeColumn
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class TimeColumn extends AbstractColumn {
/**
* Constructor TimeColumn
* @param name
*/
public TimeColumn(String name) {
super(name,"time", Time.class.getName());
}
public void test(Object obj) throws ValidationException {
try {
Time t;
if (obj instanceof String) {
t = Time.valueOf((String) obj);
} else if (obj instanceof Time) {
// all OK
} else {
throw new ValidationException("Time object named " + mName + " not recognised as String or Time");
}
} catch (IllegalArgumentException iae) {
throw new ValidationException("Time " + mName + " is not a valid format (" + obj + ")");
}
}
public Object convertFromString(String str) throws ValidationException {
test(str);
try {
return Time.valueOf((String) str);
} catch (IllegalArgumentException nfe) {
throw new ValidationException("Time object named " + mName + " not recognised as String or Time");
}
}
}
1.1 jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/data/impl/TimestampColumn.java
Index: TimestampColumn.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.db.data.impl;
import org.apache.avalon.db.data.ValidationException;
import java.sql.Timestamp;
/**
* Class TimestampColumn
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class TimestampColumn extends AbstractColumn {
/**
* Constructor TimestampColumn
* @param name
*/
public TimestampColumn(String name) {
super(name,"timestamp", Timestamp.class.getName());
}
public void test(Object obj) throws ValidationException {
try {
Timestamp ts;
if (obj instanceof String) {
ts = Timestamp.valueOf((String) obj);
} else if (obj instanceof Timestamp) {
// all OK
} else {
throw new ValidationException("Timestamp object named " + mName + " not recognised as String or Timestamp");
}
} catch (IllegalArgumentException iae) {
throw new ValidationException("Timestamp " + mName + " is not a valid format (" + obj + ")");
}
}
public Object convertFromString(String str) throws ValidationException {
test(str);
try {
return Timestamp.valueOf((String) str);
} catch (IllegalArgumentException nfe) {
throw new ValidationException("Timestamp object named " + mName + " not recognised as String or Timestamp");
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>