当前位置: 首页>>代码示例>>Java>>正文


Java Work类代码示例

本文整理汇总了Java中com.googlecode.objectify.Work的典型用法代码示例。如果您正苦于以下问题:Java Work类的具体用法?Java Work怎么用?Java Work使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Work类属于com.googlecode.objectify包,在下文中一共展示了Work类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTransact_datastoreTimeoutException_noManifest_retries

import com.googlecode.objectify.Work; //导入依赖的package包/类
@Test
public void testTransact_datastoreTimeoutException_noManifest_retries() {
  assertThat(ofy().transact(new Work<Integer>() {

    int count = 0;

    @Override
    public Integer run() {
      // We don't write anything in this transaction, so there is no commit log manifest.
      // Therefore it's always safe to retry since nothing got written.
      count++;
      if (count == 3) {
        return count;
      }
      throw new DatastoreTimeoutException("");
    }})).isEqualTo(3);
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:OfyTest.java

示例2: testTransact_datastoreTimeoutException_manifestNotWrittenToDatastore_retries

import com.googlecode.objectify.Work; //导入依赖的package包/类
@Test
public void testTransact_datastoreTimeoutException_manifestNotWrittenToDatastore_retries() {
  assertThat(ofy().transact(new Work<Integer>() {

    int count = 0;

    @Override
    public Integer run() {
      // There will be something in the manifest now, but it won't be committed if we throw.
      ofy().save().entity(someObject);
      count++;
      if (count == 3) {
        return count;
      }
      throw new DatastoreTimeoutException("");
    }})).isEqualTo(3);
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:OfyTest.java

示例3: createUser

import com.googlecode.objectify.Work; //导入依赖的package包/类
@Override
public AppUser createUser(final AppUser appUser) {

	/* BCrypt Password */
	String hashed = BCrypt.hashpw(appUser.getPassword(), BCrypt.gensalt());
	appUser.setPassword(hashed);

	AppUser appUserNew = ofy().transact(new Work<AppUser>() {
		public AppUser run() {
			Key<AppUser> appUserNewKey = ofy().save().entity(appUser).now();
			return ofy().load().key(appUserNewKey).now();
		}
	});

	return appUserNew;
}
 
开发者ID:geekmj,项目名称:google-cloud-endpoints-examples,代码行数:17,代码来源:UserServiceImpl.java

示例4: transact

import com.googlecode.objectify.Work; //导入依赖的package包/类
public Object transact(final ProceedingJoinPoint joinPoint) throws Throwable {

        try {
            return ofy().transactNew(new Work<Object>() {
                @Override
                public Object run() {
                    try {
                        return joinPoint.proceed();
                    } catch (Throwable throwable) {
                        throw new ExceptionWrapper(throwable);
                    }
                }
            });
        } catch (ExceptionWrapper e) {
            throw e.getCause();
        } catch (Throwable ex) {
            throw new RuntimeException("Unexpected exception during transaction management", ex);
        }
    }
 
开发者ID:dajudge,项目名称:appengine-objectify-spring-transactions-example,代码行数:20,代码来源:AppEngineTransactionManager.java

示例5: renameFile

import com.googlecode.objectify.Work; //导入依赖的package包/类
@Override
public void renameFile(final String source, final String dest) throws IOException {
	ofy().execute(TxnType.REQUIRES_NEW, new Work<Void>() {
		@Override
		public Void run() {
			Segment sourceSegment = ofy().load().key(newSegmentKey(source)).now();
			
			Segment destSegment = copySegment(sourceSegment);
			destSegment.name = dest;
			Key<Segment> destSegmentKey = ofy().save().entity(destSegment).now();
			
			final long hunkCount = sourceSegment.hunkCount;
			for (int i = 0; i < hunkCount; i++) {
				SegmentHunk hunk = sourceSegment.getHunk(i);
				SegmentHunk destHunk = copySegmentHunk(hunk);
				destHunk.segment = destSegmentKey;
				ofy().save().entity(destHunk);
			}
			deleteFile(source);
			return null;
		}
	});
}
 
开发者ID:UltimaPhoenix,项目名称:luceneappengine,代码行数:24,代码来源:GaeDirectory.java

示例6: join

import com.googlecode.objectify.Work; //导入依赖的package包/类
@Override
public void join(final long tableId, final Side side) {
	ofy().transact(new Work<Table>() {
		@Override
		public Table run() {
			Table table = getTable(tableId);
			Player player = new Player(table, getUser(), side);
			player.channelToken = notify.openChannel(table, side);
			TableSearch ts = ofy().transactionless().load().type(TableSearch.class).id(table.id).get();
			ts.join(player, table.game.getSides().length);
			ofy().save().entities(player);
			ofy().transactionless().save().entities(ts);
			return table;
		}
	});
}
 
开发者ID:rzymek,项目名称:obsolete-web-boards-gwt,代码行数:17,代码来源:ServerEngineImpl.java

示例7: create

import com.googlecode.objectify.Work; //导入依赖的package包/类
public static Long create(final String user, final String sideName) {
	return ofy().transact(new Work<Long>() {
		@Override
		public Long run() {
			BastogneSide side = BastogneSide.valueOf(sideName);
			Table table = new Table();
			table.game = new Bastogne();
			table.scenario = new BattleForLongvilly();
			ofy().save().entity(table).now();

			Player player = new Player(table, user, side);
			player.channelToken = notify.openChannel(table, side);
			TableSearch ts = new TableSearch(table);
			ts.join(player, table.game.getSides().length);
			ofy().save().entities(player);
			ofy().transactionless().save().entities(ts);
			return table.id;
		}
	});
}
 
开发者ID:rzymek,项目名称:obsolete-web-boards-gwt,代码行数:21,代码来源:ServerEngineImpl.java

示例8: updateDeviceInfo

import com.googlecode.objectify.Work; //导入依赖的package包/类
/**
 * This method is used for updating a entity. It uses HTTP PUT method.
 * 
 * @param deviceinfo the entity to be updated.
 * @return The updated entity.
 */
@ApiMethod(name = "devices.update", httpMethod = HttpMethod.PUT, path = "devices")
public DeviceInfo updateDeviceInfo(DeviceInfo deviceInfo) {
    
    final DeviceInfo queryDevice = DbHelper.findDeviceInfoByKey(Long.parseLong(deviceInfo.getServerRegistrationId()));

    if (null == queryDevice) {
        return null;
    }

    queryDevice.setDeviceRegistrationId(deviceInfo.getDeviceRegistrationId());

    Boolean transactionResult = ofy().transact(new Work<Boolean>() {
        @Override
        public Boolean run() {
            ofy().save().entity(queryDevice).now();
            return true;
        }
    });

    return queryDevice;
}
 
开发者ID:lolletsoc,项目名称:dissertation-project,代码行数:28,代码来源:DeviceInfoEndpoint.java

示例9: removeDeviceInfo

import com.googlecode.objectify.Work; //导入依赖的package包/类
/**
 * This method removes the entity with primary key id. It uses HTTP DELETE
 * method.
 * 
 * @param id the primary key of the entity to be deleted.
 * @return The deleted entity.
 */
@ApiMethod(name = "devices.delete", httpMethod = HttpMethod.DELETE, path = "devices/{id}")
public DeviceInfo removeDeviceInfo(@Named("id") String id) {

    final DeviceInfo queryDevice = DbHelper.findDeviceInfoByKey(Long.parseLong(id));

    if (null == queryDevice) {
        return null;
    }

    Boolean transactionResult = ofy().transact(new Work<Boolean>() {
        @Override
        public Boolean run() {
            ofy().delete().entity(queryDevice).now();
            return true;
        }
    });

    return queryDevice;
}
 
开发者ID:lolletsoc,项目名称:dissertation-project,代码行数:27,代码来源:DeviceInfoEndpoint.java

示例10: increment

import com.googlecode.objectify.Work; //导入依赖的package包/类
/**
 * Overidden so that all calls to {@link #increment} occur inside of an existing Transaction.
 *
 * @param counterName
 * @param requestedIncrementAmount
 * @return
 */
@Override
public CounterOperation increment(final String counterName, final long requestedIncrementAmount)
{
	return ObjectifyService.ofy().transact(new Work<CounterOperation>()
	{
		@Override
		public CounterOperation run()
		{
			// 1.) Create a random CounterShardData for simulation purposes. It doesn't do anything except
			// to allow us to do something else in the Datastore in the same transactional context whilst
			// performing all unit tests. This effectively allows us to simulate a parent transactional context
			// occuring with some other data operation being performed against the database.
			final CounterShardData counterShardData = new CounterShardData(UUID.randomUUID().toString(), 1);
			ObjectifyService.ofy().save().entity(counterShardData);

			// 2.) Operate on the counter and return.
			return ShardedCounterServiceTxWrapper.super.increment(counterName, requestedIncrementAmount);
		}
	});
}
 
开发者ID:instacount,项目名称:appengine-counter,代码行数:28,代码来源:ShardedCounterServiceShardIncrementInExistingTXTest.java

示例11: getIdType

import com.googlecode.objectify.Work; //导入依赖的package包/类
@Override
public Class<ID> getIdType() {
    return ObjectifyService.run(new Work<Class<ID>>(){
        @Override
        public Class<ID> run() {
            EntityMetadata<T> entityMetadata = ofy().factory().getMetadata(getJavaType());
            KeyMetadata<T> keyMetadata = entityMetadata.getKeyMetadata();
            
            return (Class<ID>)keyMetadata.getIdFieldType();
        }
    });
}
 
开发者ID:nhuttrung,项目名称:spring-data-objectify,代码行数:13,代码来源:ObjectifyEntityInformation.java

示例12: purge

import com.googlecode.objectify.Work; //导入依赖的package包/类
@ApiMethod(name = "purge", path = "purge", httpMethod = ApiMethod.HttpMethod.DELETE)
public void purge(final User user, HttpServletRequest request) throws OAuthRequestException, IOException {
    final String userId = authenticate(user, request);

    ofy().transact(new Work<Void>() {
        public Void run() {
            SauceUser sauceUser = registerOrGetUser(userId, user.getEmail());
            ofy().delete().keys(ofy().load().ancestor(sauceUser.getKey()).keys().list());
            return null;
        }
    });
}
 
开发者ID:saucenet,项目名称:sync,代码行数:13,代码来源:SauceSyncEndpoint.java

示例13: doTransactionless

import com.googlecode.objectify.Work; //导入依赖的package包/类
/** Execute some work in a transactionless context. */
public <R> R doTransactionless(Work<R> work) {
  try {
    com.googlecode.objectify.ObjectifyService.push(
        com.googlecode.objectify.ObjectifyService.ofy().transactionless());
    return work.run();
  } finally {
    com.googlecode.objectify.ObjectifyService.pop();
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:11,代码来源:Ofy.java

示例14: doWithFreshSessionCache

import com.googlecode.objectify.Work; //导入依赖的package包/类
/**
 * Execute some work with a fresh session cache.
 *
 * <p>This is useful in cases where we want to load the latest possible data from Datastore but
 * don't need point-in-time consistency across loads and consequently don't need a transaction.
 * Note that unlike a transaction's fresh session cache, the contents of this cache will be
 * discarded once the work completes, rather than being propagated into the enclosing session.
 */
public <R> R doWithFreshSessionCache(Work<R> work) {
  try {
    com.googlecode.objectify.ObjectifyService.push(
        com.googlecode.objectify.ObjectifyService.factory().begin());
    return work.run();
  } finally {
    com.googlecode.objectify.ObjectifyService.pop();
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:Ofy.java

示例15: update

import com.googlecode.objectify.Work; //导入依赖的package包/类
Map<String, Object> update(final Map<String, ?> args, final Registrar registrar) {
  final String clientId = sessionUtils.getRegistrarClientId(request);
  return ofy()
      .transact(
          (Work<Map<String, Object>>)
              () -> {
                ImmutableSet<RegistrarContact> oldContacts = registrar.getContacts();
                Map<String, Object> existingRegistrarMap =
                    expandRegistrarWithContacts(oldContacts, registrar);
                Registrar.Builder builder = registrar.asBuilder();
                ImmutableSet<RegistrarContact> updatedContacts =
                    changeRegistrarFields(registrar, builder, args);
                if (!updatedContacts.isEmpty()) {
                  builder.setContactsRequireSyncing(true);
                }
                Registrar updatedRegistrar = builder.build();
                ofy().save().entity(updatedRegistrar);
                if (!updatedContacts.isEmpty()) {
                  checkContactRequirements(oldContacts, updatedContacts);
                  RegistrarContact.updateContacts(updatedRegistrar, updatedContacts);
                }
                // Update the registrar map with updated contacts to bypass Objectify caching
                // issues that come into play with calling getContacts().
                Map<String, Object> updatedRegistrarMap =
                    expandRegistrarWithContacts(updatedContacts, updatedRegistrar);
                sendExternalUpdatesIfNecessary(
                    updatedRegistrar.getRegistrarName(),
                    existingRegistrarMap,
                    updatedRegistrarMap);
                return JsonResponseHelper.create(
                    SUCCESS, "Saved " + clientId, updatedRegistrar.toJsonMap());
              });
}
 
开发者ID:google,项目名称:nomulus,代码行数:34,代码来源:RegistrarSettingsAction.java


注:本文中的com.googlecode.objectify.Work类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。