Point2dFloatMapping.java :  » Database-ORM » JPOX » org » jpox » store » mapping » Java Open Source

Java Open Source » Database ORM » JPOX 
JPOX » org » jpox » store » mapping » Point2dFloatMapping.java
/**********************************************************************
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.mapping;

import java.awt.geom.Point2D;

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

/**
 * Mapping for java.awt.geom.Point2D.Float, maps the x and y values to float-precision datastore fields.
 * @version $Revision: 1.18 $
 */
public class Point2dFloatMapping extends SingleFieldMultiMapping
{
  
  private static final Point2D.Float sampleValue = new Point2D.Float(0,0);
  
    /*
     * (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);

        addDatastoreField(ClassNameConstants.FLOAT); // X
        addDatastoreField(ClassNameConstants.FLOAT); // Y
    }

    /*
     * (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
     */
    public Class getJavaType()
    {
        return Point2D.Float.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)
    {
        Point2D.Float pt = (Point2D.Float)value;
        if (pt == null)
        {
            getDataStoreMapping(0).setObject(preparedStatement, exprIndex[0], null);
            getDataStoreMapping(1).setObject(preparedStatement, exprIndex[1], null);
        }
        else
        {
            getDataStoreMapping(0).setFloat(preparedStatement, exprIndex[0], pt.x);
            getDataStoreMapping(1).setFloat(preparedStatement, exprIndex[1], pt.y);
        }
    }

    /*
     * (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;
        }

        float x = getDataStoreMapping(0).getFloat(resultSet, exprIndex[0]);
        float y = getDataStoreMapping(1).getFloat(resultSet, exprIndex[1]);
        return new Point2D.Float(x, y);
    }

    // -------------------------------- 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;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.