org.datanucleus.api.jdo.metadata.KeyMetadataImpl 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.KeyMetadata;
import javax.jdo.metadata.UniqueMetadata;
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.KeyMetaData;
import org.datanucleus.metadata.MetaData;
import org.datanucleus.metadata.UniqueMetaData;
import org.datanucleus.store.types.TypeManager;
/**
* Implementation of JDO KeyMetadata object.
*/
public class KeyMetadataImpl extends AbstractMetadataImpl implements KeyMetadata
{
public KeyMetadataImpl(KeyMetaData internal)
{
super(internal);
}
public KeyMetaData getInternal()
{
return (KeyMetaData)internalMD;
}
/* (non-Javadoc)
* @see javax.jdo.metadata.KeyMetadata#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()
{
KeyMetaData keymd = getInternal();
if (keymd.hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME))
{
String typeConverterName = keymd.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.KeyMetadata#setConverter(javax.jdo.AttributeConverter)
*/
@Override
public KeyMetadata setConverter(AttributeConverter, ?> conv)
{
String keyType = ((AbstractMemberMetaData)getInternal().getParent()).getMap().getKeyType();
Class keyCls = getInternal().getMetaDataManager().getNucleusContext().getClassLoaderResolver(null).classForName(keyType);
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(conv.getClass(), keyCls);
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.KeyMetadata#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.KeyMetadata#setUseDefaultConversion(boolean)
*/
@Override
public KeyMetadata 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