本文整理汇总了Java中org.hibernate.type.ComponentType类的典型用法代码示例。如果您正苦于以下问题:Java ComponentType类的具体用法?Java ComponentType怎么用?Java ComponentType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ComponentType类属于org.hibernate.type包,在下文中一共展示了ComponentType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeCaller
import org.hibernate.type.ComponentType; //导入依赖的package包/类
static Object makeCaller ( Object tpl, Object getters ) throws NoSuchMethodException, InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchFieldException, Exception, ClassNotFoundException {
PojoComponentTuplizer tup = Reflections.createWithoutConstructor(PojoComponentTuplizer.class);
Reflections.getField(AbstractComponentTuplizer.class, "getters").set(tup, getters);
ComponentType t = Reflections.createWithConstructor(ComponentType.class, AbstractType.class, new Class[0], new Object[0]);
Reflections.setFieldValue(t, "componentTuplizer", tup);
Reflections.setFieldValue(t, "propertySpan", 1);
Reflections.setFieldValue(t, "propertyTypes", new Type[] {
t
});
TypedValue v1 = new TypedValue(t, null);
Reflections.setFieldValue(v1, "value", tpl);
Reflections.setFieldValue(v1, "type", t);
TypedValue v2 = new TypedValue(t, null);
Reflections.setFieldValue(v2, "value", tpl);
Reflections.setFieldValue(v2, "type", t);
return Gadgets.makeMap(v1, v2);
}
示例2: getComponentValue
import org.hibernate.type.ComponentType; //导入依赖的package包/类
/**
* Extract a component property value.
*
* @param type The component property types.
* @param component The component instance itself.
* @param propertyPath The property path for the property to be extracted.
* @return The property value extracted.
*/
protected Object getComponentValue(ComponentType type, Object component, String propertyPath) {
final int loc = propertyPath.indexOf( '.' );
final String basePropertyName = loc > 0
? propertyPath.substring( 0, loc )
: propertyPath;
final int index = findSubPropertyIndex( type, basePropertyName );
final Object baseValue = type.getPropertyValue( component, index );
if ( loc > 0 ) {
if ( baseValue == null ) {
return null;
}
return getComponentValue(
(ComponentType) type.getSubtypes()[index],
baseValue,
propertyPath.substring(loc+1)
);
}
else {
return baseValue;
}
}
示例3: needsRecreate
import org.hibernate.type.ComponentType; //导入依赖的package包/类
@Override
public boolean needsRecreate(CollectionPersister persister) {
// Workaround for situations like HHH-7072. If the collection element is a component that consists entirely
// of nullable properties, we currently have to forcefully recreate the entire collection. See the use
// of hasNotNullableColumns in the AbstractCollectionPersister constructor for more info. In order to delete
// row-by-row, that would require SQL like "WHERE ( COL = ? OR ( COL is null AND ? is null ) )", rather than
// the current "WHERE COL = ?" (fails for null for most DBs). Note that
// the param would have to be bound twice. Until we eventually add "parameter bind points" concepts to the
// AST in ORM 5+, handling this type of condition is either extremely difficult or impossible. Forcing
// recreation isn't ideal, but not really any other option in ORM 4.
if (persister.getElementType() instanceof ComponentType) {
ComponentType componentType = (ComponentType) persister.getElementType();
return !componentType.hasNotNullProperty();
}
return false;
}
示例4: ComponentJoin
import org.hibernate.type.ComponentType; //导入依赖的package包/类
public ComponentJoin(
FromClause fromClause,
FromElement origin,
String alias,
String componentPath,
ComponentType componentType) {
super( fromClause, origin, alias );
this.componentPath = componentPath;
this.componentType = componentType;
this.componentProperty = StringHelper.unqualify( componentPath );
fromClause.addJoinByPathMap( componentPath, this );
initializeComponentJoin( new ComponentFromElementType( this ) );
this.columns = origin.getPropertyMapping( "" ).toColumns( getTableAlias(), componentProperty );
StringBuilder buf = new StringBuilder();
for ( int j = 0; j < columns.length; j++ ) {
final String column = columns[j];
if ( j > 0 ) {
buf.append( ", " );
}
buf.append( column );
}
this.columnsFragment = buf.toString();
}
示例5: getPropertyValue
import org.hibernate.type.ComponentType; //导入依赖的package包/类
public Object getPropertyValue(Object entity, String propertyPath) throws HibernateException {
int loc = propertyPath.indexOf('.');
String basePropertyName = loc>0 ?
propertyPath.substring(0, loc) : propertyPath;
int index = entityMetamodel.getPropertyIndex( basePropertyName );
Object baseValue = getPropertyValue( entity, index );
if ( loc>0 ) {
ComponentType type = (ComponentType) entityMetamodel.getPropertyTypes()[index];
return getComponentValue( type, baseValue, propertyPath.substring(loc+1) );
}
else {
return baseValue;
}
}
示例6: testComponentQueries
import org.hibernate.type.ComponentType; //导入依赖的package包/类
public void testComponentQueries() {
Session s = openSession();
s.beginTransaction();
Type[] types = s.createQuery( "select h.name from Human h" ).getReturnTypes();
assertEquals( 1, types.length );
assertTrue( types[0] instanceof ComponentType );
// Test the ability to perform comparisions between component values
s.createQuery( "from Human h where h.name = h.name" ).list();
s.createQuery( "from Human h where h.name = :name" ).setParameter( "name", new Name() ).list();
s.createQuery( "from Human where name = :name" ).setParameter( "name", new Name() ).list();
s.createQuery( "from Human h where :name = h.name" ).setParameter( "name", new Name() ).list();
s.createQuery( "from Human h where :name <> h.name" ).setParameter( "name", new Name() ).list();
// Test the ability to perform comparisions between a component and an explicit row-value
s.createQuery( "from Human h where h.name = ('John', 'X', 'Doe')" ).list();
s.createQuery( "from Human h where ('John', 'X', 'Doe') = h.name" ).list();
s.createQuery( "from Human h where ('John', 'X', 'Doe') <> h.name" ).list();
s.createQuery( "from Human h where ('John', 'X', 'Doe') >= h.name" ).list();
s.createQuery( "from Human h order by h.name" ).list();
s.getTransaction().commit();
s.close();
}
示例7: getForeignKeyValue
import org.hibernate.type.ComponentType; //导入依赖的package包/类
/**
* Get the value of the foreign key property. This comes from the entity, but if that value is
* null, and the entity is deleted, we try to get it from the originalValuesMap.
* @param entityInfo Breeze EntityInfo
* @param meta Metadata for the entity class
* @param foreignKeyName Name of the foreign key property of the entity, e.g. "CustomerID"
* @return
*/
private Object getForeignKeyValue(EntityInfo entityInfo, ClassMetadata meta, String foreignKeyName) {
Object entity = entityInfo.entity;
Object id = null;
if (foreignKeyName.equalsIgnoreCase(meta.getIdentifierPropertyName())) {
id = meta.getIdentifier(entity, null);
} else if (Arrays.asList(meta.getPropertyNames()).contains(foreignKeyName)) {
id = meta.getPropertyValue(entity, foreignKeyName);
} else if (meta.getIdentifierType().isComponentType()) {
// compound key
ComponentType compType = (ComponentType) meta.getIdentifierType();
int index = Arrays.asList(compType.getPropertyNames()).indexOf(foreignKeyName);
if (index >= 0) {
Object idComp = meta.getIdentifier(entity, null);
id = compType.getPropertyValue(idComp, index, EntityMode.POJO);
}
}
if (id == null && entityInfo.entityState == EntityState.Deleted) {
id = entityInfo.originalValuesMap.get(foreignKeyName);
}
return id;
}
示例8: getEmbeddedKeyPropertyIds
import org.hibernate.type.ComponentType; //导入依赖的package包/类
/**
* This is an HbnContainer specific utility method that is used to retrieve the list of embedded property key
* identifiers.
*/
protected 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;
}
示例9: propertyInEmbeddedKey
import org.hibernate.type.ComponentType; //导入依赖的package包/类
/**
* This is an internal HbnContainer utility method. Determines if a property is contained within an embedded key.
*/
protected 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;
}
示例10: appendComponentIds
import org.hibernate.type.ComponentType; //导入依赖的package包/类
/**
* Private helper method to construct component ids with an optional alias.
*
* @param sb
* a {@link StringBuffer}
* @param componentType
* the {@link ComponentType}
* @param criteriaQuery
* the {@link CriteriaQuery}
* @param criteria
* the {@link Criteria}
* @param position
* the position of the alias, appened if >= 0
*/
private void appendComponentIds(final StringBuffer sb,
final ComponentType componentType, final CriteriaQuery criteriaQuery,
final Criteria criteria, final Integer position)
{
final String[] idProperties = componentType.getPropertyNames();
int currPos = position != null ? position.intValue() : -1;
for (int i = 0; i < idProperties.length; i++)
{
sb.append(criteriaQuery.getColumn(criteria, groupByProperty + "."
+ idProperties[i]));
if (currPos >= 0)
{
sb.append(" as y").append(currPos).append('_');
currPos++;
}
if (i + 1 < idProperties.length)
{
sb.append(", ");
}
}
}
示例11: ComponentCollectionCriteriaInfoProvider
import org.hibernate.type.ComponentType; //导入依赖的package包/类
ComponentCollectionCriteriaInfoProvider(QueryableCollection persister) {
this.persister = persister;
if ( !persister.getElementType().isComponentType() ) {
throw new IllegalArgumentException( "persister for role " + persister.getRole() + " is not a collection-of-component" );
}
ComponentType componentType = (ComponentType) persister.getElementType();
String[] names = componentType.getPropertyNames();
Type[] types = componentType.getSubtypes();
for ( int i = 0; i < names.length; i++ ) {
subTypes.put( names[i], types[i] );
}
}
示例12: readRow
import org.hibernate.type.ComponentType; //导入依赖的package包/类
@Override
public Object readRow(ResultSet resultSet, ResultSetProcessingContextImpl context) throws SQLException {
final ResultSetProcessingContext.EntityReferenceProcessingState processingState =
rootReturnReader.getIdentifierResolutionContext( context );
// if the entity reference we are hydrating is a Return, it is possible that its EntityKey is
// supplied by the QueryParameter optional entity information
if ( context.shouldUseOptionalEntityInformation() && context.getQueryParameters().getOptionalId() != null ) {
EntityKey entityKey = ResultSetProcessorHelper.getOptionalObjectKey(
context.getQueryParameters(),
context.getSession()
);
processingState.registerIdentifierHydratedForm( entityKey.getIdentifier() );
processingState.registerEntityKey( entityKey );
final EntityPersister entityPersister = processingState.getEntityReference().getEntityPersister();
if ( entityPersister.getIdentifierType().isComponentType() ) {
final ComponentType identifierType = (ComponentType) entityPersister.getIdentifierType();
if ( !identifierType.isEmbedded() ) {
addKeyManyToOnesToSession(
context,
identifierType,
entityKey.getIdentifier()
);
}
}
}
return super.readRow( resultSet, context );
}
示例13: addKeyManyToOnesToSession
import org.hibernate.type.ComponentType; //导入依赖的package包/类
private void addKeyManyToOnesToSession(ResultSetProcessingContextImpl context, ComponentType componentType, Object component ) {
for ( int i = 0 ; i < componentType.getSubtypes().length ; i++ ) {
final Type subType = componentType.getSubtypes()[ i ];
final Object subValue = componentType.getPropertyValue( component, i, context.getSession() );
if ( subType.isEntityType() ) {
( (Session) context.getSession() ).buildLockRequest( LockOptions.NONE ).lock( subValue );
}
else if ( subType.isComponentType() ) {
addKeyManyToOnesToSession( context, (ComponentType) subType, subValue );
}
}
}
示例14: buildMappedIdentifierValueMarshaller
import org.hibernate.type.ComponentType; //导入依赖的package包/类
private static MappedIdentifierValueMarshaller buildMappedIdentifierValueMarshaller(
ComponentType mappedIdClassComponentType,
ComponentType virtualIdComponent) {
// so basically at this point we know we have a "mapped" composite identifier
// which is an awful way to say that the identifier is represented differently
// in the entity and in the identifier value. The incoming value should
// be an instance of the mapped identifier class (@IdClass) while the incoming entity
// should be an instance of the entity class as defined by metamodel.
//
// However, even within that we have 2 potential scenarios:
// 1) @IdClass types and entity @Id property types match
// - return a NormalMappedIdentifierValueMarshaller
// 2) They do not match
// - return a IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller
boolean wereAllEquivalent = true;
// the sizes being off is a much bigger problem that should have been caught already...
for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) {
if ( virtualIdComponent.getSubtypes()[i].isEntityType()
&& ! mappedIdClassComponentType.getSubtypes()[i].isEntityType() ) {
wereAllEquivalent = false;
break;
}
}
return wereAllEquivalent
? new NormalMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType )
: new IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType );
}
示例15: IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller
import org.hibernate.type.ComponentType; //导入依赖的package包/类
private IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller(ComponentType virtualIdComponent, ComponentType mappedIdentifierType) {
this.virtualIdComponent = virtualIdComponent;
this.mappedIdentifierType = mappedIdentifierType;
}