IGNITE-3429: Added BinaryResolver configuration samples for org.hibernate.cache.spi.CacheKey. This closes #1516.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/05788b31 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/05788b31 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/05788b31 Branch: refs/heads/ignite-1192 Commit: 05788b3188b30b5a3b39a75fe66301e03658408f Parents: 8874f99 Author: Andrey V. Mashenkov <[email protected]> Authored: Fri Feb 17 12:14:53 2017 +0300 Committer: Andrey V. Mashenkov <[email protected]> Committed: Fri Feb 17 12:14:53 2017 +0300 ---------------------------------------------------------------------- .../Hibernate5CacheKeyTypeConfiguration.java | 52 ++++++++++++++++++++ .../HibernateCacheKeyTypeConfiguration.java | 51 +++++++++++++++++++ 2 files changed, 103 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/05788b31/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/config/Hibernate5CacheKeyTypeConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/config/Hibernate5CacheKeyTypeConfiguration.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/config/Hibernate5CacheKeyTypeConfiguration.java new file mode 100644 index 0000000..886f69b --- /dev/null +++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/config/Hibernate5CacheKeyTypeConfiguration.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.hibernate.config; + +import java.util.Objects; +import org.apache.ignite.binary.BinaryAbstractIdentityResolver; +import org.apache.ignite.binary.BinaryIdentityResolver; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.binary.BinaryTypeConfiguration; + +/** + * This configuration provides correct {@link BinaryIdentityResolver} implementation + * for Hibernate CacheKey class can be used as a key object. + * + * Note: for Hibernate version < 5.0 {@link HibernateCacheKeyTypeConfiguration} should be used. + + */ +public class Hibernate5CacheKeyTypeConfiguration extends BinaryTypeConfiguration { + + /** {@inheritDoc} */ + public Hibernate5CacheKeyTypeConfiguration() { + super("org.hibernate.cache.internal.CacheKeyImplementation"); + + setIdentityResolver(new BinaryAbstractIdentityResolver() { + @Override protected int hashCode0(BinaryObject obj) { + return obj.field("id").hashCode(); + } + + @Override protected boolean equals0(BinaryObject o1, BinaryObject o2) { + Object obj0 = o1.field("id"); + Object obj1 = o2.field("id"); + + return Objects.equals(obj0, obj1); + } + }); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/05788b31/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/config/HibernateCacheKeyTypeConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/config/HibernateCacheKeyTypeConfiguration.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/config/HibernateCacheKeyTypeConfiguration.java new file mode 100644 index 0000000..c54292e --- /dev/null +++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/config/HibernateCacheKeyTypeConfiguration.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.hibernate.config; + +import java.util.Objects; +import org.apache.ignite.binary.BinaryAbstractIdentityResolver; +import org.apache.ignite.binary.BinaryIdentityResolver; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.binary.BinaryTypeConfiguration; + +/** + * This configuration provides correct {@link BinaryIdentityResolver} implementation + * for Hibernate CacheKey class can be used as a key object. + * + * Note: for Hibernate version >= 5.0 {@link Hibernate5CacheKeyTypeConfiguration} should be used. + */ +public class HibernateCacheKeyTypeConfiguration extends BinaryTypeConfiguration { + + /** {@inheritDoc} */ + public HibernateCacheKeyTypeConfiguration() { + super("org.hibernate.cache.spi.CacheKey"); + + setIdentityResolver(new BinaryAbstractIdentityResolver() { + @Override protected int hashCode0(BinaryObject obj) { + return obj.field("key").hashCode(); + } + + @Override protected boolean equals0(BinaryObject o1, BinaryObject o2) { + Object obj0 = o1.field("key"); + Object obj1 = o2.field("key"); + + return Objects.equals(obj0, obj1); + } + }); + } +}
