Package org.jpox.store.mapped.mapping

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

/**********************************************************************
Copyright (c) 2006 Erik Bengtson 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 org.jpox.ClassLoaderResolver;
import org.jpox.ClassNameConstants;
import org.jpox.ObjectManager;
import org.jpox.store.mapped.expression.QueryExpression;
import org.jpox.store.mapped.expression.ScalarExpression;
import org.jpox.store.mapped.expression.StringLiteral;
import org.jpox.store.mapped.mapping.StringMapping;

/**
* Mapping for a StringBuffer type.
*
* Note: A java.lang.StringBuffer is a final class and does not allow a
* SCO implementation in order of implementing dirty detecting 
*
* @version $Revision: 1.2 $
**/
public class StringBufferMapping extends StringMapping
{
    protected static StringBuffer mappingSampleValue = new StringBuffer();

    public Object getSampleValue(ClassLoaderResolver clr)
    {
        return mappingSampleValue;
    }

    /**
     * Accessor for the name of the java-type actually used when mapping the particular datastore
     * field. This java-type must have an entry in the datastore mappings.
     * @param index requested datastore field index.
     * @return the name of java-type for the requested datastore field.
     */
    public String getJavaTypeForDatastoreMapping(int index)
    {
        // All of the types extending this class will be using java-type of String for the datastore
        return ClassNameConstants.JAVA_LANG_STRING;
    }

    public ScalarExpression newLiteral(QueryExpression qs, Object value)
    {
        ScalarExpression expr = new StringLiteral(qs, this, ((StringBuffer)value).toString());
        return expr;
    }

    /**
     * Delegates to StringMapping the storage with giving a String
     */
    public void setObject(ObjectManager om, Object preparedStatement, int[] exprIndex, Object value)
    {
        Object v = value;
        if( v != null )
        {
            v = ((StringBuffer)v).toString();
        }
        super.setObject(om, preparedStatement, exprIndex, v);
    }

    /**
     * Delegates to StringMapping the retrieval of a String and constructs
     * a StringBuffer out of it
     */
    public Object getObject(ObjectManager om, Object resultSet, int[] exprIndex)
    {
        if (exprIndex == null)
        {
            return null;
        }
        Object value = getDataStoreMapping(0).getObject(resultSet, exprIndex[0]);
        if( value != null )
        {
            return new StringBuffer(value.toString());
        }
        return null;
    }
   
    public Class getJavaType()
    {
        return StringBuffer.class;
    }
}
TOP

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

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.