/** * Convenience method to get all objects of the candidate type (and optional subclasses) from the * specified connection. * * @param ec Execution Context * @param mconn Managed Connection * @param candidateClass Candidate * @param subclasses Include subclasses? * @param ignoreCache Whether to ignore the cache * @param fetchPlan Fetch Plan * @param filter Optional filter for the candidates * @return List of objects of the candidate type (or subclass) */ static List getObjectsOfCandidateType( final ExecutionContext ec, final HBaseManagedConnection mconn, Class candidateClass, boolean subclasses, boolean ignoreCache, FetchPlan fetchPlan, Filter filter, StoreManager storeMgr) { List<AbstractClassMetaData> cmds = MetaDataUtils.getMetaDataForCandidates(candidateClass, subclasses, ec); if (NucleusLogger.DATASTORE_NATIVE.isDebugEnabled()) { NucleusLogger.DATASTORE_NATIVE.debug( "Retrieving objects for candidate=" + candidateClass.getName() + (subclasses ? " and subclasses" : "") + (filter != null ? (" with filter=" + filter) : "")); } Iterator<AbstractClassMetaData> cmdIter = cmds.iterator(); List results = new ArrayList(); while (cmdIter.hasNext()) { results.addAll( getObjectsOfType(ec, mconn, cmdIter.next(), ignoreCache, fetchPlan, filter, storeMgr)); } return results; }
/** * Accessor for the name of the java-type actually used when mapping the particular datastore * field. This java-type must have an entry in the datastore mappings. * * @param index requested datastore field index. * @return the name of java-type for the requested datastore field. */ public String getJavaTypeForDatastoreMapping(int index) { if (datastoreMappings == null || datastoreMappings.length == 0) { // Not got mappings yet so use column metadata to define ColumnMetaData[] colmds = getColumnMetaDataForMember(mmd, roleForMember); boolean useString = false; if (colmds != null && colmds.length > 0 && colmds[0].getJdbcType() != null) { if (MetaDataUtils.isJdbcTypeString(colmds[0].getJdbcType())) { useString = true; } } return (useString ? ClassNameConstants.JAVA_LANG_STRING : ClassNameConstants.JAVA_SQL_TIME); } else if (datastoreMappings[0].isStringBased()) { // Use String as our java type return ClassNameConstants.JAVA_LANG_STRING; } else { return ClassNameConstants.JAVA_SQL_TIME; } }
/* (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); }