001: /**********************************************************************
002: Copyright (c) 2007 Thomas Marti and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.store.mapping;
019:
020: import java.awt.geom.Point2D;
021:
022: import org.jpox.ClassLoaderResolver;
023: import org.jpox.ClassNameConstants;
024: import org.jpox.ObjectManager;
025: import org.jpox.metadata.AbstractMemberMetaData;
026: import org.jpox.store.DatastoreAdapter;
027: import org.jpox.store.DatastoreContainerObject;
028: import org.jpox.store.expression.LogicSetExpression;
029: import org.jpox.store.expression.QueryExpression;
030: import org.jpox.store.expression.ScalarExpression;
031:
032: /**
033: * Mapping for java.awt.geom.Point2D.Double, maps the x and y values to double-precision datastore fields.
034: * @version $Revision: 1.18 $
035: */
036: public class Point2dDoubleMapping extends SingleFieldMultiMapping {
037:
038: private static final Point2D.Double sampleValue = new Point2D.Double(
039: 0, 0);
040:
041: /*
042: * (non-Javadoc)
043: * @see org.jpox.store.mapping.JavaTypeMapping#initialize()
044: */
045: public void initialize(DatastoreAdapter dba,
046: AbstractMemberMetaData fmd,
047: DatastoreContainerObject container, ClassLoaderResolver clr) {
048: super .initialize(dba, fmd, container, clr);
049:
050: addDatastoreField(ClassNameConstants.DOUBLE); // X
051: addDatastoreField(ClassNameConstants.DOUBLE); // Y
052: }
053:
054: /*
055: * (non-Javadoc)
056: * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
057: */
058: public Class getJavaType() {
059: return Point2D.Double.class;
060: }
061:
062: /*
063: * (non-Javadoc)
064: * @see org.jpox.store.mapping.JavaTypeMapping#getSampleValue()
065: */
066: public Object getSampleValue(ClassLoaderResolver clr) {
067: return sampleValue;
068: }
069:
070: /*
071: * (non-Javadoc)
072: * @see org.jpox.store.mapping.JavaTypeMapping#setObject(org.jpox.ObjectManager,
073: * java.lang.Object, int[], java.lang.Object)
074: */
075: public void setObject(ObjectManager om, Object preparedStatement,
076: int[] exprIndex, Object value) {
077: Point2D.Double pt = (Point2D.Double) value;
078: if (pt == null) {
079: getDataStoreMapping(0).setObject(preparedStatement,
080: exprIndex[0], null);
081: getDataStoreMapping(1).setObject(preparedStatement,
082: exprIndex[1], null);
083: } else {
084: getDataStoreMapping(0).setDouble(preparedStatement,
085: exprIndex[0], pt.getX());
086: getDataStoreMapping(1).setDouble(preparedStatement,
087: exprIndex[1], pt.getY());
088: }
089: }
090:
091: /*
092: * (non-Javadoc)
093: * @see org.jpox.store.mapping.JavaTypeMapping#getObject(org.jpox.ObjectManager,
094: * java.lang.Object, int[])
095: */
096: public Object getObject(ObjectManager om, Object resultSet,
097: int[] exprIndex) {
098: // Check for null entries
099: if (getDataStoreMapping(0).getObject(resultSet, exprIndex[0]) == null) {
100: return null;
101: }
102:
103: double x = getDataStoreMapping(0).getDouble(resultSet,
104: exprIndex[0]);
105: double y = getDataStoreMapping(1).getDouble(resultSet,
106: exprIndex[1]);
107: return new Point2D.Double(x, y);
108: }
109:
110: // -------------------------------- JDOQL Query Methods -----------------------------------------
111:
112: /*
113: * (non-Javadoc)
114: * @see org.jpox.store.mapping.JavaTypeMapping#newLiteral(org.jpox.store.query.QueryStatement,
115: * java.lang.Object)
116: */
117: public ScalarExpression newLiteral(QueryExpression qs, Object value) {
118: return null;
119: }
120:
121: /*
122: * (non-Javadoc)
123: * @see org.jpox.store.mapping.JavaTypeMapping#newScalarExpression(org.jpox.store.query.QueryStatement,
124: * org.jpox.store.expression.TableExpression)
125: */
126: public ScalarExpression newScalarExpression(QueryExpression qs,
127: LogicSetExpression te) {
128: return null;
129: }
130: }
|