javax.persistence.metamodel.SingularAttribute Java Examples
The following examples show how to use
javax.persistence.metamodel.SingularAttribute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SingularAttributeJoin.java From lams with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings({ "unchecked" }) public SingularAttributeJoin( CriteriaBuilderImpl criteriaBuilder, Class<X> javaType, PathSource<O> pathSource, SingularAttribute<? super O, ?> joinAttribute, JoinType joinType) { super( criteriaBuilder, javaType, pathSource, joinAttribute, joinType ); if ( Attribute.PersistentAttributeType.EMBEDDED == joinAttribute.getPersistentAttributeType() ) { this.model = (Bindable<X>) joinAttribute; } else { if ( javaType != null ) { this.model = (Bindable<X>) criteriaBuilder.getEntityManagerFactory().getMetamodel().managedType( javaType ); } else { this.model = (Bindable<X>) joinAttribute.getType(); } } }
Example #2
Source File: BuildConfigurationRSQLMapper.java From pnc with Apache License 2.0 | 6 votes |
@Override protected SingularAttribute<BuildConfiguration, ?> toAttribute(String name) { switch (name) { case "id": return BuildConfiguration_.id; case "name": return BuildConfiguration_.name; case "description": return BuildConfiguration_.description; case "buildScript": return BuildConfiguration_.buildScript; case "scmRevision": return BuildConfiguration_.scmRevision; case "creationTime": return BuildConfiguration_.creationTime; case "modificationTime": return BuildConfiguration_.lastModificationTime; case "buildType": return BuildConfiguration_.buildType; default: return null; } }
Example #3
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private <Y> JoinImplementor<X, Y> constructJoin(SingularAttribute<? super X, Y> attribute, JoinType jt) { if ( Type.PersistenceType.BASIC.equals( attribute.getType().getPersistenceType() ) ) { throw new BasicPathUsageException( "Cannot join to attribute of basic type", attribute ); } // TODO : runtime check that the attribute in fact belongs to this From's model/bindable if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } final Class<Y> attributeType = attribute.getBindableJavaType(); return new SingularAttributeJoin<X, Y>( criteriaBuilder(), attributeType, this, attribute, jt ); }
Example #4
Source File: BuildConfigurationRSQLMapper.java From pnc with Apache License 2.0 | 5 votes |
@Override protected SingularAttribute<BuildConfiguration, ? extends GenericEntity<Integer>> toEntity(String name) { switch (name) { case "project": return BuildConfiguration_.project; case "scmRepository": return BuildConfiguration_.repositoryConfiguration; case "environment": return BuildConfiguration_.buildEnvironment; case "productVersion": return BuildConfiguration_.productVersion; default: return null; } }
Example #5
Source File: JpaMetadataProviderImpl.java From rice with Educational Community License v2.0 | 5 votes |
/** * Gets the attribute names for the primary keys from the given entity type. * * @param entityType The entity type of the data object. * @return A list of primary key attribute names. */ protected List<String> getPrimaryKeyAttributeNames(EntityType<?> entityType) { List<String> primaryKeyAttributeNames = new ArrayList<String>(); // JHK: After examining of the metadata structures of EclipseLink, I determined that there // was nothing in those which preserved the order of the original annotations. // We *need* to know the order of PK fields for KNS/KRAD functionality. // So, I'm falling back to checking the annotations and fields on the referenced objects. // Yes, the Javadoc states that the getDeclaredFields() method does not guarantee order, // But, it's the best we have. And, as of Java 6, it is returning them in declaration order. if (entityType.getIdType() instanceof EmbeddableType) { for (Field pkField : entityType.getIdType().getJavaType().getDeclaredFields()) { primaryKeyAttributeNames.add(pkField.getName()); } } else { // First, get the ID attributes from the metadata List<String> unsortedPkFields = new ArrayList<String>(); for (SingularAttribute attr : entityType.getSingularAttributes()) { if (attr.isId()) { unsortedPkFields.add(attr.getName()); } } getPrimaryKeyNamesInOrder(primaryKeyAttributeNames, unsortedPkFields, entityType.getJavaType().getDeclaredFields(), entityType.getJavaType()); } return primaryKeyAttributeNames; }
Example #6
Source File: RepositoryConfigurationRSQLMapper.java From pnc with Apache License 2.0 | 5 votes |
@Override protected SingularAttribute<RepositoryConfiguration, ?> toAttribute(String name) { switch (name) { case "id": return RepositoryConfiguration_.id; case "internalUrl": return RepositoryConfiguration_.internalUrl; case "externalUrl": return RepositoryConfiguration_.externalUrl; case "preBuildSyncEnabled": return RepositoryConfiguration_.preBuildSyncEnabled; default: return null; } }
Example #7
Source File: EntityRepositoryHandler.java From deltaspike with Apache License 2.0 | 5 votes |
private List<Property<Object>> extractProperties(SingularAttribute<E, ?>... attributes) { List<String> names = extractPropertyNames(attributes); List<Property<Object>> properties = PropertyQueries.createQuery(entityClass()) .addCriteria(new NamedPropertyCriteria(names.toArray(new String[]{}))).getResultList(); return properties; }
Example #8
Source File: DefaultLuceneQueryBuilder.java From javaee-lab with Apache License 2.0 | 5 votes |
private List<String> getAllClauses(SearchParameters sp, List<TermSelector> terms, List<SingularAttribute<?, ?>> availableProperties) { List<String> clauses = newArrayList(); for (TermSelector term : terms) { if (term.isNotEmpty()) { String clause = getClause(sp, term.getSelected(), term.getAttribute(), term.isOrMode(), availableProperties); if (isNotBlank(clause)) { clauses.add(clause); } } } return clauses; }
Example #9
Source File: GenericDataContainer.java From cia with Apache License 2.0 | 5 votes |
@Override public final <T, V> T findByQueryProperty(final Class<T> clazz, final SingularAttribute<T, ? extends Object> property, final Class<V> clazz2, final SingularAttribute<V, ? extends Object> property2, final Object value) { return dataProxy.findByQueryProperty(clazz, property, clazz2, property2, value); }
Example #10
Source File: SingularAttributePath.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "unchecked" }) public SingularAttributePath( CriteriaBuilderImpl criteriaBuilder, Class<X> javaType, PathSource pathSource, SingularAttribute<?, X> attribute) { super( criteriaBuilder, javaType, pathSource ); this.attribute = attribute; this.managedType = resolveManagedType( attribute ); }
Example #11
Source File: AbstractGenericDAOImpl.java From cia with Apache License 2.0 | 5 votes |
@Override public final List<T> findListByProperty(final Object[] values, final SingularAttribute<T, ? extends Object>... properties) { final CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(persistentClass); final Root<T> root = criteriaQuery.from(persistentClass); criteriaQuery.select(root); final Object value = values[0]; final SingularAttribute<T, ? extends Object> property = properties[0]; Predicate condition; condition = QueryHelper.equalsIgnoreCaseIfStringPredicate(criteriaBuilder, root, value, property); if (values.length > 1) { for (int i = 1; i < properties.length; i++) { final SingularAttribute<T, ? extends Object> property2 = properties[i]; final Object value2 = values[i]; final Predicate condition2 = QueryHelper.equalsIgnoreCaseIfStringPredicate(criteriaBuilder, root, value2, property2); condition = criteriaBuilder.and(condition, condition2); } } criteriaQuery.where(condition); final TypedQuery<T> typedQuery = getEntityManager().createQuery(criteriaQuery); addCacheHints(typedQuery, "findListByProperty"); return typedQuery.getResultList(); }
Example #12
Source File: EnvironmentRSQLMapper.java From pnc with Apache License 2.0 | 5 votes |
@Override protected SingularAttribute<BuildEnvironment, ? extends GenericEntity<Integer>> toEntity(String name) { switch (name) { default: return null; } }
Example #13
Source File: MetamodelUtil.java From javaee-lab with Apache License 2.0 | 5 votes |
public SingularAttribute<?, ?> toAttribute(String property, Class<?> from) { try { Class<?> metamodelClass = getCachedClass(from); Field field = metamodelClass.getField(property); return (SingularAttribute<?, ?>) field.get(null); } catch (Exception e) { throw new IllegalArgumentException(e); } }
Example #14
Source File: UnmodifiableDao.java From judgels with GNU General Public License v2.0 | 5 votes |
@Deprecated List<M> findSortedByFilters( String orderBy, String orderDir, String filterString, Map<SingularAttribute<? super M, ?>, ?> filterColumnsEq, Map<SingularAttribute<? super M, String>, ? extends Collection<String>> filterColumnsIn, long offset, long limit);
Example #15
Source File: EntitySelector.java From gazpachoquest with GNU General Public License v3.0 | 5 votes |
public EntitySelector(final SingularAttribute<E, TPK> field, final T... values) { this(field); for (T value : values) { Validate.notNull(value); selected.add(value); } }
Example #16
Source File: ProductRSQLMapper.java From pnc with Apache License 2.0 | 5 votes |
@Override protected SingularAttribute<Product, ?> toAttribute(String name) { switch (name) { case "id": return Product_.id; case "name": return Product_.name; case "description": return Product_.description; case "abbreviation": return Product_.abbreviation; default: return null; } }
Example #17
Source File: EntityRepositoryHandler.java From deltaspike with Apache License 2.0 | 5 votes |
private Long executeCountQuery(E example, boolean useLikeOperator, SingularAttribute<E, ?>... attributes) { if (isEmpty(attributes)) { return count(); } List<Property<Object>> properties = extractProperties(attributes); String jpqlQuery = exampleQuery(countQuery(), properties, useLikeOperator); log.log(Level.FINER, "count: Created query {0}", jpqlQuery); TypedQuery<Long> query = entityManager().createQuery(jpqlQuery, Long.class); addParameters(query, example, properties, useLikeOperator); context.applyRestrictions(query); return query.getSingleResult(); }
Example #18
Source File: AbstractGenericDAOImpl.java From cia with Apache License 2.0 | 5 votes |
@Override public final List<T> findListByProperty(final SingularAttribute<T, ? extends Object> property, final Object value) { final CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(getPersistentClass()); final Root<T> root = criteriaQuery.from(getPersistentClass()); criteriaQuery.select(root); final Predicate condition = criteriaBuilder.equal(root.get(property), value); criteriaQuery.where(condition); final TypedQuery<T> typedQuery = getEntityManager().createQuery(criteriaQuery); addCacheHints(typedQuery, "findListByProperty"); return typedQuery.getResultList(); }
Example #19
Source File: ByFullTextUtil.java From javaee-lab with Apache License 2.0 | 5 votes |
private <T extends Identifiable<?>> Predicate onCompositePrimaryKeys(Root<T> root, CriteriaBuilder builder, SearchParameters sp, List<SingularAttribute<?, ?>> properties) { List<? extends T> found = hibernateSearchUtil.find(root.getJavaType(), sp, properties); if (found == null) { return null; } else if (found.isEmpty()) { return builder.disjunction(); } List<Predicate> predicates = newArrayList(); for (T t : found) { predicates.add(byExampleOnEntity(root, t, sp, builder)); } return jpaUtil.concatPredicate(sp, builder, jpaUtil.orPredicate(builder, predicates)); }
Example #20
Source File: JpaUtil.java From javaee-lab with Apache License 2.0 | 5 votes |
public <T> boolean isPk(ManagedType<T> mt, SingularAttribute<? super T, ?> attr) { try { Method m = MethodUtils.getAccessibleMethod(mt.getJavaType(), "get" + WordUtils.capitalize(attr.getName()), (Class<?>) null); if (m != null && m.getAnnotation(Id.class) != null) { return true; } Field field = mt.getJavaType().getField(attr.getName()); return field.getAnnotation(Id.class) != null; } catch (Exception e) { return false; } }
Example #21
Source File: Q.java From zstack with Apache License 2.0 | 4 votes |
public Q gte(SingularAttribute attr, Object val) { q.add(attr, SimpleQuery.Op.GTE, val); return this; }
Example #22
Source File: JPAManagedTypeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public Set<SingularAttribute<? super X, ?>> getSingularAttributes() { return null; }
Example #23
Source File: QueryCriteria.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public <P> Criteria<C, R> like(SingularAttribute<? super C, String> att, String value) { add(new Like<C>(att, value), value); return this; }
Example #24
Source File: SearchParameters.java From gazpachoquest with GNU General Public License v3.0 | 4 votes |
public SearchParameters lower(final SingularAttribute<?, Integer> field, final Integer value) { RangeInteger<?> rangeInteger = RangeInteger.rangeInteger(field); rangeInteger.setTo(value); addRange(rangeInteger); return this; }
Example #25
Source File: SimpleQueryImpl.java From zstack with Apache License 2.0 | 4 votes |
@Override public SimpleQuery<T> add(SingularAttribute attr, Op op, Object... val) { _conditions.add(new Condition(attr, op, val)); return this; }
Example #26
Source File: UpdateQueryImpl.java From zstack with Apache License 2.0 | 4 votes |
@Override public UpdateQuery in(SingularAttribute attr, Collection val) { condAnd(attr, Op.IN, val); return this; }
Example #27
Source File: Q.java From zstack with Apache License 2.0 | 4 votes |
public Q isNull(SingularAttribute attr) { q.add(attr, SimpleQuery.Op.NULL); return this; }
Example #28
Source File: ViewDataDataContainerFactoryImpl.java From cia with Apache License 2.0 | 4 votes |
@Override public <T> List<T> findListByProperty(final Class<T> clazz, final Object[] values, final SingularAttribute<T, ? extends Object>... properties) { return dataViewer.findListByProperty(clazz, values, properties); }
Example #29
Source File: QueryCriteria.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public <P> Criteria<C, R> in(SingularAttribute<? super C, P> att, P... values) { add(new In<C, P>(att, values), values); return this; }
Example #30
Source File: Q.java From zstack with Apache License 2.0 | 4 votes |
public Q notLike(SingularAttribute attr, Object val) { q.add(attr, SimpleQuery.Op.NOT_LIKE, val); return this; }