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()); } } }
protected static Object getObjectUsingNondurableIdForResult( final Result result, final AbstractClassMetaData cmd, final ExecutionContext ec, boolean ignoreCache, final int[] fpMembers, String tableName, StoreManager storeMgr, Table table) { if (cmd.hasDiscriminatorStrategy()) { // Check the class for this discriminator value String familyName = HBaseUtils.getFamilyNameForColumn(table.getDiscriminatorColumn()); String columnName = HBaseUtils.getQualifierNameForColumn(table.getDiscriminatorColumn()); Object discValue = new String(result.getValue(familyName.getBytes(), columnName.getBytes())); if (cmd.getDiscriminatorStrategy() == DiscriminatorStrategy.CLASS_NAME && !cmd.getFullClassName().equals(discValue)) { return null; } else if (cmd.getDiscriminatorStrategy() == DiscriminatorStrategy.VALUE_MAP && !cmd.getDiscriminatorValue().equals(discValue)) { return null; } } final FieldManager fm = new FetchFieldManager(ec, cmd, result, table); SCOID id = new SCOID(cmd.getFullClassName()); Object pc = ec.findObject( id, new FieldValues() { // ObjectProvider calls the fetchFields method public void fetchFields(ObjectProvider op) { op.replaceFields(fpMembers, fm); } public void fetchNonLoadedFields(ObjectProvider op) { op.replaceNonLoadedFields(fpMembers, fm); } public FetchPlan getFetchPlanForLoading() { return null; } }, null, ignoreCache, false); if (cmd.isVersioned()) { // Set the version on the object ObjectProvider op = ec.findObjectProvider(pc); Object version = null; VersionMetaData vermd = cmd.getVersionMetaDataForClass(); if (vermd.getFieldName() != null) { // Set the version from the field value AbstractMemberMetaData verMmd = cmd.getMetaDataForMember(vermd.getFieldName()); version = op.provideField(verMmd.getAbsoluteFieldNumber()); } else { // Get the surrogate version from the datastore version = HBaseUtils.getSurrogateVersionForObject(cmd, result, tableName, storeMgr); } op.setVersion(version); } if (result.getRow() != null) { ObjectProvider sm = ec.findObjectProvider(pc); sm.setAssociatedValue("HBASE_ROW_KEY", result.getRow()); } return pc; }
protected static Object getObjectUsingDatastoreIdForResult( final Result result, final AbstractClassMetaData cmd, final ExecutionContext ec, boolean ignoreCache, final int[] fpMembers, String tableName, StoreManager storeMgr, Table table) { if (cmd.hasDiscriminatorStrategy()) { // Check the class for this discriminator value String familyName = HBaseUtils.getFamilyNameForColumn(table.getDiscriminatorColumn()); String columnName = HBaseUtils.getQualifierNameForColumn(table.getDiscriminatorColumn()); Object discValue = new String(result.getValue(familyName.getBytes(), columnName.getBytes())); if (cmd.getDiscriminatorStrategy() == DiscriminatorStrategy.CLASS_NAME && !cmd.getFullClassName().equals(discValue)) { return null; } else if (cmd.getDiscriminatorStrategy() == DiscriminatorStrategy.VALUE_MAP && !cmd.getDiscriminatorValue().equals(discValue)) { return null; } } String dsidFamilyName = HBaseUtils.getFamilyNameForColumn(table.getDatastoreIdColumn()); String dsidColumnName = HBaseUtils.getQualifierNameForColumn(table.getDatastoreIdColumn()); Object id = null; try { byte[] bytes = result.getValue(dsidFamilyName.getBytes(), dsidColumnName.getBytes()); if (bytes != null) { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); Object key = ois.readObject(); id = ec.getNucleusContext().getIdentityManager().getDatastoreId(cmd.getFullClassName(), key); ois.close(); bis.close(); } else { throw new NucleusException( "Retrieved identity for family=" + dsidFamilyName + " column=" + dsidColumnName + " IS NULL"); } } catch (Exception e) { throw new NucleusException(e.getMessage(), e); } final FieldManager fm = new FetchFieldManager(ec, cmd, result, table); Object pc = ec.findObject( id, new FieldValues() { // ObjectProvider calls the fetchFields method public void fetchFields(ObjectProvider op) { op.replaceFields(fpMembers, fm); } public void fetchNonLoadedFields(ObjectProvider op) { op.replaceNonLoadedFields(fpMembers, fm); } public FetchPlan getFetchPlanForLoading() { return null; } }, null, ignoreCache, false); if (cmd.isVersioned()) { // Set the version on the object ObjectProvider op = ec.findObjectProvider(pc); Object version = null; VersionMetaData vermd = cmd.getVersionMetaDataForClass(); if (vermd.getFieldName() != null) { // Set the version from the field value AbstractMemberMetaData verMmd = cmd.getMetaDataForMember(vermd.getFieldName()); version = op.provideField(verMmd.getAbsoluteFieldNumber()); } else { // Get the surrogate version from the datastore version = HBaseUtils.getSurrogateVersionForObject(cmd, result, tableName, storeMgr); } op.setVersion(version); } if (result.getRow() != null) { ObjectProvider sm = ec.findObjectProvider(pc); sm.setAssociatedValue("HBASE_ROW_KEY", result.getRow()); } return pc; }