ClassLoaderResolver getClassLoaderResolver() { return ec.getClassLoaderResolver(); }
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()) == Relation.NONE ? false : true); }
private ClassLoaderResolver getClassLoaderResolver() { return getExecutionContext().getClassLoaderResolver(); }
public static String determineKind(AbstractClassMetaData acmd, ExecutionContext ec) { MappedStoreManager storeMgr = (MappedStoreManager) ec.getStoreManager(); return determineKind(acmd, storeMgr, ec.getClassLoaderResolver()); }
private Object getTransformedValueFromParamValue(Object paramValue, ExecutionContext executionContext) { AbstractClassMetaData acmd = executionContext.getMetaDataManager().getMetaDataForClass(paramValue.getClass(), executionContext.getClassLoaderResolver()); if (acmd != null && paramValue instanceof PersistenceCapable) { return getIdFromObject((PersistenceCapable) paramValue, acmd).toString(); } else if (paramValue instanceof Collection<?>) { return new CollectionParameter((Collection<?>) paramValue); } else { return paramValue; } }
private Object getTransformedValueFromParamValue(Object paramValue, ExecutionContext executionContext) { AbstractClassMetaData acmd = executionContext.getMetaDataManager().getMetaDataForClass(paramValue.getClass(), executionContext.getClassLoaderResolver()); if (acmd != null && paramValue instanceof PersistenceCapable) { return getIdFromObject((PersistenceCapable) paramValue, acmd).toString(); } else if (paramValue instanceof Collection<?>) { return new CollectionParameter((Collection<?>) paramValue); } else { return paramValue; } }
/** * Instantiates a JPQLParser and stores the symbol table from the compilation, or * creates a new one. * * @param ec the current execution context * @param compilation possibly {@code null}, contains components of a query string * @param options JPQL parser options * @param params parameters for the parser */ public JPQLPartialCompiler(ExecutionContext ec, QueryCompilation compilation, Map options, Map params) { parser = new JPQLParser(options, params); this.symbolTable = compilation != null ? compilation.getSymbolTable() : new SymbolTable(ec.getClassLoaderResolver()); }
/** * Instantiates a JPQLParser and stores the symbol table from the compilation, or * creates a new one. * * @param ec the current execution context * @param compilation possibly {@code null}, contains components of a query string * @param options JPQL parser options * @param params parameters for the parser */ public JPQLPartialCompiler(ExecutionContext ec, QueryCompilation compilation, Map options, Map params) { parser = new JPQLParser(options, params); this.symbolTable = compilation != null ? compilation.getSymbolTable() : new SymbolTable(ec.getClassLoaderResolver()); }
@Override public FieldManager getFieldManagerForResultProcessing(ExecutionContext ec, Object resultSet, StatementClassMapping resultMappings, AbstractClassMetaData cmd) { Class<?> cls = ec.getClassLoaderResolver().classForName(cmd.getFullClassName()); Object internalKey = EntityUtils.idToInternalKey(ec, cls, resultSet, true); // Need to provide this to the field manager in the form of the pk // of the type: Key, Long, encoded String, or unencoded String return new KeyOnlyFieldManager(internalKey); }
/** * Method to check if an element is already persistent, or is managed by a different * persistence manager. If not persistent, this will persist it. * @param ec ExecutionContext * @param element The element * @param fieldValues any initial field values to use if persisting the element * @return Whether the element was persisted during this call */ protected boolean validateElementForWriting(ExecutionContext ec, Object element, FieldValues fieldValues) { // Check the element type for this collection if (!storeMgr.getNucleusContext().getMetaDataManager().isPersistentInterface(elementType) && !validateElementType(ec.getClassLoaderResolver(), element)) { throw new ClassCastException(LOCALISER.msg("056033", element.getClass().getName(), ownerMemberMetaData.getFullFieldName(), elementType)); } return SCOUtils.validateObjectForWriting(ec, element, fieldValues); }
/** * Accessor for an Extent for a class. * @param ec execution context * @param c The class requiring the Extent * @param subclasses Whether to include subclasses of 'c' * @return The Extent. */ public Extent getExtent(ExecutionContext ec, Class c, boolean subclasses) { AbstractClassMetaData cmd = getMetaDataManager().getMetaDataForClass(c, ec.getClassLoaderResolver()); if (!cmd.isRequiresExtent()) { throw new NoExtentException(c.getName()); } return new DB4OExtent(this, ec, c, subclasses, cmd); }
/** * Convenience method to return a managed (POJO) object for the provided Entity for the EntityManager. * @param entity The entity * @param em The EntityManager * @param cls The POJO class being represented here * @return The POJO */ public Object getJPAFromEntity(Entity entity, EntityManager em, Class cls) { ExecutionContext ec = ((JPAEntityManager)em).getExecutionContext(); ClassLoaderResolver clr = ec.getClassLoaderResolver(); AbstractClassMetaData cmd = ec.getMetaDataManager().getMetaDataForClass(cls, clr); return EntityUtils.entityToPojo(entity, cmd, clr, ec, false, ec.getFetchPlan()); } }
/** * Convenience method to return a managed (POJO) object for the provided Entity for the PersistenceManager. * @param entity The entity * @param pm The PersistenceManager * @param cls The POJO class being represented here * @return The POJO */ public Object getJDOFromEntity(Entity entity, PersistenceManager pm, Class cls) { ExecutionContext ec = ((JDOPersistenceManager)pm).getExecutionContext(); ClassLoaderResolver clr = ec.getClassLoaderResolver(); AbstractClassMetaData cmd = ec.getMetaDataManager().getMetaDataForClass(cls, clr); return EntityUtils.entityToPojo(entity, cmd, clr, ec, false, ec.getFetchPlan()); } }
@Override public Extent getExtent(ExecutionContext ec, Class c, boolean subclasses) { AbstractClassMetaData cmd = getMetaDataManager().getMetaDataForClass(c, ec.getClassLoaderResolver()); validateMetaDataForClass(cmd); if (!cmd.isRequiresExtent()) { throw new NoExtentException(c.getName()); } if (!getBooleanProperty(GET_EXTENT_CAN_RETURN_SUBCLASSES_PROPERTY, false)) { subclasses = false; } // In order to avoid breaking existing apps I'm hard-coding subclasses to // be false. This breaks spec compliance since the no-arg overload of // PersistenceManager.getExtent() is supposed to return subclasses. return new DefaultCandidateExtent(ec, c, subclasses, cmd); }
public FieldManager getFieldManagerForResultProcessing(ObjectProvider op, Object resultSet, StatementClassMapping resultMappings) { ExecutionContext ec = op.getExecutionContext(); Class<?> cls = ec.getClassLoaderResolver().classForName(op.getClassMetaData().getFullClassName()); Object internalKey = EntityUtils.idToInternalKey(ec, cls, resultSet, true); // Need to provide this to the field manager in the form of the pk // of the type: Key, Long, encoded String, or unencoded String return new KeyOnlyFieldManager(internalKey); }
public void persist(JSONObject obj) { // TODO This is flawed persistence since it doesn't handle value-generation etc that the StateManager provides AbstractClassMetaData acmd = ec.getMetaDataManager().getMetaDataForClass(getType(obj), ec.getClassLoaderResolver()); ctx.getStoreManager().getPersistenceHandler().insertObject(new JsonAPIObjectProvider(ec, acmd, obj)); }
public void deleteObject(JSONObject id) { AbstractClassMetaData acmd = ec.getMetaDataManager().getMetaDataForClass(getType(id), ec.getClassLoaderResolver()); JsonAPIObjectProvider op = new JsonAPIObjectProvider(ec, acmd, id); ctx.getStoreManager().getPersistenceHandler().deleteObject(op); }
@Override public void setSubclasses(boolean subclasses) { // TODO Enable this! // We support only queries that also return subclasses if all subclasses belong to the same kind. if (subclasses) { DatastoreManager storeMgr = (DatastoreManager) ec.getStoreManager(); ClassLoaderResolver clr = ec.getClassLoaderResolver(); AbstractClassMetaData acmd = storeMgr.getMetaDataManager().getMetaDataForClass(getCandidateClass(), clr); if (!MetaDataUtils.isNewOrSuperclassTableInheritanceStrategy(acmd)) { throw new NucleusFatalUserException( "The App Engine datastore only supports queries that return subclass entities with the " + "SINGLE_TABLE interitance mapping strategy."); } } super.setSubclasses(subclasses); } }
public JSONObject findObject(JSONObject id) { AbstractClassMetaData acmd = ec.getMetaDataManager().getMetaDataForClass(getType(id), ec.getClassLoaderResolver()); JsonAPIObjectProvider op = new JsonAPIObjectProvider(ec, acmd, id); ctx.getStoreManager().getPersistenceHandler().fetchObject(op, acmd.getAllMemberPositions()); return (JSONObject) op.getObject(); }
private void updateOneToOneBidirectionalOwnerObjectForField( ObjectProvider op, AbstractMemberMetaData fmd, Entity owningEntity) { MappedStoreManager storeMgr = (MappedStoreManager) op.getExecutionContext().getStoreManager(); ExecutionContext ec = op.getExecutionContext(); ClassLoaderResolver clr = ec.getClassLoaderResolver(); AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr); String fullClassName = ((AbstractClassMetaData) relatedMmds[0].getParent()).getFullClassName(); DatastoreClass refTable = storeMgr.getDatastoreClass(fullClassName, clr); JavaTypeMapping refMapping = refTable.getMemberMapping(fmd.getMappedBy()); if (refMapping.isNullable()) { // Null out the relationship to the object being deleted. refMapping.setObject(ec, owningEntity, new int[1], op.getObject()); // TODO If the object being deleted is this objects parent, do we delete this? // TODO(maxr): Do I need to manually request an update now? } }