Package org.jpox.store.mapped.mapping

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

/**********************************************************************
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.geom.RoundRectangle2D;

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.geom.RoundRectangle2D.Double, maps the x, y, width, height,
* arc-width and arc-height values to double-precision datastore fields.
*
* @version $Revision: 1.20 $
*/
public class RoundRectangle2dDoubleMapping extends SingleFieldMultiMapping
{

    private static final RoundRectangle2D.Double sampleValue = new RoundRectangle2D.Double(0, 0, 1, 1, 1, 1);

  /* (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.DOUBLE); // X
        addDatastoreField(ClassNameConstants.DOUBLE); // Y
        addDatastoreField(ClassNameConstants.DOUBLE); // Width
        addDatastoreField(ClassNameConstants.DOUBLE); // Height
        addDatastoreField(ClassNameConstants.DOUBLE); // Arc-Width
        addDatastoreField(ClassNameConstants.DOUBLE); // Arc-Height
    }

    /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
     */
    public Class getJavaType()
    {
        return RoundRectangle2D.Double.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)
    {
      RoundRectangle2D roundRectangle = (RoundRectangle2D)value;
        if (roundRectangle == null)
        {
        for (int i = 0; i < exprIndex.length; i++)
        {
          getDataStoreMapping(i).setObject(preparedStatement, exprIndex[i], null);         
      }
        }
        else
        {
            getDataStoreMapping(0).setDouble(preparedStatement,exprIndex[0],roundRectangle.getX());
            getDataStoreMapping(1).setDouble(preparedStatement,exprIndex[1],roundRectangle.getY());
            getDataStoreMapping(2).setDouble(preparedStatement,exprIndex[2],roundRectangle.getWidth());
            getDataStoreMapping(3).setDouble(preparedStatement,exprIndex[3],roundRectangle.getHeight());
            getDataStoreMapping(4).setDouble(preparedStatement,exprIndex[4],roundRectangle.getArcWidth());
            getDataStoreMapping(5).setDouble(preparedStatement,exprIndex[5],roundRectangle.getArcHeight());
        }
    }
   
    /* (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;
        }

        double x = getDataStoreMapping(0).getDouble(resultSet,exprIndex[0]);
        double y = getDataStoreMapping(1).getDouble(resultSet,exprIndex[1]);
        double width  = getDataStoreMapping(2).getDouble(resultSet,exprIndex[2]);
        double height = getDataStoreMapping(3).getDouble(resultSet,exprIndex[3]);
        double arcwidth  = getDataStoreMapping(4).getDouble(resultSet,exprIndex[4]);
        double archeight = getDataStoreMapping(5).getDouble(resultSet,exprIndex[5]);
        return new RoundRectangle2D.Double(x, y, width, height, arcwidth, archeight);
    }

    // --------------------------------- 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.RoundRectangle2dDoubleMapping

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.