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.Polygon;
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.Polygon, maps the points to int-precision datastore fields.
033: *
034: * @version $Revision: 1.20 $
035: */
036: public class PolygonMapping extends SingleFieldMultiMapping {
037:
038: private static final Polygon sampleValue = new Polygon();
039:
040: /* (non-Javadoc)
041: * @see org.jpox.store.mapping.JavaTypeMapping#initialize()
042: */
043: public void initialize(DatastoreAdapter dba,
044: AbstractMemberMetaData fmd,
045: DatastoreContainerObject container, ClassLoaderResolver clr) {
046: super .initialize(dba, fmd, container, clr);
047:
048: // String typeName = ClassNameConstants.INT_ARRAY;
049: // ArrayMapping arrayMapping = new ArrayMapping();
050: // arrayMapping.initialize(dba, fmd, container, clr);
051: //
052: // MappingManager mgr = dba.getMappingManager();
053: // DatastoreField column = mgr.createDatastoreField(arrayMapping, typeName, getNumberOfDatastoreFields());
054: // DatastoreMapping datastoreMapping = mgr.createDatastoreMapping(arrayMapping, datastoreContainer.getStoreManager(), column, typeName);
055:
056: addDatastoreField(ClassNameConstants.INT_ARRAY); // X-Points
057: addDatastoreField(ClassNameConstants.INT_ARRAY); // Y-Points
058: addDatastoreField(ClassNameConstants.INT); // Npoints
059: }
060:
061: /* (non-Javadoc)
062: * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
063: */
064: public Class getJavaType() {
065: return Polygon.class;
066: }
067:
068: /* (non-Javadoc)
069: * @see org.jpox.store.mapping.JavaTypeMapping#getSampleValue()
070: */
071: public Object getSampleValue(ClassLoaderResolver clr) {
072: return sampleValue;
073: }
074:
075: /* (non-Javadoc)
076: * @see org.jpox.store.mapping.JavaTypeMapping#setObject(org.jpox.ObjectManager, java.lang.Object, int[], java.lang.Object)
077: */
078: public void setObject(ObjectManager om, Object preparedStatement,
079: int[] exprIndex, Object value) {
080: Polygon poly = (Polygon) value;
081: if (poly == null) {
082: getDataStoreMapping(0).setObject(preparedStatement,
083: exprIndex[0], null);
084: getDataStoreMapping(1).setObject(preparedStatement,
085: exprIndex[1], null);
086: getDataStoreMapping(2).setObject(preparedStatement,
087: exprIndex[2], null);
088: } else {
089: getDataStoreMapping(0).setObject(preparedStatement,
090: exprIndex[0], poly.xpoints);
091: getDataStoreMapping(1).setObject(preparedStatement,
092: exprIndex[1], poly.ypoints);
093: getDataStoreMapping(2).setInt(preparedStatement,
094: exprIndex[2], poly.npoints);
095: }
096: }
097:
098: /* (non-Javadoc)
099: * @see org.jpox.store.mapping.JavaTypeMapping#getObject(org.jpox.ObjectManager, java.lang.Object, int[])
100: */
101: public Object getObject(ObjectManager om, Object resultSet,
102: int[] exprIndex) {
103: // Check for null entries
104: if (getDataStoreMapping(0).getObject(resultSet, exprIndex[0]) == null) {
105: return null;
106: }
107:
108: int[] xpoints = (int[]) getDataStoreMapping(0).getObject(
109: resultSet, exprIndex[0]);
110: int[] ypoints = (int[]) getDataStoreMapping(1).getObject(
111: resultSet, exprIndex[1]);
112: int npoints = getDataStoreMapping(2).getInt(resultSet,
113: exprIndex[2]);
114: return new Polygon(xpoints, ypoints, npoints);
115: }
116:
117: // --------------------------------- JDOQL Query Methods -------------------------------------------
118:
119: /* (non-Javadoc)
120: * @see org.jpox.store.mapping.JavaTypeMapping#newLiteral(org.jpox.store.query.QueryStatement, java.lang.Object)
121: */
122: public ScalarExpression newLiteral(QueryExpression qs, Object value) {
123: return null;
124: }
125:
126: /* (non-Javadoc)
127: * @see org.jpox.store.mapping.JavaTypeMapping#newScalarExpression(org.jpox.store.query.QueryStatement, org.jpox.store.expression.TableExpression)
128: */
129: public ScalarExpression newScalarExpression(QueryExpression qs,
130: LogicSetExpression te) {
131: return null;
132: }
133: }
|