org.datanucleus.api.jdo.metadata.ValueMetadataImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datanucleus-api-jdo Show documentation
Show all versions of datanucleus-api-jdo Show documentation
Plugin providing DataNucleus implementation of the JDO API.
/**********************************************************************
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.jdo.metadata;
import javax.jdo.AttributeConverter;
import javax.jdo.annotations.ForeignKeyAction;
import javax.jdo.metadata.ColumnMetadata;
import javax.jdo.metadata.EmbeddedMetadata;
import javax.jdo.metadata.ForeignKeyMetadata;
import javax.jdo.metadata.IndexMetadata;
import javax.jdo.metadata.UniqueMetadata;
import javax.jdo.metadata.ValueMetadata;
import org.datanucleus.api.jdo.JDOTypeConverter;
import org.datanucleus.api.jdo.JDOTypeConverterUtils;
import org.datanucleus.metadata.AbstractMemberMetaData;
import org.datanucleus.metadata.ColumnMetaData;
import org.datanucleus.metadata.EmbeddedMetaData;
import org.datanucleus.metadata.ForeignKeyMetaData;
import org.datanucleus.metadata.IndexMetaData;
import org.datanucleus.metadata.MetaData;
import org.datanucleus.metadata.UniqueMetaData;
import org.datanucleus.metadata.ValueMetaData;
import org.datanucleus.store.types.TypeManager;
/**
* Implementation of JDO ValueMetadata object.
*/
public class ValueMetadataImpl extends AbstractMetadataImpl implements ValueMetadata
{
public ValueMetadataImpl(ValueMetaData internal)
{
super(internal);
}
public ValueMetaData getInternal()
{
return (ValueMetaData)internalMD;
}
/* (non-Javadoc)
* @see javax.jdo.metadata.ValueMetadata#getColumn()
*/
public String getColumn()
{
return getInternal().getColumnName();
}
/* (non-Javadoc)
* @see javax.jdo.metadata.KeyMetadata#getColumns()
*/
public ColumnMetadata[] getColumns()
{
ColumnMetaData[] internalColmds = getInternal().getColumnMetaData();
if (internalColmds == null)
{
return null;
}
ColumnMetadataImpl[] colmds = new ColumnMetadataImpl[internalColmds.length];
for (int i=0;i getConverter()
{
ValueMetaData valmd = getInternal();
if (valmd.hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME))
{
String typeConverterName = valmd.getValueForExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME);
if (typeConverterName != null)
{
JDOTypeConverter typeConv = (JDOTypeConverter)getInternal().getMetaDataManager().getNucleusContext().getTypeManager().getTypeConverterForName(typeConverterName);
return typeConv.getAttributeConverter();
}
}
return null;
}
/* (non-Javadoc)
* @see javax.jdo.metadata.ValueMetadata#setConverter(javax.jdo.AttributeConverter)
*/
@Override
public ValueMetadata setConverter(AttributeConverter, ?> conv)
{
String valType = ((AbstractMemberMetaData)getInternal().getParent()).getMap().getKeyType();
Class valCls = getInternal().getMetaDataManager().getNucleusContext().getClassLoaderResolver(null).classForName(valType);
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(conv.getClass(), valCls);
Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(conv.getClass(), attrType, null);
// Register the TypeConverter under the name of the AttributeConverter class
JDOTypeConverter typeConv = new JDOTypeConverter(conv);
TypeManager typeMgr = getInternal().getMetaDataManager().getNucleusContext().getTypeManager();
typeMgr.registerConverter(conv.getClass().getName(), typeConv, attrType, dbType, false, null);
getInternal().addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME, conv.getClass().getName());
return this;
}
/* (non-Javadoc)
* @see javax.jdo.metadata.ValueMetadata#getUseDefaultConversion()
*/
@Override
public Boolean getUseDefaultConversion()
{
if (getInternal().hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_DISABLED))
{
String val = getInternal().getValueForExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_DISABLED);
return Boolean.valueOf(val);
}
else if (getInternal().hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME))
{
return false;
}
return true;
}
/* (non-Javadoc)
* @see javax.jdo.metadata.ValueMetadata#setUseDefaultConversion(Boolean)
*/
@Override
public ValueMetadata setUseDefaultConversion(Boolean flag)
{
if (flag)
{
getInternal().addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_DISABLED, "true");
}
else
{
getInternal().removeExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_DISABLED);
}
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy