From: <gca...@us...> - 2012-07-02 12:56:33
|
Revision: 4088 http://openutils.svn.sourceforge.net/openutils/?rev=4088&view=rev Author: gcatania Date: 2012-07-02 12:56:22 +0000 (Mon, 02 Jul 2012) Log Message: ----------- Merged revisions 4087 via svnmerge from https://openutils.svn.sourceforge.net/svnroot/openutils/trunk/openutils-bshd5 ........ r4087 | gcatania | 2012-07-02 14:44:01 +0200 (Mon, 02 Jul 2012) | 1 line BSHD-11 also fixed in FilterMetadataSupport ........ Revision Links: -------------- http://openutils.svn.sourceforge.net/openutils/?rev=4087&view=rev Modified Paths: -------------- branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTree.java branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java Property Changed: ---------------- branches/openutils-bshd5-backport/ branches/openutils-bshd5-backport/pom.xml branches/openutils-bshd5-backport/src/ Property changes on: branches/openutils-bshd5-backport ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/openutils-bshd5:1-4040,4042-4056,4058-4085 + /trunk/openutils-bshd5:1-4040,4042-4056,4058-4087 Modified: svn:mergeinfo - /trunk/openutils-bshd5:4045-4047*,4057,4059,4069-4070*,4073*,4075-4078*,4080*,4082*,4084-4085* + /trunk/openutils-bshd5:4045-4047*,4057,4059,4069-4070*,4073*,4075-4078*,4080*,4082*,4084-4085*,4087* Property changes on: branches/openutils-bshd5-backport/pom.xml ___________________________________________________________________ Modified: svn:mergeinfo - /trunk/openutils-bshd5/pom.xml:4045-4047,4059,4069-4070,4073,4075-4078,4080,4082,4084-4085 + /trunk/openutils-bshd5/pom.xml:4045-4047,4059,4069-4070,4073,4075-4078,4080,4082,4084-4085,4087 Property changes on: branches/openutils-bshd5-backport/src ___________________________________________________________________ Modified: svn:mergeinfo - /trunk/openutils-bshd5/src:4045-4047,4057,4069-4070,4073,4075-4078,4080,4082,4084-4085 + /trunk/openutils-bshd5/src:4045-4047,4057,4069-4070,4073,4075-4078,4080,4082,4084-4085,4087 Modified: branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTree.java =================================================================== --- branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2012-07-02 12:44:01 UTC (rev 4087) +++ branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2012-07-02 12:56:22 UTC (rev 4088) @@ -45,8 +45,6 @@ import org.hibernate.criterion.Example; import org.hibernate.criterion.Example.PropertySelector; import org.hibernate.criterion.MatchMode; -import org.hibernate.criterion.Restrictions; -import org.hibernate.engine.SessionImplementor; import org.hibernate.metadata.ClassMetadata; import org.hibernate.type.Type; @@ -265,7 +263,7 @@ } ClassMetadata classMetadata = sessionFactory.getClassMetadata(Hibernate.getClass(entity)); - addIdentifierRestriction(crit, entity, classMetadata); // BSHD-11 + ExampleTreeUtils.addIdentifierRestriction(crit, entity, classMetadata, sessionFactory.getCurrentSession()); // BSHD-11 Type[] types = classMetadata.getPropertyTypes(); String[] names = classMetadata.getPropertyNames(); @@ -300,26 +298,6 @@ } } - /* - * BSHD-11 - */ - private void addIdentifierRestriction(Criteria crit, Object entity, ClassMetadata classMetadata) - { - String identifierName = classMetadata.getIdentifierPropertyName(); - if (identifierName != null) - { - // TODO is this cast really necessary? Will it fail in future hibernate versions? - SessionImplementor si = (SessionImplementor) sessionFactory.getCurrentSession(); - - // Object idValue = classMetadata.getIdentifier(entity, si); - Object idValue = classMetadata.getIdentifier(entity, entityMode); - if (idValue != null) // TODO should we use property selectors instead? - { - crit.add(Restrictions.idEq(idValue)); - } - } - } - private Example example(Object entity, String associationPath) { Example ex = Example.create(entity); @@ -417,4 +395,4 @@ } } -} \ No newline at end of file +} Modified: branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java =================================================================== --- branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2012-07-02 12:44:01 UTC (rev 4087) +++ branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2012-07-02 12:56:22 UTC (rev 4088) @@ -30,6 +30,11 @@ import java.util.Collection; import org.apache.commons.lang3.StringUtils; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; +import org.hibernate.engine.SessionImplementor; +import org.hibernate.metadata.ClassMetadata; /** @@ -144,4 +149,29 @@ return propertyNames.length > 0 ? StringUtils.join(propertyNames, '.') : StringUtils.EMPTY; } + /** + * adds the identifier restriction to the input criteria, if required + * @param crit the criteria + * @param entity the entity to use as example + * @param classMetadata the class metadata to use + * @param ses the current session + * @see BSHD-11 + */ + public static void addIdentifierRestriction(Criteria crit, Object entity, ClassMetadata classMetadata, Session ses) + { + String identifierName = classMetadata.getIdentifierPropertyName(); + if (identifierName != null) + { + // TODO is this cast really necessary? Will it fail in future hibernate versions? + SessionImplementor si = (SessionImplementor) ses; + + // Object idValue = classMetadata.getIdentifier(entity, si); + Object idValue = classMetadata.getIdentifier(entity, ses.getEntityMode()); + if (idValue != null) // TODO should we use property selectors instead? + { + crit.add(Restrictions.idEq(idValue)); + } + } + } + } Modified: branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java =================================================================== --- branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2012-07-02 12:44:01 UTC (rev 4087) +++ branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2012-07-02 12:56:22 UTC (rev 4088) @@ -116,6 +116,9 @@ Map<String, FilterMetadata> currFilterMetadata = getFilterMetadata(path); crit.add(example(entity, currFilterMetadata.keySet())); ClassMetadata classMetadata = sessionFactory.getClassMetadata(Hibernate.getClass(entity)); + + ExampleTreeUtils.addIdentifierRestriction(crit, entity, classMetadata, sessionFactory.getCurrentSession()); // BSHD-11 + Type[] types = classMetadata.getPropertyTypes(); String[] names = classMetadata.getPropertyNames(); for (int i = 0; i < types.length; i++) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |