|
Hibernate example source code file (MapKeyHelpers.java)
The Hibernate MapKeyHelpers.java source code/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by * third-party contributors as indicated by either @author tags or express * copyright attribution statements applied by the authors. All * third-party contributions are distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.path; import java.io.Serializable; import java.lang.reflect.Member; import java.util.Map; import javax.persistence.criteria.Join; import javax.persistence.criteria.MapJoin; import javax.persistence.criteria.Path; import javax.persistence.metamodel.Attribute; import javax.persistence.metamodel.Bindable; import javax.persistence.metamodel.ManagedType; import javax.persistence.metamodel.MapAttribute; import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.Type; import org.hibernate.ejb.criteria.CriteriaBuilderImpl; import org.hibernate.ejb.criteria.MapJoinImplementor; import org.hibernate.ejb.criteria.PathImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.persister.collection.CollectionPersister; /** * {@link MapJoin#key} poses a number of implementation difficulties in terms of the type signatures * amongst the {@link Path}, {@link Join} and {@link Attribute} reference at play. The implementations found here * provide that bridge. * * @author Steve Ebersole */ public class MapKeyHelpers { /** * Models a path to a map key. This is the actual return used from {@link MapJoin#key} * * @param <K> The type of the map key. */ public static class MapKeyPath<K> extends AbstractPathImpl<K> implements PathImplementor<K>, Serializable { private final MapKeyAttribute<K> mapKeyAttribute; public MapKeyPath( CriteriaBuilderImpl criteriaBuilder, MapKeySource<K,?> source, MapKeyAttribute<K> mapKeyAttribute) { super( criteriaBuilder, mapKeyAttribute.getJavaType(), source ); this.mapKeyAttribute = mapKeyAttribute; } @Override public MapKeySource getPathSource() { return (MapKeySource) super.getPathSource(); } public MapKeyAttribute<K> getAttribute() { return mapKeyAttribute; } private boolean isBasicTypeKey() { return Attribute.PersistentAttributeType.BASIC == mapKeyAttribute.getPersistentAttributeType(); } @Override protected boolean canBeDereferenced() { return ! isBasicTypeKey(); } @Override protected Attribute locateAttributeInternal(String attributeName) { if ( ! canBeDereferenced() ) { throw new IllegalArgumentException( "Map key [" + getPathSource().getPathIdentifier() + "] cannot be dereferenced" ); } throw new UnsupportedOperationException( "Not yet supported!" ); } public Bindable<K> getModel() { return mapKeyAttribute; } } /** * Defines a {@link Path} for the map which can then be used to represent the source of the * map key "attribute". * * @param <K> The map key type * @param <V> The map value type */ public static class MapKeySource<K,V> extends AbstractPathImpl<Map Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate MapKeyHelpers.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.