Package org.datanucleus.api.jpa.metamodel

Source Code of org.datanucleus.api.jpa.metamodel.SingularAttributeImpl

/**********************************************************************
Copyright (c) 2009 Andy Jefferson 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.datanucleus.api.jpa.metamodel;

import javax.persistence.metamodel.SingularAttribute;

import org.datanucleus.metadata.AbstractMemberMetaData;
import org.datanucleus.metadata.Relation;
import org.datanucleus.metadata.VersionMetaData;

/**
* Implementation of JPA2 Metamodel "SingularAttribute".
*
* @param <X> The type containing the represented attribute
* @param <T> The type of the represented attribute
*/
public class SingularAttributeImpl<X, T> extends AttributeImpl<X, T> implements SingularAttribute<X, T>
{
    /**
     * Constructor for a single-valued attribute.
     * @param mmd Metadata for the member
     * @param owner The owner type
     */
    public SingularAttributeImpl(AbstractMemberMetaData mmd, ManagedTypeImpl<X> owner)
    {
        super(mmd, owner);
    }

    /* (non-Javadoc)
     * @see javax.persistence.metamodel.SingularAttribute#isId()
     */
    public boolean isId()
    {
        return mmd.isPrimaryKey();
    }

    /* (non-Javadoc)
     * @see javax.persistence.metamodel.SingularAttribute#isOptional()
     */
    public boolean isOptional() // Really wants to know if it is nullable
    {
        return mmd.getColumnMetaData() != null && mmd.getColumnMetaData()[0].isAllowsNull();
    }

    /* (non-Javadoc)
     * @see javax.persistence.metamodel.SingularAttribute#isVersion()
     */
    public boolean isVersion()
    {
        VersionMetaData vermd = mmd.getAbstractClassMetaData().getVersionMetaData();
        if (vermd.getFieldName() != null && vermd.getFieldName().equals(mmd.getName()))
        {
            return true;
        }
        return false;
    }

    /* (non-Javadoc)
     * @see javax.persistence.metamodel.Bindable#getBindableJavaType()
     */
    public Class<T> getBindableJavaType()
    {
        return mmd.getType();
    }

    /* (non-Javadoc)
     * @see javax.persistence.metamodel.Bindable#getBindableType()
     */
    public javax.persistence.metamodel.Bindable.BindableType getBindableType()
    {
        int relationType = mmd.getRelationType(owner.model.clr);
        if (Relation.isRelationSingleValued(relationType))
        {
             return BindableType.ENTITY_TYPE;
        }
        else
        {
            return BindableType.SINGULAR_ATTRIBUTE;
        }
    }
}
TOP

Related Classes of org.datanucleus.api.jpa.metamodel.SingularAttributeImpl

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.