Java Code Examples for javax.persistence.metamodel.SingularAttribute#getName()
The following examples show how to use
javax.persistence.metamodel.SingularAttribute#getName() .
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: JPAPersistenceManager.java From Knowage-Server with GNU Affero General Public License v3.0 | 8 votes |
public String getKeyAttributeName(EntityType entity) { logger.debug("IN : entity = [" + entity + "]"); String keyName = null; for (Object attribute : entity.getAttributes()) { if (attribute instanceof SingularAttribute) { SingularAttribute s = (SingularAttribute) attribute; logger.debug("Attribute: " + s.getName() + " is a singular attribute."); if (s.isId()) { keyName = s.getName(); break; } } else { logger.debug("Attribute " + attribute + " is not singular attribute, cannot manage it"); } } Assert.assertNotNull(keyName, "Key attribute name was not found!"); logger.debug("OUT : " + keyName); return keyName; }
Example 2
Source File: EntityModel.java From webanno with Apache License 2.0 | 5 votes |
private void analyze(T aObject) { if (aObject != null) { entityClass = HibernateProxyHelper.getClassWithoutInitializingProxy(aObject); String idProperty = null; Metamodel metamodel = getEntityManager().getMetamodel(); EntityType entity = metamodel.entity(entityClass); Set<SingularAttribute> singularAttributes = entity.getSingularAttributes(); for (SingularAttribute singularAttribute : singularAttributes) { if (singularAttribute.isId()) { idProperty = singularAttribute.getName(); break; } } if (idProperty == null) { throw new RuntimeException("id field not found"); } DirectFieldAccessor accessor = new DirectFieldAccessor(aObject); id = (Number) accessor.getPropertyValue(idProperty); } else { entityClass = null; id = null; } }
Example 3
Source File: AbstractRSQLMapper.java From pnc with Apache License 2.0 | 5 votes |
@Override public String toPath(RSQLSelectorPath selector) { String name = selector.getElement(); if (toAttribute(name) != null) { return toAttribute(name).getName(); } SingularAttribute<DB, ? extends GenericEntity<?>> entity = toEntity(name); if (entity != null) { Class<? extends GenericEntity<?>> bindableType = entity.getBindableJavaType(); return entity.getName() + "." + mapper.toPath(bindableType, selector.next()); } throw new RSQLException("Unknown RSQL selector " + name + " for type " + type); }
Example 4
Source File: OrderBy.java From gazpachoquest with GNU General Public License v3.0 | 5 votes |
public OrderBy(final SingularAttribute<? extends Persistable, ? extends Serializable> attribute, final OrderByDirection direction) { Validate.notNull(attribute); Validate.notNull(direction); columnOrProperty = attribute.getName(); this.direction = direction; }
Example 5
Source File: QueryProxy.java From tomee with Apache License 2.0 | 5 votes |
private void remove(final Object[] args, final Class<?> returnType) { if (args != null && args.length == 1 && returnType.equals(Void.TYPE)) { Object entity = args[0]; if (!em.contains(entity)) { // reattach the entity if possible final Class<?> entityClass = entity.getClass(); final EntityType<? extends Object> et = em.getMetamodel().entity(entityClass); if (!et.hasSingleIdAttribute()) { throw new IllegalArgumentException("Dynamic EJB doesn't manage IdClass yet"); } SingularAttribute<?, ?> id = null; // = et.getId(entityClass); doesn't work with openJPA for (final SingularAttribute<?, ?> sa : et.getSingularAttributes()) { if (sa.isId()) { id = sa; break; } } if (id == null) { throw new IllegalArgumentException("id field not found"); } final String idName = id.getName(); final Object idValue = getProperty(entity, idName); entity = em.getReference(et.getJavaType(), idValue); if (entity == null) { throw new IllegalArgumentException("entity " + entity + " is not managed and can't be found."); } } em.remove(entity); } else { throw new IllegalArgumentException(REMOVE_NAME + " should have only one parameter and return void"); } }
Example 6
Source File: OrderByQueryStringPostProcessor.java From deltaspike with Apache License 2.0 | 5 votes |
public OrderByQueryStringPostProcessor(SingularAttribute<?, ?> attribute, OrderDirection direction, boolean appendEntityName) { this.attribute = attribute.getName(); this.direction = direction; this.appendEntityName = appendEntityName; }