Package org.jpox.store.mapped.mapping

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

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

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.Line2D.Double, maps the x1, y1, x2 and y2 values to double-precision datastore fields.
*
* @version $Revision: 1.20 $
*/
public class Line2dDoubleMapping extends SingleFieldMultiMapping
{

    private static final Line2D.Double sampleValue = new Line2D.Double(0, 0, 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); // X1
        addDatastoreField(ClassNameConstants.DOUBLE); // Y1
        addDatastoreField(ClassNameConstants.DOUBLE); // X2
        addDatastoreField(ClassNameConstants.DOUBLE); // Y2
    }

    /* (non-Javadoc)
     * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
     */
    public Class getJavaType()
    {
        return Line2D.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)
    {
      Line2D line = (Line2D)value;
        if (line == null)
        {
        for (int i = 0; i < exprIndex.length; i++)
        {
          getDataStoreMapping(i).setObject(preparedStatement, exprIndex[i], null);         
      }
        }
        else
        {
            getDataStoreMapping(0).setDouble(preparedStatement,exprIndex[0],line.getX1());
            getDataStoreMapping(1).setDouble(preparedStatement,exprIndex[1],line.getY1());
            getDataStoreMapping(2).setDouble(preparedStatement,exprIndex[2],line.getX2());
            getDataStoreMapping(3).setDouble(preparedStatement,exprIndex[3],line.getY2());
        }
    }
   
    /* (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 x1 = getDataStoreMapping(0).getDouble(resultSet,exprIndex[0]);
        double y1 = getDataStoreMapping(1).getDouble(resultSet,exprIndex[1]);
        double x2 = getDataStoreMapping(2).getDouble(resultSet,exprIndex[2]);
        double y2 = getDataStoreMapping(3).getDouble(resultSet,exprIndex[3]);
        return new Line2D.Double(x1, y1, x2, y2);
    }

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

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.