List of usage examples for org.hibernate.type Type isComponentType
boolean isComponentType();
From source file:com.siemens.scr.avt.ad.query.common.DicomMappingDictionaryLoadingStrategy.java
License:Open Source License
private void loadProperty(DicomMappingDictionary dict, Property prop, Table table, String classPrefix) { String key = classPrefix + "." + prop.getName(); Type type = prop.getType(); String tableName = table.getSchema() + "." + table.getName(); if (type.isAssociationType() || type.isCollectionType()) { // do nothing } else if (type.isComponentType()) { Component component = (Component) prop.getValue(); Iterator<Property> it = component.getPropertyIterator(); while (it.hasNext()) { Property subProp = it.next(); loadProperty(dict, subProp, table, component.getRoleName()); }//w ww . j a va 2 s. c om } else { int sqltype = sqlTypes(type); assert prop.getColumnSpan() == 1; Iterator<Column> it = prop.getColumnIterator(); String column = it.next().getName(); dict.addMappingEntry(key, tableName, column, sqltype); loadTag(dict, prop, key); loadDicomHeaderMetadata(dict, tableName, column, prop); } }
From source file:com.vaadin.data.hbnutil.HbnContainer.java
License:Open Source License
/** * This is an HbnContainer specific utility method that is used to retrieve the list of embedded property key * identifiers.//from w w w .j a v a 2 s . co m */ private Collection<String> getEmbeddedKeyPropertyIds() { logger.executionTrace(); final ArrayList<String> embeddedKeyPropertyIds = new ArrayList<String>(); final Type identifierType = classMetadata.getIdentifierType(); if (identifierType.isComponentType()) { final ComponentType idComponent = (ComponentType) identifierType; final String[] propertyNameArray = idComponent.getPropertyNames(); if (propertyNameArray != null) { final List<String> propertyNames = Arrays.asList(propertyNameArray); embeddedKeyPropertyIds.addAll(propertyNames); } } return embeddedKeyPropertyIds; }
From source file:com.vaadin.data.hbnutil.HbnContainer.java
License:Open Source License
/** * This is an internal HbnContainer utility method. Determines if a property is contained within an embedded key. *//*from ww w. j a v a 2s. c om*/ private boolean propertyInEmbeddedKey(Object propertyId) { logger.executionTrace(); if (embeddedPropertiesCache.containsKey(propertyId)) return embeddedPropertiesCache.get(propertyId); final Type identifierType = classMetadata.getIdentifierType(); if (identifierType.isComponentType()) { final ComponentType componentType = (ComponentType) identifierType; final String[] idPropertyNames = componentType.getPropertyNames(); final List<String> idPropertyNameList = Arrays.asList(idPropertyNames); return idPropertyNameList.contains(propertyId); } return false; }
From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java
License:Apache License
private Tuple<Type, String>[] getPath(ClassMetadata classMetadata, String[] names) { Tuple<Type, String>[] path = new Tuple[names.length]; Object element = classMetadata; for (int i = 0; i < names.length; ++i) { String name = names[i];/*from w ww . jav a 2 s . c o m*/ Type propertyType = getPropertyType(element, name); path[i] = new Tuple<Type, String>(propertyType, name); if (propertyType.isCollectionType()) { CollectionType collectionType = (CollectionType) propertyType; String associatedEntityName = collectionType.getRole(); CollectionPersister collectionPersister = getSessionFactory() .getCollectionPersister(associatedEntityName); element = collectionPersister.getElementType(); } else if (propertyType.isAssociationType()) { AssociationType associationType = (AssociationType) propertyType; String associatedEntityName = associationType.getAssociatedEntityName(getSessionFactory()); element = getSessionFactory().getClassMetadata(associatedEntityName); } else if (propertyType.isComponentType()) { element = propertyType; } } return path; }
From source file:edu.northwestern.bioinformatics.studycalendar.service.auditing.AuditEventFactory.java
License:BSD License
public void appendEventValues(AuditEvent event, Type propertyType, String propertyName, Object previousState, Object currentState) {// w w w . j a v a 2s . com if (ignoreCurrentStateForType(propertyType) || propertyName.indexOf(HIBERNATE_BACK_REF_STRING) > 0) { return; } else if (propertyType.isComponentType()) { addComponentValues(event, (CompositeType) propertyType, propertyName, previousState, currentState); } else { if (ignoreStates(previousState, currentState)) { return; } else { String prevValue = scalarValue(previousState); String curValue = scalarValue(currentState); if (prevValue != null && curValue != null && prevValue.equals(curValue)) { return; } event.addValue(new DataAuditEventValue(propertyName, prevValue, curValue)); } } }
From source file:edu.northwestern.bioinformatics.studycalendar.service.auditing.AuditEventFactory.java
License:BSD License
private String scalarCollectionValue(Collection coll, Type elementType) { Iterator it = coll.iterator(); StringBuffer sb = new StringBuffer(); String objValue;//w ww .j av a 2 s . c o m while (it.hasNext()) { Object obj = it.next(); if (elementType != null && elementType.isComponentType()) { Object[] componentObj = getComponentState((CompositeType) elementType, obj); objValue = scalarCollectionValue(Arrays.asList(componentObj), null); } else { objValue = scalarValue(obj); } if (objValue != null) { sb.append(EditorUtils.getEncodedString(objValue)); if (it.hasNext()) { sb.append(EditorUtils.SEPARATOR); } } } if (sb.length() == 0) { return null; } else { return sb.toString(); } }
From source file:edu.utah.further.core.data.hibernate.query.GroupByHavingProjection.java
License:Apache License
@Override public String toSqlString(final Criteria criteria, final int position, final CriteriaQuery criteriaQuery) throws HibernateException { final Type identifierType = criteriaQuery.getIdentifierType(criteria); if (identifierType.isComponentType()) { final StringBuffer sb = new StringBuffer(); appendComponentIds(sb, (ComponentType) identifierType, criteriaQuery, criteria, new Integer(position)); return sb.toString(); }/* w ww .ja v a 2 s. c o m*/ return super.toSqlString(criteria, position, criteriaQuery); }
From source file:edu.utah.further.core.data.hibernate.query.GroupByHavingProjection.java
License:Apache License
@Override public String toGroupSqlString(final Criteria criteria, final CriteriaQuery criteriaQuery) throws HibernateException { final StringBuffer sb = new StringBuffer(50); final Type identifierType = criteriaQuery.getIdentifierType(criteria); if (identifierType.isComponentType()) { appendComponentIds(sb, (ComponentType) identifierType, criteriaQuery, criteria, null); } else {// ww w . j a v a 2 s . com sb.append(criteriaQuery.getColumn(criteria, groupByProperty)); } // Append HAVING clause sb.append(" having "); sb.append("("); // Remove the alias final String proj = projection.toSqlString(criteria, 0xCAFEBABE, criteriaQuery); sb.append(proj.substring(0, proj.indexOf("as")).trim()); sb.append(")"); sb.append(SPACE_STRING).append(op.getSqloperator()).append(SPACE_STRING).append(value); return sb.toString(); }
From source file:edu.utah.further.core.data.util.HibernateUtil.java
License:Apache License
/** * @deprecated This method does not work well due to Hibernate bug HHH-817, nor does * AliasToBeanResultTransformer handle multi-level property values. * Therefore it should not be used. * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-817 *///from www . j ava 2 s . c o m @Deprecated public static Projection createProjectionList(final String identifierProperty, final Type identifierType, final String[] propertyNames, final Class<?> domainClass) { final ProjectionList projectionList = Projections.projectionList(); if (identifierType.isComponentType()) { final String[] idProperties = ((ComponentType) (identifierType)).getPropertyNames(); for (final String idProperty : idProperties) { final String idPath = identifierProperty + "." + idProperty; projectionList.add(Projections.property(idPath)); } } else { projectionList.add(Projections.id()); } for (final String propertyName : propertyNames) { final Field field = ReflectionUtils.findField(domainClass, propertyName); if (!hasAssociationAnnotation(field)) { projectionList.add(Projections.property(propertyName), propertyName); } } return projectionList; }
From source file:edu.utah.further.core.data.util.HibernateUtil.java
License:Apache License
/** * Generates an SQL in (...) statement to be used with in statements involving * composite keys.//from w ww . j a va 2 s . c o m * * This method is strictly a workaround utility method for an issue with using * {@link Restrictions#in(String, java.util.Collection)} with a composite key. It * generates an sql statement correctly but binds the parameters wrong. This issue has * been reported SEVERAL times, as early as 05 and it still hasn't been fixed (it's * 09). There is a 2 second correction that needs to be added to the code to fix the * issue but for some reason Hibernate developers refuse to do it. In light of not * knowing what else it might break in custom compiling Hibernate with the fix it was * preferred to do a work around. It is to be used directly with * {@link Restrictions#sqlRestriction(String)}. * * @param entityClass * the entity which contains the composite key for which an SQL in * statement needs to be generated * @param sessionFactory * the {@link SessionFactory} assosciated with the entities * @param elementsSize * the size of the elements that will be in the in clause * @return * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-708 * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-1575 * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-1743 * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-1832 * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-1972 * @see http://opensource.atlassian.com/projects/hibernate/browse/HHH-3164 */ public static String sqlRestrictionCompositeIn(final Class<? extends PersistentEntity<?>> entityClass, final SessionFactory sessionFactory, final int elementsSize) { final ClassMetadata classMetadata = sessionFactory.getClassMetadata(entityClass); final String identifierName = classMetadata.getIdentifierPropertyName(); final Type identifierType = classMetadata.getIdentifierType(); if (!(identifierType.isComponentType())) { return Strings.EMPTY_STRING; } final ComponentType componentType = (ComponentType) identifierType; final String[] idPropertyNames = componentType.getPropertyNames(); final PropertyMapping propertyMapping = getPropertyMapping(entityClass, sessionFactory); final StringBuilder inString = StringUtil.newStringBuilder(); // field names -- ({alias}.field1, {alias}.field2) inString.append('('); for (int i = 0; i < idPropertyNames.length; i++) { inString.append("{alias}").append('.') // Look up the database field from the property path .append(propertyMapping.toColumns(identifierName + "." + idPropertyNames[i])[0]); if (i + 1 < idPropertyNames.length) { inString.append(", "); } else { inString.append(')'); } } // values -- in ( (?, ?), (?, ?) ) inString.append(" in ").append('('); for (int i = 0; i < elementsSize; i++) { if (elementsSize % MAX_IN == 0) { inString.append(')'); inString.append(Strings.EMPTY_STRING); inString.append("or"); inString.append(Strings.EMPTY_STRING); inString.append('('); } inString.append('('); for (int j = 0; j < idPropertyNames.length; j++) { inString.append('?'); if (j + 1 < idPropertyNames.length) { inString.append(","); } } inString.append(')'); if ((i + 1 < elementsSize) && (i + 1 % MAX_IN != 0)) { inString.append(", "); } } inString.append(')'); return inString.toString(); }