Author: tfischer
Date: Wed Apr 6 12:27:37 2011
New Revision: 1089423
URL: http://svn.apache.org/viewvc?rev=1089423&view=rev
Log:
Added a mapper for java.util.Date.
The class was written and licensed to the Apache Software Foundation by my
colleague Ralph Noerenberg.
Added:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java
Added:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java?rev=1089423&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java
(added)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java
Wed Apr 6 12:27:37 2011
@@ -0,0 +1,82 @@
+package org.apache.torque.om.mapper;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+
+import org.apache.torque.TorqueException;
+
+/**
+ * Maps a database record to a java.util.Date.
+ *
+ * @version $Id: $
+ */
+public class DateMapper implements RecordMapper<Date>
+{
+ /** The internal offset for the mapper. */
+ private int internalOffset;
+
+ /**
+ * Constructs a DateMapper with an offset of 0.
+ */
+ public DateMapper()
+ {
+ this.internalOffset = 0;
+ }
+
+ /**
+ * Constructs a DateMapper with the given offset.
+ *
+ * @param offset the additional offset (0 based).
+ */
+ public DateMapper(int offset)
+ {
+ this.internalOffset = offset;
+ }
+
+ /**
+ * Maps a ResultSet column to a java.uti.Date.
+ *
+ * @param resultSet the result set to read
+ * @param offset the column offset for the column.
+ *
+ * @return the column as a Date.
+ */
+ public Date processRow(ResultSet resultSet, int offset)
+ throws TorqueException
+ {
+ try
+ {
+ java.util.Date value = resultSet.getTimestamp(
+ offset + internalOffset + 1);
+ if (resultSet.wasNull())
+ {
+ value = null;
+ }
+ return value;
+ }
+ catch (SQLException e)
+ {
+ throw new TorqueException(e);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]