Package org.datanucleus

Examples of org.datanucleus.ObjectManager


          + "provide a reference to its parent but the entity does not have a parent.  "
          + "Did you perhaps try to establish an instance of " + childClass  +  " as "
          + "the child of an instance of " + ammd.getTypeName() + " after the child had already been "
          + "persisted?");
    }
    ObjectManager om = getStateManager().getObjectManager();
    return mapping.getObject(om, parentKey, NOT_USED);
  }
View Full Code Here


    ObjectManager om = getStateManager().getObjectManager();
    return mapping.getObject(om, parentKey, NOT_USED);
  }

  private Object lookupOneToOneChild(AbstractMemberMetaData ammd, ClassLoaderResolver clr) {
    ObjectManager om = getStateManager().getObjectManager();
    AbstractClassMetaData childClassMetaData =
        om.getMetaDataManager().getMetaDataForClass(ammd.getType(), clr);
    String kind = getStoreManager().getIdentifierFactory().newDatastoreContainerIdentifier(
        childClassMetaData).getIdentifierName();
    Entity parentEntity = fieldManager.getEntity();
    // We're going to issue a query for all entities of the given kind with
    // the parent entity's key as their parent.  There should be only 1.
    Query q = new Query(kind, parentEntity.getKey());
    DatastoreService datastoreService = DatastoreServiceFactoryInternal.getDatastoreService();
    // We have to pull back all children because the datastore does not let us
    // filter ancestors by depth and an indirect child could come back before a
    // direct child.  eg:
    // a/b/c
    // a/c
    for (Entity e : datastoreService.prepare(q).asIterable()) {
      if (parentEntity.getKey().equals(e.getKey().getParent())) {
        // TODO(maxr) Figure out how to hook this up to a StateManager!
        return DatastoreQuery.entityToPojo(e, childClassMetaData, clr, om, false, om.getFetchPlan());
        // We are potentially ignoring data errors where there is more than one
        // direct child for the one to one.  Unfortunately, in order to detect
        // this we need to read all the way to the end of the Iterable and that
        // might pull back a lot more data than is really necessary.
      }
View Full Code Here

  private void put(List<PutState> putStateList) {
    if (putStateList.isEmpty()) {
      return;
    }
    DatastoreTransaction txn = null;
    ObjectManager om = null;
    List<Entity> entityList = Utils.newArrayList();
    for (PutState putState : putStateList) {
      if (txn == null) {
        txn = EntityUtils.getCurrentTransaction(putState.sm.getObjectManager());
      }
View Full Code Here

    DatastoreService service = DatastoreServiceFactoryInternal.getDatastoreService();
    AbstractClassMetaData acmd = ecs.getEmd();
    String kind =
        storeMgr.getIdentifierFactory().newDatastoreContainerIdentifier(acmd).getIdentifierName();
    Query q = new Query(kind);
    ObjectManager om = ownerSM.getObjectManager();
    Object id = om.getApiAdapter().getTargetKeyForSingleFieldIdentity(
        ownerSM.getInternalObjectId());
    Key key = id instanceof Key ? (Key) id : KeyFactory.stringToKey((String) id);
    q.setAncestor(key);
    // create an entity just to capture the name of the index property
    Entity entity = new Entity(kind);
View Full Code Here

        assertEquals(userInfoResult.getUserId(), userInfo.getUserId());
        assertEquals(userInfoResult.getUserName(), userInfo.getUserName());
    }
   
    protected ForceManagedConnection getManagedConnection(EntityManager em) {
        ObjectManager om = (ObjectManager) em.getDelegate();
       
        ConnectionFactory connFactory = om.getStoreManager().getConnectionManager().lookupConnectionFactory("force");
        return (ForceManagedConnection) connFactory.createManagedConnection(null, null);
    }
View Full Code Here

            EntityManagerFactory emf = Persistence.createEntityManagerFactory("CodeGenTest");
            em = emf.createEntityManager();
        }
       
        if (conn == null) {
            ObjectManager om = (ObjectManager) em.getDelegate();
           
            // Get the EntityManager's PartnerConnection
            ConnectionFactory connFactory = om.getStoreManager().getConnectionManager().lookupConnectionFactory("force");
            ForceManagedConnection mconn = (ForceManagedConnection) connFactory.createManagedConnection(null, null);
            conn = (PartnerConnection) mconn.getConnection();
        }
    }
View Full Code Here

        em.find(generatedClass, "deadbeef");
    }

    @Test(dataProvider = "queryableClassProvider")
    public void testGeneratedClassQueryCommonFields(Class generatedClass) {
        ObjectManager om = (ObjectManager) em.getDelegate();
        AbstractClassMetaData acmd = om.getMetaDataManager().getMetaDataForClass(generatedClass, null);
       
        StringBuffer selectCommonFields = new StringBuffer("o.id");
        if (acmd.hasMember("name")) selectCommonFields.append(", o.name"); // Not every entity has a name field
       
        // We don't care about the results, just that we can execute a query without error
View Full Code Here

    public void deleteObject(ObjectProvider op) {
        // Check if read-only so update not permitted
        storeManager.assertReadOnlyForUpdateOfObject(op);

        ForceManagedConnection mconn = (ForceManagedConnection) storeManager.getConnection(op.getExecutionContext());
        ObjectManager om = ((ObjectProviderImpl) op).getStateManager().getObjectManager();
        boolean isAllOrNothingMode = om instanceof ForceObjectManagerImpl && ((ForceObjectManagerImpl) om).isInAllOrNothingMode();
        try {
            Object pkValue = op.provideField(op.getClassMetaData().getPKMemberPositions()[0]);
            if (!isAllOrNothingMode) {
                if (LOGGER.isDebugEnabled()) {
View Full Code Here

            /**
             * It is possible that this field is just a parent whose children have been updated only. In that case
             * the current object will not be dirty and we have nothing else to do.
             */
            if (!fm.isDirty()) return;
            ObjectManager om = ((ObjectProviderImpl) op).getStateManager().getObjectManager();
            boolean isAllOrNothingMode =
                om instanceof ForceObjectManagerImpl && ((ForceObjectManagerImpl) om).isInAllOrNothingMode();
            SObject toSave;
            if (!isAllOrNothingMode) {
                PartnerConnection connection = getPartnerConnection(mconn, op);
View Full Code Here

        assertNotNull(entity.getForceOwner(), "Force.com Owner field was not found");
        assertNotNull(entity.getForceOwner().getId(), "Force.com Owner id was not found");
        assertNotNull(entity.getForceOwner().getName(), "Force.com Owner name was not found");
       
        // Assert that the Force.com Owner is in the cache
        ObjectManager om = (ObjectManager) em.getDelegate();
        assertNotNull(om.getObjectFromCache(new StringIdentity(ForceOwner.class, entity.getForceOwner().getId())));
        tx.commit();
       
        // Force.com Owner is eagerly fetched on AccountCustomFields so
        // it should be available outside of the find transaction
        assertNotNull(entity.getForceOwner(), "Force.com Owner field did not get eagerly fetched");
View Full Code Here

TOP

Related Classes of org.datanucleus.ObjectManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.