本文整理汇总了Java中com.googlecode.objectify.Ref类的典型用法代码示例。如果您正苦于以下问题:Java Ref类的具体用法?Java Ref怎么用?Java Ref使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ref类属于com.googlecode.objectify包,在下文中一共展示了Ref类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasFieldWithUserRef
import com.googlecode.objectify.Ref; //导入依赖的package包/类
public static <T> Matcher<T> hasFieldWithUserRef(final String fieldName, final User user) {
return new BaseMatcher<T>() {
@Override
public boolean matches(Object o) {
Ref<User> userRef = TestSupport.getField(o, fieldName);
if (user == null) {
return userRef == null;
} else {
String username = userRef.getKey().getName();
return user.getUsername().equals(username);
}
}
@Override
public void describeTo(Description description) {
description.appendText(String.format("User with username '%s' on field %s", user, fieldName));
}
};
}
示例2: refCollection
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@Test
public void refCollection() throws Exception {
TestStringEntity a = new TestStringEntity("a");
TestStringEntity b = new TestStringEntity("b");
TestStringEntity c = new TestStringEntity("c");
assertThat(Refs.ref(
Arrays.asList(
a, b, null, c
)
)).containsExactly(
Ref.create(a),
Ref.create(b),
null,
Ref.create(c)
);
}
示例3: refKeysCollection
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@Test
public void refKeysCollection() throws Exception {
TestStringEntity a = new TestStringEntity("a");
TestStringEntity b = new TestStringEntity("b");
TestStringEntity c = new TestStringEntity("c");
assertThat(Refs.refKeys(
Arrays.asList(
Key.create(a),
Key.create(b),
null,
Key.create(c)
)
)).containsExactly(
Ref.create(a),
Ref.create(b),
null,
Ref.create(c)
);
}
示例4: refKeysVarargs
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@Test
public void refKeysVarargs() throws Exception {
TestStringEntity a = new TestStringEntity("a");
TestStringEntity b = new TestStringEntity("b");
TestStringEntity c = new TestStringEntity("c");
assertThat(Refs.refKeys(
Key.create(a),
Key.create(b),
null,
Key.create(c)
)).containsExactly(
Ref.create(a),
Ref.create(b),
null,
Ref.create(c)
);
}
示例5: derefCollection
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@Test
public void derefCollection() throws Exception {
TestStringEntity a = new TestStringEntity("a");
TestStringEntity b = new TestStringEntity("b");
TestStringEntity c = new TestStringEntity("c");
save(a, b, c);
assertThat(Refs.deref(
Arrays.asList(
Ref.create(a),
Ref.create(b),
null,
Ref.create(c)
)
)).containsExactly(
a, b, null, c
);
}
示例6: derefVarargs
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@Test
public void derefVarargs() throws Exception {
TestStringEntity a = new TestStringEntity("a");
TestStringEntity b = new TestStringEntity("b");
TestStringEntity c = new TestStringEntity("c");
save(a, b, c);
assertThat(Refs.deref(
Ref.create(a),
Ref.create(b),
null,
Ref.create(c)
)).containsExactly(
a, b, null, c
);
}
示例7: save
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@Override
@Path("save")
@POST
public NoteList save(NoteList list) {
User loggedInUser = AuthFilter.getUser();
if (list.getId() == null) {
// insert
// Add new subscription to go with it
list.setDateCreated(new Date());
list.setOwnerKey(Ref.create(loggedInUser));
Ref<NoteList> listKey = Ref.create(this.put(list));
LOG.info("Added list with id = " + list.getId());
return list;
} else {
// update
return super.save(list);
}
}
示例8: removeMany
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@Override
@Path("deleteMany")
@POST
public int removeMany(List<Long> ids) {
try {
// could eliminate loop with IN query, but same effect
for (long id : ids) {
// TODO delete corresponding items also
Ref<NoteList> listKey = Ref.create(Key.create(clazz, id));
// Delete list itself
this.deleteKey(listKey.key());
}
} catch (RuntimeException e) {
LOG.throwing(this.getClass().getSimpleName(), "execute", e);
throw e;
}
return super.removeMany(ids);
}
示例9: save
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@Override
@Path("save")
@POST
public Note save(Note item) {
// Populate item
// User creator = action.getItemCreator();
User creator = AuthFilter.getUser();
long listId = item.getListId();
Ref<User> creatorKey = Ref.create(creator);
Ref<NoteList> listKey = Ref.create(Key.create(NoteList.class, listId));
item.setOwnerKey(creatorKey);
item.setDateCreated(new Date());
item.setListKey(listKey);
this.put(item);
LOG.info("Saved item = " + item.getId() + "and itemText = " + item.getItemText());
return item;
}
示例10: getFullImage
import com.googlecode.objectify.Ref; //导入依赖的package包/类
@GET
@Path("/image/{id}")
@Produces("image/png")
public Response getFullImage(@PathParam("id") String id) {
Item item = new ItemDao().getItemById(id);
List<Ref<Image>> refs = item.getImageRefs();
if (!refs.isEmpty()) {
Image image = refs.get(0).getValue();
//Image image = ImageDao.getImageById(id);
// uncomment line below to send non-streamed
// return Response.ok(imageData).build();
// uncomment line below to send streamed
return Response.ok(new ByteArrayInputStream(image.getImage().getBytes())).build();
} else {
return Response.status(404).entity("Image not found.").build();
}
}
示例11: removeMany
import com.googlecode.objectify.Ref; //导入依赖的package包/类
public int removeMany(List<Long> ids) {
User user = AuthFilter.getUser();
Ref<User> userRef = Ref.create(user);
// Create List of Keys
List<Key<T>> keys = new ArrayList<Key<T>>();
for (long id : ids) {
keys.add(Key.create(clazz, id));
}
Map<Key<T>, T> items = super.get(keys);
for (T item : items.values()) {
if (!item.getOwnerKey().equals(userRef)) {
throw new NotAuthorizedException("User does not own the object");
}
}
super.deleteKeys(keys);
return keys.size();
}
示例12: createEndorsementList
import com.googlecode.objectify.Ref; //导入依赖的package包/类
private List<Endorsement> createEndorsementList() {
// TODO increase to a more complete test scenario
TechGalleryUser endorsed = new TechGalleryUser();
endorsed.setName("GOKU");
endorsed.setId(1L);
TechGalleryUser endorser = new TechGalleryUser();
endorser.setId(2L);
endorser.setName("FELIPE");
Endorsement endorsement = new Endorsement();
endorsement.setId(3L);
endorsement.setEndorsed(Ref.create(endorsed));
endorsement.setEndorser(Ref.create(endorser));
List<Endorsement> list = new ArrayList<Endorsement>();
list.add(endorsement);
return list;
}
示例13: transformFrom
import com.googlecode.objectify.Ref; //导入依赖的package包/类
/**
* Transform entity from response which is transient into datastore entity which can be persisted.
*
* @param transient entity
* @return entity from datastore
*/
@Override
public Skill transformFrom(SkillResponse arg0) {
Skill product = new Skill();
product.setId(arg0.getId());
product.setValue(arg0.getValue());
if (arg0.getTechnology() != null) {
Key<Technology> techKey = Key.create(Technology.class, arg0.getTechnology());
product.setTechnology(Ref.create(techKey));
} else {
product.setTechnology(null);
}
if (arg0.getUser() != null) {
Key<TechGalleryUser> userKey = Key.create(arg0.getUser());
product.setTechGalleryUser(Ref.create(userKey));
} else {
product.setTechGalleryUser(null);
}
product.setCreationDate(arg0.getCreationDate());
return product;
}
示例14: transformComment
import com.googlecode.objectify.Ref; //导入依赖的package包/类
private void transformComment(UserProfileItem userProfileItem,
UserProfileItemTo userProfileItemTo) {
if (userProfileItem.getComments() != null){
if(userProfileItemTo.getComments()==null){
userProfileItemTo.setComments(new ArrayList<SubItemCommentTo>());
}
SubItemCommentTo commentTo;
for(Ref<TechnologyComment> comm : userProfileItem.getComments()){
commentTo = new SubItemCommentTo();
commentTo.setBody(comm.get().getComment());
commentTo.setTimestamp(comm.get().getTimestamp());
userProfileItemTo.getComments().add(commentTo);
}
}
}
示例15: addNewRecommendation
import com.googlecode.objectify.Ref; //导入依赖的package包/类
/**
* Adds a new recommendation to the datastore, invalidates the previous one.
*
* @param recommendation the recommendation to be added
* @param technology the technology for which the recommendation was made
* @param tgUser the user who made the recommendation
* @return the updated recommendation, with id
*/
private TechnologyRecommendation addNewRecommendation(TechnologyRecommendation recommendation,
TechGalleryUser tgUser) {
recommendation.setActive(true);
recommendation.setRecommender(Ref.create(tgUser));
final TechnologyRecommendation previousRec = technologyRecommendationDAO
.findActiveByRecommenderAndTechnology(tgUser, recommendation.getTechnology().get());
final Technology technology = recommendation.getTechnology().get();
// Inactivate previous recommendation
if (previousRec != null) {
previousRec.setActive(false);
previousRec.setInactivatedDate(new Date());
technologyRecommendationDAO.update(previousRec);
technologyService.removeRecomendationCounter(technology, previousRec.getScore());
}
recommendation.setId(technologyRecommendationDAO.add(recommendation).getId());
technologyService.addRecomendationCounter(technology, recommendation.getScore());
UserProfileServiceImpl.getInstance().handleRecommendationChanges(recommendation);
return recommendation;
}