Refine search
@SuppressWarnings({"rawtypes", "unchecked", "serial"}) public Path getPath(From root, FieldPath fieldPath, final CriteriaBuilder builder) { FieldPath myFieldPath = fieldPath; if (!StringUtils.isEmpty(fieldPath.getTargetProperty())) { myFieldPath = getFieldPath(root, fieldPath.getTargetProperty()); String original = ((SingularAttributePath) path).getAttribute().getDeclaringType().getJavaType().getName() + "." + ((SingularAttributePath) path).getAttribute().getName() + "." + piece; String copy = path.getJavaType().getName() + "." + piece; copyCollectionPersister(original, copy, ((CriteriaBuilderImpl) builder).getEntityManagerFactory().getSessionFactory()); ManagedType mt = mm.managedType(clazz); try { Attribute attr = mt.getAttribute(piece);
/** * Returns whether the attribute of given name and type is the single identifier attribute of the given entity. * * @param entity must not be {@literal null}. * @param name must not be {@literal null}. * @param attributeType must not be {@literal null}. * @return */ public boolean isSingleIdAttribute(Class<?> entity, String name, Class<?> attributeType) { return metamodel.getEntities().stream() // .filter(it -> entity.equals(it.getJavaType())) // .findFirst() // .flatMap(it -> getSingularIdAttribute(it)) // .filter(it -> it.getJavaType().equals(attributeType)) // .map(it -> it.getName().equals(name)) // .orElse(false); }
private String tryFindSingularIdAttributeNameOrUseFallback(Class<? extends Object> idPropertyValueType, String fallbackIdTypePropertyName) { ManagedType<? extends Object> idPropertyType = metamodel.managedType(idPropertyValueType); for (SingularAttribute<?, ?> sa : idPropertyType.getSingularAttributes()) { if (sa.isId()) { return sa.getName(); } } return fallbackIdTypePropertyName; }
private ManagedType<X> resolveManagedType(SingularAttribute<?, X> attribute) { if ( Attribute.PersistentAttributeType.BASIC == attribute.getPersistentAttributeType() ) { return null; } else if ( Attribute.PersistentAttributeType.EMBEDDED == attribute.getPersistentAttributeType() ) { return (EmbeddableType<X>) attribute.getType(); } else { return (IdentifiableType<X>) attribute.getType(); } }
builder.append(translator.ensureCase(new StringBuilder(), joinTableData.getInverseJoinColumnName(), false)); insert_Query = StringUtils.replace(insert_Query, CQLTranslator.COLUMN_FAMILY, translator.ensureCase(new StringBuilder(), joinTableName, false).toString()); insert_Query = StringUtils.replace(insert_Query, CQLTranslator.COLUMNS, builder.toString()); PropertyAccessorFactory.getPropertyAccessor((Field) entityMetadata.getIdAttribute().getJavaMember()); StringUtils.replace(insertQuery, CQLTranslator.COLUMN_VALUES, columnValueBuilder.toString()); statements.append(insertQuery); statements.append(" ");
private String where() { if (andConditions.isEmpty()) { return null; } List<String> condstrs = new ArrayList<>(); for (List<Cond> conds : andConditions.values()) { for (int i=0; i<conds.size(); i++) { Cond cond = conds.get(i); String condName = String.format("cond_%s_%s", cond.attr.getName(), i); if (Op.IN == cond.op || Op.NOT_IN == cond.op) { condstrs.add(String.format("vo.%s %s (:%s)", cond.attr.getName(), cond.op.toString(), condName)); } else if (Op.NULL == cond.op || Op.NOT_NULL == cond.op) { condstrs.add(String.format("vo.%s %s", cond.attr.getName(), cond.op)); } else { condstrs.add(String.format("vo.%s %s :%s", cond.attr.getName(), cond.op.toString(), condName)); } } } return StringUtils.join(condstrs, " AND "); }
/** * Prepares ID column value for embedded IDs by combining its attributes * * @param m * @param id * @param metaModel * @return */ private String serializeIdAttributeValue(final EntityMetadata m, MetamodelImpl metaModel, Object id) { if (!metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType())) { return null; } Class<?> embeddableClass = m.getIdAttribute().getBindableJavaType(); String idUniqueValue = ""; for (Field embeddedField : embeddableClass.getDeclaredFields()) { if (!ReflectUtils.isTransientOrStatic(embeddedField)) { Object value = PropertyAccessorHelper.getObject(id, embeddedField); if (value != null && !StringUtils.isEmpty(value.toString())) idUniqueValue = idUniqueValue + value + COMPOSITE_KEY_SEPARATOR; } } if (idUniqueValue.endsWith(COMPOSITE_KEY_SEPARATOR)) idUniqueValue = idUniqueValue.substring(0, idUniqueValue.length() - COMPOSITE_KEY_SEPARATOR.length()); return idUniqueValue; }
Set<Attribute> attributes = entityType.getAttributes(); if (!entityMetadata.getIdAttribute().getName().equals(attrib.getName()) && !metaModel.isEmbeddable(attrib.getJavaType()) && !attrib.isAssociation()) { String tableName = ((AbstractAttribute) attrib).getTableName() != null ? ((AbstractAttribute) attrib).getTableName() : entityMetadata.getTableName(); update_Query = StringUtils.replace(update_Query, CQLTranslator.COLUMN_FAMILY, translator.ensureCase(new StringBuilder(), tableName, false).toString());
update_Query = StringUtils.replace(update_Query, CQLTranslator.COLUMN_FAMILY, translator.ensureCase(new StringBuilder(), tableName, false).toString()); builder.append(CQLTranslator.ADD_WHERE_CLAUSE); Class compoundKeyClass = metadata.getIdAttribute().getBindableJavaType(); EmbeddableType compoundKey = null; String idColumn;
EntityType entityType = metaModel.entity(entityMetadata.getEntityClazz()); Map<String, PropertyIndex> columns = entityMetadata.getIndexProperties(); Set attributes = entityType.getAttributes(); if (!attr.isAssociation()) if (((MetamodelImpl) metaModel).isEmbeddable(attr.getJavaType())) EmbeddableType embeddable = metaModel.embeddable(attr.getJavaType()); EmbeddedColumnInfo embeddedColumnInfo = getEmbeddedColumn(tableInfo, embeddable, attr.getName(), else if (!attr.isCollection() && !((SingularAttribute) attr).isId())
Set<Attribute> attributes = entityType.getSingularAttributes(); Field field = (Field) attribute.getJavaMember(); String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); if (metaModel.isEmbeddable(relationshipEntityMetadata.getIdAttribute().getBindableJavaType()) && relationshipEntityMetadata.getIdAttribute().getJavaType().equals(field.getType())) else if (!attribute.isCollection() && !attribute.isAssociation() && !field.getType().equals(topLevelEntityMetadata.getEntityClazz()) && !field.getType().equals(relation.getTargetEntity())) && !metaModel.isEmbeddable(relationshipEntityMetadata.getIdAttribute().getBindableJavaType())) relationshipEntityMetadata, fromNeo4JObject(rowKey, (Field) relationshipEntityMetadata.getIdAttribute() .getJavaMember()));
public Object find(Class entityClass, Object key) { EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass); String tableName = entityMetadata.getTableName(); Class fieldClass = entityMetadata.getIdAttribute().getJavaType(); String select_Query = SparkQueryConstants.SELECTALL_QUERY; select_Query = StringUtils.replace(select_Query, SparkQueryConstants.TABLE, tableName); StringBuilder builder = new StringBuilder(select_Query); builder.append(SparkQueryConstants.ADD_WHERE_CLAUSE); builder.append(dataHandler.getColumnName(entityMetadata.getIdAttribute())); builder.append(SparkQueryConstants.EQUALS); appendValue(builder, fieldClass, key); List result = this.executeQuery(builder.toString(), entityMetadata, null); return result.isEmpty() ? null : result.get(0); }
@Override protected String idAttribute() { Class<?> entityClass = context.getEntityViewManager().getMetamodel().view(viewClass()).getEntityClass(); EntityType<?> entityType = context.getEntityManager().getMetamodel().entity(entityClass); return JpaMetamodelUtils.getSingleIdAttribute(entityType).getName(); } }
public JpaValueEncoder(final EntityType<E> entity, final EntityManagerManager entityManagerManager, final String persistenceUnitName, final PropertyAccess propertyAccess, final TypeCoercer typeCoercer, final Logger logger) { super(); this.entity = entity; this.entityManagerManager = entityManagerManager; this.persistenceUnitName = persistenceUnitName; this.typeCoercer = typeCoercer; this.logger = logger; final Type<?> idType = this.entity.getIdType(); final SingularAttribute<? super E, ?> idAttribute = this.entity.getId(idType.getJavaType()); idPropertyName = idAttribute.getName(); propertyAdapter = propertyAccess.getAdapter(entity.getJavaType()).getPropertyAdapter( idPropertyName); }
if (root.getModel().hasSingleIdAttribute()) { SingularAttribute<?, ?> id = root.getModel().getId(root.getModel().getIdType().getJavaType()); query = query.multiselect(root.get((SingularAttribute) id).alias(id.getName())); query = query.multiselect(root.getModel().getIdClassAttributes().stream()// .map(it -> (Selection<?>) root.get((SingularAttribute) it).alias(it.getName())) .collect(Collectors.toList()));
public static EntityTypeDescriptor createSimpleEntityTypeDescriptor(EntityManagerFactory emf, Class<?> clazz) { EntityType<?> entityType = emf.getMetamodel().entity( clazz ); SingularAttribute<?, ?> idAttribute = entityType.getId( entityType.getIdType().getJavaType() ); return new EntityTypeDescriptor( clazz, new SingularIdOrder( idAttribute.getName() ) ); }
Set<Attribute> columns = entityType.getAttributes(); for (Attribute column : columns) boolean isLob = ((Field) column.getJavaMember()).getAnnotation(Lob.class) != null; if (isLob) gridFSInputFile = createGFSInputFile(gfs, entity, (Field) column.getJavaMember()); gridFSInputFile.setFilename(column.getName()); if (isUpdate && column.getName().equals(m.getIdAttribute().getName()))
m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Set<Attribute> attributes = entityType.getAttributes(); String[] columns = new String[attributes.size() - 1]; int count = 0; for (Attribute attr : attributes) if (!attr.isCollection() && !attr.getName().equalsIgnoreCase(m.getIdAttribute().getName())) else if (attr.isCollection())
if (metaModel.isEmbeddable(entityMetadata.getIdAttribute().getBindableJavaType())) keyObj = metaModel.embeddable(entityMetadata.getIdAttribute().getBindableJavaType()); || (keyObj != null && StringUtils.contains(fieldName, '.')) || (idColumn.equals(fieldName)))
private String getIdAttribute(Class<?> entityClass) { EntityType<?> entityType = entityManager.getMetamodel().entity(entityClass); return entityType.getDeclaredId(entityType.getIdType().getJavaType()).getName(); }