/* (non-Javadoc)
   * @see org.datanucleus.store.fieldmanager.AbstractFieldManager#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)) {
        // TODO Cater for null value detection

        List<AbstractMemberMetaData> embMmds = new ArrayList<AbstractMemberMetaData>(mmds);
        embMmds.add(mmd);

        AbstractClassMetaData embCmd =
            ec.getMetaDataManager().getMetaDataForClass(mmd.getType(), clr);
        ObjectProvider embOP =
            ec.getNucleusContext()
                .getObjectProviderFactory()
                .newForEmbedded(ec, embCmd, op, fieldNumber);
        FieldManager ffm = new FetchEmbeddedFieldManager(embOP, result, embMmds, table);
        embOP.replaceFields(embCmd.getAllMemberPositions(), ffm);
        return embOP.getObject();
      }
    }

    return fetchNonEmbeddedObjectField(mmd, relationType, clr);
  }
 private static void addColumnsToScanForEmbeddedMember(
     Scan scan, List<AbstractMemberMetaData> embMmds, Table table, ExecutionContext ec) {
   AbstractMemberMetaData lastMmd = embMmds.get(embMmds.size() - 1);
   ClassLoaderResolver clr = ec.getClassLoaderResolver();
   AbstractClassMetaData embCmd =
       ec.getMetaDataManager().getMetaDataForClass(lastMmd.getTypeName(), clr);
   int[] embMmdPosns = embCmd.getAllMemberPositions();
   for (int i = 0; i < embMmdPosns.length; i++) {
     AbstractMemberMetaData embMmd = embCmd.getMetaDataForManagedMemberAtAbsolutePosition(i);
     List<AbstractMemberMetaData> subEmbMmds = new ArrayList<AbstractMemberMetaData>(embMmds);
     subEmbMmds.add(embMmd);
     RelationType relationType = embMmd.getRelationType(clr);
     MemberColumnMapping mapping = table.getMemberColumnMappingForEmbeddedMember(subEmbMmds);
     if (RelationType.isRelationSingleValued(relationType)) {
       addColumnsToScanForEmbeddedMember(scan, subEmbMmds, table, ec);
     } else {
       String familyName = HBaseUtils.getFamilyNameForColumn(mapping.getColumn(0));
       String qualifName = HBaseUtils.getQualifierNameForColumn(mapping.getColumn(0));
       scan.addColumn(familyName.getBytes(), qualifName.getBytes());
     }
   }
 }
 public boolean useBackedSCOWrapperForMember(AbstractMemberMetaData mmd, ExecutionContext ec) {
   // Use backed SCO wrapper on relation field (to support legacy), and use simple SCO wrapper on
   // others
   return (mmd.getRelationType(ec.getClassLoaderResolver()) == RelationType.NONE ? false : true);
 }