org.datanucleus.store.cassandra.fieldmanager.FetchEmbeddedFieldManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datanucleus-cassandra Show documentation
Show all versions of datanucleus-cassandra Show documentation
Plugin providing persistence to Cassandra datastores.
/**********************************************************************
Copyright (c) 2014 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.store.cassandra.fieldmanager;
import java.util.ArrayList;
import java.util.List;
import org.datanucleus.ClassLoaderResolver;
import org.datanucleus.ExecutionContext;
import org.datanucleus.metadata.AbstractClassMetaData;
import org.datanucleus.metadata.AbstractMemberMetaData;
import org.datanucleus.metadata.EmbeddedMetaData;
import org.datanucleus.metadata.MetaDataUtils;
import org.datanucleus.metadata.RelationType;
import org.datanucleus.state.ObjectProvider;
import org.datanucleus.store.fieldmanager.FieldManager;
import org.datanucleus.store.schema.table.MemberColumnMapping;
import org.datanucleus.store.schema.table.Table;
import org.datanucleus.util.NucleusLogger;
import com.datastax.driver.core.Row;
/**
* FieldManager for the retrieval of field values of an embedded PC object.
*/
public class FetchEmbeddedFieldManager extends FetchFieldManager
{
/** Metadata for the embedded member (maybe nested) that this FieldManager represents). */
protected List mmds;
public FetchEmbeddedFieldManager(ObjectProvider op, Row row, List mmds, Table table)
{
super(op, row, table);
this.mmds = mmds;
}
public FetchEmbeddedFieldManager(ExecutionContext ec, Row row, AbstractClassMetaData cmd, List mmds, Table table)
{
super(ec, row, cmd, table);
this.mmds = mmds;
}
protected MemberColumnMapping getColumnMapping(int fieldNumber)
{
List embMmds = new ArrayList(mmds);
embMmds.add(cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber));
return table.getMemberColumnMappingForEmbeddedMember(embMmds);
}
/*
* (non-Javadoc)
* @see org.datanucleus.store.cassandra.fieldmanager.FetchFieldManager#fetchObjectField(int)
*/
@Override
public Object fetchObjectField(int fieldNumber)
{
ClassLoaderResolver clr = ec.getClassLoaderResolver();
AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
RelationType relationType = mmd.getRelationType(clr);
EmbeddedMetaData embmd = mmds.get(0).getEmbeddedMetaData();
if (mmds.size() == 1 && embmd != null && embmd.getOwnerMember() != null && embmd.getOwnerMember().equals(mmd.getName()))
{
// Special case of this being a link back to the owner. TODO Repeat this for nested and their owners
ObjectProvider[] ownerOps = ec.getOwnersForEmbeddedObjectProvider(op);
return (ownerOps != null && ownerOps.length > 0 ? ownerOps[0].getObject() : null);
}
if (relationType != RelationType.NONE && MetaDataUtils.getInstance().isMemberEmbedded(ec.getMetaDataManager(), clr, mmd, relationType, null))
{
// Embedded field
if (RelationType.isRelationSingleValued(relationType))
{
List embMmds = new ArrayList(mmds);
embMmds.add(mmd);
AbstractClassMetaData embCmd = ec.getMetaDataManager().getMetaDataForClass(mmd.getType(), clr);
ObjectProvider embOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, embCmd, op, fieldNumber);
FieldManager fetchEmbFM = new FetchEmbeddedFieldManager(embOP, row, embMmds, table);
embOP.replaceFields(embCmd.getAllMemberPositions(), fetchEmbFM);
return embOP.getObject();
}
else if (RelationType.isRelationMultiValued(relationType))
{
// TODO Embedded Collection
NucleusLogger.PERSISTENCE.debug("Field=" + mmd.getFullFieldName() + " not currently supported (embedded)");
}
return null; // Remove this when we support embedded
}
return fetchNonEmbeddedObjectField(mmd, relationType, clr);
}
}