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: Contributors:
016: ...
017: **********************************************************************/package org.jpox.store.mapping;
018:
019: import java.awt.geom.Ellipse2D;
020:
021: import org.jpox.ClassLoaderResolver;
022: import org.jpox.ClassNameConstants;
023: import org.jpox.ObjectManager;
024: import org.jpox.metadata.AbstractMemberMetaData;
025: import org.jpox.store.DatastoreAdapter;
026: import org.jpox.store.DatastoreContainerObject;
027: import org.jpox.store.expression.LogicSetExpression;
028: import org.jpox.store.expression.QueryExpression;
029: import org.jpox.store.expression.ScalarExpression;
030:
031: /**
032: * Mapping for java.awt.geom.Ellipse2D.Double, maps the x, y, width and height values to double-precision datastore fields.
033: *
034: * @version $Revision: 1.20 $
035: */
036: public class Ellipse2dDoubleMapping extends SingleFieldMultiMapping {
037:
038: private static final Ellipse2D.Double sampleValue = new Ellipse2D.Double(
039: 0, 0, 1, 1);
040:
041: /* (non-Javadoc)
042: * @see org.jpox.store.mapping.JavaTypeMapping#initialize()
043: */
044: public void initialize(DatastoreAdapter dba,
045: AbstractMemberMetaData fmd,
046: DatastoreContainerObject container, ClassLoaderResolver clr) {
047: super .initialize(dba, fmd, container, clr);
048:
049: addDatastoreField(ClassNameConstants.DOUBLE); // X
050: addDatastoreField(ClassNameConstants.DOUBLE); // Y
051: addDatastoreField(ClassNameConstants.DOUBLE); // Width
052: addDatastoreField(ClassNameConstants.DOUBLE); // Height
053: }
054:
055: /* (non-Javadoc)
056: * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
057: */
058: public Class getJavaType() {
059: return Ellipse2D.Double.class;
060: }
061:
062: /* (non-Javadoc)
063: * @see org.jpox.store.mapping.JavaTypeMapping#getSampleValue()
064: */
065: public Object getSampleValue(ClassLoaderResolver clr) {
066: return sampleValue;
067: }
068:
069: /* (non-Javadoc)
070: * @see org.jpox.store.mapping.JavaTypeMapping#setObject(org.jpox.ObjectManager, java.lang.Object, int[], java.lang.Object)
071: */
072: public void setObject(ObjectManager om, Object preparedStatement,
073: int[] exprIndex, Object value) {
074: Ellipse2D ellipse = (Ellipse2D) value;
075: if (ellipse == null) {
076: for (int i = 0; i < exprIndex.length; i++) {
077: getDataStoreMapping(i).setObject(preparedStatement,
078: exprIndex[i], null);
079: }
080: } else {
081: getDataStoreMapping(0).setDouble(preparedStatement,
082: exprIndex[0], ellipse.getX());
083: getDataStoreMapping(1).setDouble(preparedStatement,
084: exprIndex[1], ellipse.getY());
085: getDataStoreMapping(2).setDouble(preparedStatement,
086: exprIndex[2], ellipse.getWidth());
087: getDataStoreMapping(3).setDouble(preparedStatement,
088: exprIndex[3], ellipse.getHeight());
089: }
090: }
091:
092: /* (non-Javadoc)
093: * @see org.jpox.store.mapping.JavaTypeMapping#getObject(org.jpox.ObjectManager, java.lang.Object, int[])
094: */
095: public Object getObject(ObjectManager om, Object resultSet,
096: int[] exprIndex) {
097: // Check for null entries
098: if (getDataStoreMapping(0).getObject(resultSet, exprIndex[0]) == null) {
099: return null;
100: }
101:
102: double x = getDataStoreMapping(0).getDouble(resultSet,
103: exprIndex[0]);
104: double y = getDataStoreMapping(1).getDouble(resultSet,
105: exprIndex[1]);
106: double width = getDataStoreMapping(2).getDouble(resultSet,
107: exprIndex[2]);
108: double height = getDataStoreMapping(3).getDouble(resultSet,
109: exprIndex[3]);
110: return new Ellipse2D.Double(x, y, width, height);
111: }
112:
113: // --------------------------------- JDOQL Query Methods -------------------------------------------
114:
115: /* (non-Javadoc)
116: * @see org.jpox.store.mapping.JavaTypeMapping#newLiteral(org.jpox.store.query.QueryStatement, java.lang.Object)
117: */
118: public ScalarExpression newLiteral(QueryExpression qs, Object value) {
119: return null;
120: }
121:
122: /* (non-Javadoc)
123: * @see org.jpox.store.mapping.JavaTypeMapping#newScalarExpression(org.jpox.store.query.QueryStatement, org.jpox.store.expression.TableExpression)
124: */
125: public ScalarExpression newScalarExpression(QueryExpression qs,
126: LogicSetExpression te) {
127: return null;
128: }
129: }
|