List of usage examples for javax.persistence.metamodel Attribute getName
String getName();
From source file:com.impetus.kundera.metadata.MetadataUtils.java
public static void onJPAColumnMapping(final EntityType entityType, EntityMetadata entityMetadata) { Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iter = attributes.iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); // jpa column mapping is for non id columns only. if (!entityMetadata.getIdAttribute().equals(attribute)) { entityMetadata.addJPAColumnMapping(((AbstractAttribute) attribute).getJPAColumnName(), attribute.getName()); }/* w w w . j ava 2 s .c o m*/ } entityMetadata.setEntityType(entityType); }
From source file:com.eclecticlogic.pedal.dm.internal.MetamodelUtil.java
/** * @param attribute JPA metamodel attribute. * @param entity Entity to set the value on. * @param value Value to set./*from w w w . java 2 s. c o m*/ */ public static <E extends Serializable, T extends Serializable> void set(Attribute<? super E, T> attribute, E entity, T value) { Member member = attribute.getJavaMember(); if (member instanceof Field) { Field field = (Field) member; field.setAccessible(true); try { field.set(entity, value); } catch (Exception e) { throw new RuntimeException(e); } } else if (member instanceof Method) { PropertyDescriptor pd = BeanUtils.findPropertyForMethod((Method) member); if (pd.getWriteMethod() != null) { pd.getWriteMethod().setAccessible(true); try { pd.getWriteMethod().invoke(entity, value); } catch (Exception e) { throw new RuntimeException(e); } } else { throw new RuntimeException( "No setter for " + attribute.getName() + " in " + entity.getClass().getName()); } } else { throw new RuntimeException("Failed to set " + attribute.getName() + " of type " + member.getClass().getName() + " in entity " + entity.getClass().getName()); } }
From source file:bq.jpa.demo.metadata.service.MetadataService.java
public void doMD() { Metamodel md = em.getMetamodel();//w ww. ja v a 2s . c o m EntityType<Employee> employee = md.entity(Employee.class); for (Attribute<? super Employee, ?> attr : employee.getAttributes()) { System.out.println(attr.getName() + " | " + attr.getJavaType().getName() + " | " + attr.getPersistentAttributeType()); } }
From source file:name.marcelomorales.siqisiqi.openjpa.impl.OrmFinderImpl.java
protected Predicate[] newQBEPredicates(OpenJPACriteriaBuilder cb, Root<T> from, T example, T example2, ComparisonStyle style) {/*w w w . j av a2 s. co m*/ Attribute<?, ?>[] betweens = settings.betweens(from, persistentClass); ArrayList<Predicate> predicates = Lists.newArrayListWithExpectedSize(betweens.length + 1); predicates.add(cb.qbe(from, example, style, betweens)); if (betweens.length > 0) { for (Attribute<?, ?> between : betweens) { String name = between.getName(); Path<Comparable> objectPath = from.get(name); Comparable propertyValue1 = OrmUtils.get(example, name); Comparable propertyValue2 = OrmUtils.get(example2, name); predicates.add(cb.between(objectPath, propertyValue1, propertyValue2)); } } return predicates.toArray(new Predicate[predicates.size()]); }
From source file:com.dbs.sdwt.jpa.JpaUtil.java
public List<String> toNamesList(List<Attribute<?, ?>> attributes) { List<String> ret = newArrayList(); for (Attribute<?, ?> attribute : attributes) { ret.add(attribute.getName()); }//from w ww . j a v a 2s . c o m return ret; }
From source file:com.dbs.sdwt.jpa.JpaUtil.java
public <T, A> SingularAttribute<? super T, A> attribute(ManagedType<? super T> mt, Attribute<? super T, A> attr) { return mt.getSingularAttribute(attr.getName(), attr.getJavaType()); }
From source file:com.dbs.sdwt.jpa.JpaUtil.java
public <T> SingularAttribute<? super T, String> stringAttribute(ManagedType<? super T> mt, Attribute<? super T, ?> attr) { return mt.getSingularAttribute(attr.getName(), String.class); }
From source file:com.dbs.sdwt.jpa.JpaUtil.java
@SuppressWarnings("unchecked") public <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) { Path<?> path = root;/*from ww w. j a va 2s.c o m*/ for (Attribute<?, ?> attribute : attributes) { boolean found = false; if (path instanceof FetchParent) { for (Fetch<E, ?> fetch : ((FetchParent<?, E>) path).getFetches()) { if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) { path = (Join<E, ?>) fetch; found = true; break; } } } if (!found) { if (attribute instanceof PluralAttribute) { path = ((From<?, ?>) path).join(attribute.getName(), JoinType.LEFT); } else { path = path.get(attribute.getName()); } } } return (Path<F>) path; }
From source file:eu.uqasar.service.AbstractService.java
protected Long performDistinctCountWithEqualPredicate(final Attribute<T, ?> attr, Object value) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> query = cb.createQuery(Long.class); Root<T> root = query.from(clazz); query.where(cb.equal(root.get(attr.getName()), value)); query.select(cb.countDistinct(root)); return em.createQuery(query).getSingleResult(); }
From source file:com.impetus.client.rdbms.query.RDBMSEntityReader.java
/** * Checks if is string property./*from w w w. ja v a2s . co m*/ * * @param m * the m * @param fieldName * the field name * @return true, if is string property */ private boolean isStringProperty(EntityType entityType, Attribute attribute) { String discriminatorColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn(); if (attribute.getName().equals(discriminatorColumn)) { return true; } return attribute != null ? ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(String.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Character.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(char.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Date.class) || ((AbstractAttribute) attribute).getBindableJavaType() .isAssignableFrom(java.util.Date.class) : false; }