Package org.jpox.store.mapped.mapping

Source Code of org.jpox.store.mapped.mapping.PolygonMapping

/**********************************************************************
Copyright (c) 2007 Thomas Marti and others. All rights reserved.
Licensed 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.

Contributors:
    ...
**********************************************************************/
package org.jpox.store.mapped.mapping;

import java.awt.Polygon;

import org.jpox.ClassLoaderResolver;
import org.jpox.ClassNameConstants;
import org.jpox.ObjectManager;
import org.jpox.metadata.AbstractMemberMetaData;
import org.jpox.store.mapped.DatastoreAdapter;
import org.jpox.store.mapped.DatastoreContainerObject;
import org.jpox.store.mapped.expression.LogicSetExpression;
import org.jpox.store.mapped.expression.QueryExpression;
import org.jpox.store.mapped.expression.ScalarExpression;

/**
* Mapping for java.awt.Polygon, maps the points to int-precision datastore fields.
*
* @version $Revision: 1.20 $
*/
public class PolygonMapping extends SingleFieldMultiMapping
{

    private static final Polygon sampleValue = new Polygon();

  /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#initialize()
     */
    public void initialize(DatastoreAdapter dba, AbstractMemberMetaData fmd, DatastoreContainerObject container, ClassLoaderResolver clr)
    {
    super.initialize(dba, fmd, container, clr);

//    String typeName = ClassNameConstants.INT_ARRAY;
//    ArrayMapping arrayMapping = new ArrayMapping();
//    arrayMapping.initialize(dba, fmd, container, clr);
//   
//        MappingManager mgr = dba.getMappingManager();
//        DatastoreField column = mgr.createDatastoreField(arrayMapping, typeName, getNumberOfDatastoreFields());
//        DatastoreMapping datastoreMapping =  mgr.createDatastoreMapping(arrayMapping, datastoreContainer.getStoreManager(), column, typeName);

    addDatastoreField(ClassNameConstants.INT_ARRAY); // X-Points
        addDatastoreField(ClassNameConstants.INT_ARRAY); // Y-Points
        addDatastoreField(ClassNameConstants.INT); // Npoints
    }

    /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
     */
    public Class getJavaType()
    {
        return Polygon.class;
    }

    /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#getSampleValue()
     */
    public Object getSampleValue(ClassLoaderResolver clr)
    {
        return sampleValue;
    }
   
    /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#setObject(org.jpox.ObjectManager, java.lang.Object, int[], java.lang.Object)
     */
    public void setObject(ObjectManager om, Object preparedStatement, int[] exprIndex, Object value)
    {
      Polygon poly = (Polygon)value;
        if (poly == null)
        {
            getDataStoreMapping(0).setObject(preparedStatement, exprIndex[0], null);
            getDataStoreMapping(1).setObject(preparedStatement, exprIndex[1], null);
            getDataStoreMapping(2).setObject(preparedStatement, exprIndex[2], null);
        }
        else
        {
            getDataStoreMapping(0).setObject(preparedStatement,exprIndex[0],poly.xpoints);
            getDataStoreMapping(1).setObject(preparedStatement,exprIndex[1],poly.ypoints);
            getDataStoreMapping(2).setInt(preparedStatement,exprIndex[2],poly.npoints);
        }
    }
   
    /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#getObject(org.jpox.ObjectManager, java.lang.Object, int[])
     */
    public Object getObject(ObjectManager om, Object resultSet, int[] exprIndex)
    {
        // Check for null entries
        if (getDataStoreMapping(0).getObject(resultSet, exprIndex[0]) == null)
        {
            return null;
        }

        int[] xpoints = (int[])getDataStoreMapping(0).getObject(resultSet,exprIndex[0]);
        int[] ypoints = (int[])getDataStoreMapping(1).getObject(resultSet,exprIndex[1]);
        int npoints = getDataStoreMapping(2).getInt(resultSet,exprIndex[2]);
        return new Polygon(xpoints, ypoints, npoints);
    }

    // --------------------------------- JDOQL Query Methods -------------------------------------------

    /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#newLiteral(org.jpox.store.query.QueryStatement, java.lang.Object)
     */
    public ScalarExpression newLiteral(QueryExpression qs, Object value)
    {
        return null;
    }

    /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#newScalarExpression(org.jpox.store.query.QueryStatement, org.jpox.store.expression.TableExpression)
     */
    public ScalarExpression newScalarExpression(QueryExpression qs, LogicSetExpression te)
    {
        return null;
    }
}
TOP

Related Classes of org.jpox.store.mapped.mapping.PolygonMapping

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.