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.CubicCurve2D;
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.CubicCurve2D.Double, maps the x1, y1, ctrlx1, ctrly1,
033: * ctrlx2, ctrly2, x2 and y2 values to double-precision datastore fields.
034: *
035: * @version $Revision: 1.20 $
036: */
037: public class CubicCurve2dDoubleMapping extends SingleFieldMultiMapping {
038:
039: private static final CubicCurve2D.Double sampleValue = new CubicCurve2D.Double();
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); // X1
050: addDatastoreField(ClassNameConstants.DOUBLE); // Y1
051: addDatastoreField(ClassNameConstants.DOUBLE); // CtrlX1
052: addDatastoreField(ClassNameConstants.DOUBLE); // CtrlY1
053: addDatastoreField(ClassNameConstants.DOUBLE); // CtrlX2
054: addDatastoreField(ClassNameConstants.DOUBLE); // CtrlY2
055: addDatastoreField(ClassNameConstants.DOUBLE); // X2
056: addDatastoreField(ClassNameConstants.DOUBLE); // Y2
057: }
058:
059: /* (non-Javadoc)
060: * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
061: */
062: public Class getJavaType() {
063: return CubicCurve2D.Double.class;
064: }
065:
066: /* (non-Javadoc)
067: * @see org.jpox.store.mapping.JavaTypeMapping#getSampleValue()
068: */
069: public Object getSampleValue(ClassLoaderResolver clr) {
070: return sampleValue;
071: }
072:
073: /* (non-Javadoc)
074: * @see org.jpox.store.mapping.JavaTypeMapping#setObject(org.jpox.ObjectManager, java.lang.Object, int[], java.lang.Object)
075: */
076: public void setObject(ObjectManager om, Object preparedStatement,
077: int[] exprIndex, Object value) {
078: CubicCurve2D.Double cubicCurve = (CubicCurve2D.Double) value;
079: if (cubicCurve == null) {
080: for (int i = 0; i < exprIndex.length; i++) {
081: getDataStoreMapping(i).setObject(preparedStatement,
082: exprIndex[i], null);
083: }
084: } else {
085: getDataStoreMapping(0).setDouble(preparedStatement,
086: exprIndex[0], cubicCurve.getX1());
087: getDataStoreMapping(1).setDouble(preparedStatement,
088: exprIndex[1], cubicCurve.getY1());
089: getDataStoreMapping(2).setDouble(preparedStatement,
090: exprIndex[2], cubicCurve.getCtrlX1());
091: getDataStoreMapping(3).setDouble(preparedStatement,
092: exprIndex[3], cubicCurve.getCtrlY1());
093: getDataStoreMapping(4).setDouble(preparedStatement,
094: exprIndex[4], cubicCurve.getCtrlX2());
095: getDataStoreMapping(5).setDouble(preparedStatement,
096: exprIndex[5], cubicCurve.getCtrlY2());
097: getDataStoreMapping(6).setDouble(preparedStatement,
098: exprIndex[6], cubicCurve.getX2());
099: getDataStoreMapping(7).setDouble(preparedStatement,
100: exprIndex[7], cubicCurve.getY2());
101: }
102: }
103:
104: /* (non-Javadoc)
105: * @see org.jpox.store.mapping.JavaTypeMapping#getObject(org.jpox.ObjectManager, java.lang.Object, int[])
106: */
107: public Object getObject(ObjectManager om, Object resultSet,
108: int[] exprIndex) {
109: // Check for null entries
110: if (getDataStoreMapping(0).getObject(resultSet, exprIndex[0]) == null) {
111: return null;
112: }
113:
114: double x1 = getDataStoreMapping(0).getDouble(resultSet,
115: exprIndex[0]);
116: double y1 = getDataStoreMapping(1).getDouble(resultSet,
117: exprIndex[1]);
118: double ctrlx1 = getDataStoreMapping(2).getDouble(resultSet,
119: exprIndex[2]);
120: double ctrly1 = getDataStoreMapping(3).getDouble(resultSet,
121: exprIndex[3]);
122: double ctrlx2 = getDataStoreMapping(4).getDouble(resultSet,
123: exprIndex[4]);
124: double ctrly2 = getDataStoreMapping(5).getDouble(resultSet,
125: exprIndex[5]);
126: double x2 = getDataStoreMapping(6).getDouble(resultSet,
127: exprIndex[6]);
128: double y2 = getDataStoreMapping(7).getDouble(resultSet,
129: exprIndex[7]);
130: return new CubicCurve2D.Double(x1, y1, ctrlx1, ctrly1, ctrlx2,
131: ctrly2, x2, y2);
132: }
133:
134: // --------------------------------- JDOQL Query Methods -------------------------------------------
135:
136: /* (non-Javadoc)
137: * @see org.jpox.store.mapping.JavaTypeMapping#newLiteral(org.jpox.store.query.QueryStatement, java.lang.Object)
138: */
139: public ScalarExpression newLiteral(QueryExpression qs, Object value) {
140: return null;
141: }
142:
143: /* (non-Javadoc)
144: * @see org.jpox.store.mapping.JavaTypeMapping#newScalarExpression(org.jpox.store.query.QueryStatement, org.jpox.store.expression.TableExpression)
145: */
146: public ScalarExpression newScalarExpression(QueryExpression qs,
147: LogicSetExpression te) {
148: return null;
149: }
150: }
|