/** * Named differently so you don't accidentally use the Object form * @return the metadata for a kind of typed object. * @throws IllegalArgumentException if the kind has not been registered */ @SuppressWarnings("unchecked") public <T> EntityMetadata<T> getMetadataForEntity(final T obj) throws IllegalArgumentException { // Type erasure sucks return (EntityMetadata<T>)this.getMetadata(obj.getClass()); }
/** */ @Override public Integer getExpirySeconds(Key key) { final EntityMetadata<?> meta = fact.getMetadata(key.getKind()); return meta == null ? null : meta.getCacheExpirySeconds(); } }
@Override public FullEntity<?> toEntity(final Object pojo) { if (pojo instanceof FullEntity<?>) { return (FullEntity<?>)pojo; } else { @SuppressWarnings("unchecked") final EntityMetadata<Object> meta = (EntityMetadata<Object>)ofy.factory().getMetadata(pojo.getClass()); return meta.save(pojo, new SaveContext()); } }
/** * Converts a datastore entity into a typed pojo object * @return an assembled pojo, or the Entity itself if the kind is not registered, or null if the input value was null */ @SuppressWarnings("unchecked") public <T> T load(final BaseEntity<com.google.cloud.datastore.Key> ent, final LoadContext ctx) { if (ent == null) return null; final EntityMetadata<T> meta = ofy.factory().getMetadata(ent.getKey().getKind()); if (meta == null) return (T)ent; else return meta.load(ent, ctx); } }
/** * @return true if we should hybridize this query */ private boolean shouldHybridize() { if (hybrid != null) return hybrid; // If the class is cacheable if (classRestriction != null && loader.getObjectifyImpl().getOptions().isCache() && fact().getMetadata(classRestriction).getCacheExpirySeconds() != null) return true; return false; }
/** * Named differently so you don't accidentally use the Object form * @return the metadata for a kind of typed object. * @throws IllegalArgumentException if the kind has not been registered */ @SuppressWarnings("unchecked") public <T> EntityMetadata<T> getMetadataForEntity(T obj) { // Type erasure sucks ass return (EntityMetadata<T>)this.getMetadata(obj.getClass()); }
/** * @return the metadata for a kind of entity based on its key * @throws IllegalArgumentException if the kind has not been registered */ public <T> EntityMetadata<T> getMetadata(Key<T> key) { return this.getMetadata(key.getKind()); }
/** */ @Override public Integer getExpirySeconds(Key key) { return fact.getMetadata(key).getCacheExpirySeconds(); } }
/** * @return the metadata for a kind of entity based on its key * @throws IllegalArgumentException if the kind has not been registered */ public <T> EntityMetadata<T> getMetadata(com.google.appengine.api.datastore.Key key) { return this.getMetadata(key.getKind()); }
@Override protected Map<Key<T>, T> wrap(Map<com.google.appengine.api.datastore.Key, Entity> orig) throws Exception { Map<Key<T>, T> result = new LinkedHashMap<Key<T>, T>(orig.size() * 2); // We preserve the order of the original keys for (com.google.appengine.api.datastore.Key rawKey: rawKeys) { Entity entity = orig.get(rawKey); if (entity != null) { EntityMetadata<T> metadata = factory.getMetadata(rawKey); result.put(new Key<T>(rawKey), (T)metadata.toObject(entity, sync())); } } return result; } };
@Override public Query<T> order(String condition) { condition = condition.trim(); SortDirection dir = SortDirection.ASCENDING; if (condition.startsWith("-")) { dir = SortDirection.DESCENDING; condition = condition.substring(1).trim(); } // Check for @Id field if (this.classRestriction != null) { EntityMetadata<?> meta = this.factory.getMetadata(this.classRestriction); if (meta.isIdField(condition) || meta.isNameField(condition)) condition = "__key__"; } this.actual.addSort(condition, dir); return this; }
protected Field idField(Class<E> entityType) { try { String idFieldName = ObjectifyService.factory().getMetadata(entityType).getKeyMetadata().getIdFieldName(); return FieldUtils.getField(entityType, idFieldName, true); } catch (IllegalArgumentException | SecurityException e) { throw new RepositoryException(e, "Unable to determine id field for type %s: %s", entityType.getClass().getName(), e.getMessage()); } }
EntityMetadata<?> meta = this.factory.getMetadata(this.classRestriction); if (meta.isIdField(prop) || meta.isNameField(prop))