public String getEntityName() { return classMetadata.getEntityName(); }
public String getIdProperty() { return classMetadata.getIdProperty(); }
public Metadata get(Class<?> rootEntityClass, String propertyPath) throws IllegalArgumentException { Metadata md = get(rootEntityClass); if (propertyPath == null || propertyPath.equals("")) { return md; } else { for (String prop : propertyPath.split("\\.")) { if ("id".equals(prop)) { md = md.getIdType(); } else { md = md.getPropertyType(prop); } if (md == null) throw new IllegalArgumentException("Property path '" + propertyPath + "' invalid for type " + rootEntityClass.getName()); } return md; } }
private void getFilterFromExampleRecursive(Object example, Metadata metadata, ExampleOptions options, LinkedList<String> path, List<Filter> filters) { if (metadata.isEntity() && !metadata.getIdType().isEmbeddable()) { Object id = metadata.getIdValue(example); if (id != null) { filters.add(Filter.equal(listToPath(path, "id"), id)); for (String property : metadata.getProperties()) { if (options.getExcludeProps() != null && options.getExcludeProps().size() != 0) { if (options.getExcludeProps().contains(listToPath(path, property))) Metadata pMetadata = metadata.getPropertyType(property); if (pMetadata.isCollection()) { Object value = metadata.getPropertyValue(example, property); if (value == null) { if (!options.isExcludeNulls()) { if (pMetadata.isEntity() || pMetadata.isEmbeddable()) { path.add(property); getFilterFromExampleRecursive(value, pMetadata, options, path, filters); path.removeLast(); } else if (pMetadata.isString() && (options.getLikeMode() != ExampleOptions.EXACT || options.isIgnoreCase())) { String val = value.toString();
public boolean isId(Class<?> rootClass, String propertyPath) { if (propertyPath == null || "".equals(propertyPath)) return false; // with hibernate, "id" always refers to the id property, no matter what // that property is named. just make sure the segment before this "id" // refers to an entity since only entities have ids. if (propertyPath.equals("id") || (propertyPath.endsWith(".id") && get(rootClass, propertyPath.substring(0, propertyPath.length() - 3)) .isEntity())) return true; // see if the property is the identifier property of the entity it // belongs to. int pos = propertyPath.lastIndexOf("."); if (pos != -1) { Metadata parentType = get(rootClass, propertyPath.substring(0, pos)); if (!parentType.isEntity()) return false; return propertyPath.substring(pos + 1).equals(parentType.getIdProperty()); } else { return propertyPath.equals(get(rootClass).getIdProperty()); } }
} else if (!first && metadataUtil.get(ctx.rootClass, currentPath).isEntity()) { && metadataUtil.get(ctx.rootClass, currentPath.substring(0, pos)).isCollection()) { first = true;
case Filter.OP_EMPTY: metadata = metadataUtil.get(ctx.rootClass, property); if (metadata.isCollection()) { return "not exists elements(" + getPathRef(ctx, property) + ")"; } else if (metadata.isString()) { String pathRef = getPathRef(ctx, property); return "(" + pathRef + " is null or " + pathRef + " = '')"; if (metadata.isCollection()) { return "exists elements(" + getPathRef(ctx, property) + ")"; } else if (metadata.isString()) { String pathRef = getPathRef(ctx, property); return "(" + pathRef + " is not null and " + pathRef + " != '')";
public Class<?> getJavaClass() { return classMetadata.getJavaClass(); }
public Serializable getIdValue(Object object) { return classMetadata.getIdValue(object); }
public Metadata getPropertyType(String property) { return classMetadata.getPropertyType(property); }
public Object getPropertyValue(Object object, String property) { return classMetadata.getPropertyValue(object, property); }
public Metadata getIdType() { return classMetadata.getIdType(); }
public String[] getProperties() { return classMetadata.getProperties(); }
public boolean isId(Class<?> rootClass, String propertyPath) { if (propertyPath == null || "".equals(propertyPath)) return false; // with hibernate, "id" always refers to the id property, no matter what // that property is named. just make sure the segment before this "id" // refers to an entity since only entities have ids. if (propertyPath.equals("id") || (propertyPath.endsWith(".id") && get(rootClass, propertyPath.substring(0, propertyPath.length() - 3)) .isEntity())) return true; // see if the property is the identifier property of the entity it // belongs to. int pos = propertyPath.lastIndexOf("."); if (pos != -1) { Metadata parentType = get(rootClass, propertyPath.substring(0, pos)); if (!parentType.isEntity()) return false; return propertyPath.substring(pos + 1).equals(parentType.getIdProperty()); } else { return propertyPath.equals(sessionFactory.getClassMetadata(rootClass).getIdentifierPropertyName()); } }
ctx2.rootClass = metadataUtil.get(ctx.rootClass, property).getJavaClass(); ctx2.setRootAlias(rootAlias + (ctx.nextSubqueryNum++)); ctx2.paramList = ctx.paramList;
public Serializable getId(Object entity) { if (entity == null) throw new NullPointerException("Cannot get ID from null object."); return get(entity.getClass()).getIdValue(entity); }
public Metadata get(Class<?> rootEntityClass, String propertyPath) throws IllegalArgumentException { try { Metadata md = get(rootEntityClass); if (propertyPath == null || "".equals(propertyPath)) return md; String[] chain = propertyPath.split("\\."); for (int i = 0; i < chain.length; i++) { md = md.getPropertyType(chain[i]); } return md; } catch (HibernateException ex) { throw new IllegalArgumentException("Could not find property '" + propertyPath + "' on class " + rootEntityClass + "."); } }
/** * Returns the number of instances of this entity in the datastore. */ protected int _count(Class<?> type) { return ((Number) em().createQuery("select count(_it_) from " + getMetadataUtil().get(type).getEntityName() + " _it_").getSingleResult()).intValue(); }
expectedClass = Integer.class; } else { expectedClass = metadataUtil.get(rootClass, property).getJavaClass();
public Serializable getId(Object object) { Metadata md = get(object.getClass()); return md.getIdValue(object); }