org.hibernate.mapping.Property.getType()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中org.hibernate.mapping.Property.getType()方法的一些代码示例,展示了Property.getType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Property.getType()方法的具体详情如下:
包路径:org.hibernate.mapping.Property
类名称:Property
方法名:getType

Property.getType介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

private static boolean isSameType(Property left, Property right) {
  return left.getType().getName().equals( right.getType().getName() );
}

代码示例来源:origin: hibernate/hibernate-orm

public boolean isPlural() {
  return propertyMapping.getType().isCollectionType();
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public org.hibernate.type.Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
  final PersistentClass pc = entityBindingMap.get( entityName );
  if ( pc == null ) {
    throw new MappingException( "persistent class not known: " + entityName );
  }
  Property prop = pc.getReferencedProperty( propertyName );
  if ( prop == null ) {
    throw new MappingException(
        "property not known: " +
            entityName + '.' + propertyName
    );
  }
  return prop.getType();
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public org.hibernate.type.Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
  final PersistentClass pc = entityBindingMap.get( entityName );
  if ( pc == null ) {
    throw new MappingException( "persistent class not known: " + entityName );
  }
  Property prop = pc.getReferencedProperty( propertyName );
  if ( prop == null ) {
    throw new MappingException(
        "property not known: " +
            entityName + '.' + propertyName
    );
  }
  return prop.getType();
}

代码示例来源:origin: hibernate/hibernate-orm

public static LazyAttributeDescriptor from(
    Property property,
    int attributeIndex,
    int lazyIndex) {
  String fetchGroupName = property.getLazyGroup();
  if ( fetchGroupName == null ) {
    fetchGroupName = property.getType().isCollectionType()
        ? property.getName()
        : "DEFAULT";
  }
  return new LazyAttributeDescriptor(
      attributeIndex,
      lazyIndex,
      property.getName(),
      property.getType(),
      fetchGroupName
  );
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public Comparator getOwnerVersionComparator() {
  if ( !isVersioned() ) {
    return null;
  }
  return ( (VersionType) collectionDescriptor.getOwner().getVersion().getType() ).getComparator();
}

代码示例来源:origin: hibernate/hibernate-orm

public void validate(Mapping mapping) throws MappingException {
  Iterator iter = getPropertyIterator();
  while ( iter.hasNext() ) {
    Property prop = (Property) iter.next();
    if ( !prop.isValid( mapping ) ) {
      throw new MappingException(
          "property mapping has wrong number of columns: " +
              StringHelper.qualify( getEntityName(), prop.getName() ) +
              " type: " +
              prop.getType().getName()
      );
    }
  }
  checkPropertyDuplication();
  checkColumnDuplication();
}

代码示例来源:origin: hibernate/hibernate-orm

private void validateEnumMapping(Property property, EnumType expectedJpaEnumType) {
  assertThat( property.getType(), instanceOf( CustomType.class ) );
  final CustomType customType = (CustomType) property.getType();
  assertThat( customType.getUserType(), instanceOf( org.hibernate.type.EnumType.class ) );
  final org.hibernate.type.EnumType hibernateMappingEnumType = (org.hibernate.type.EnumType) customType.getUserType();
  assertThat( hibernateMappingEnumType.isOrdinal(), is(expectedJpaEnumType==EnumType.ORDINAL) );
  assertThat( hibernateMappingEnumType.sqlTypes().length, is(1) );
  assertThat( hibernateMappingEnumType.sqlTypes()[0], is(expectedJpaEnumType==EnumType.ORDINAL? Types.INTEGER:Types.VARCHAR) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public Member resolveMember(AttributeContext attributeContext) {
    final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
    final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType );
    if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) {
      throw new IllegalArgumentException( "expecting IdClass mapping" );
    }
    org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType();
    if ( !EmbeddedComponentType.class.isInstance( type ) ) {
      throw new IllegalArgumentException( "expecting IdClass mapping" );
    }
    final EmbeddedComponentType componentType = (EmbeddedComponentType) type;
    final String attributeName = attributeContext.getPropertyMapping().getName();
    final Getter getter = componentType.getComponentTuplizer()
        .getGetter( componentType.getPropertyIndex( attributeName ) );
    return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter )
        ? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() )
        : getter.getMember();
  }
};

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public Member resolveMember(AttributeContext attributeContext) {
    final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
    final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType );
    final String versionPropertyName = attributeContext.getPropertyMapping().getName();
    if ( !versionPropertyName.equals( entityMetamodel.getVersionProperty().getName() ) ) {
      // this should never happen, but to be safe...
      throw new IllegalArgumentException( "Given property did not match declared version property" );
    }
    final Getter getter = entityMetamodel.getTuplizer().getVersionGetter();
    if ( PropertyAccessMapImpl.GetterImpl.class.isInstance( getter ) ) {
      return new MapMember(
          versionPropertyName,
          attributeContext.getPropertyMapping().getType().getReturnedClass()
      );
    }
    else {
      return getter.getMember();
    }
  }
};

代码示例来源:origin: hibernate/hibernate-orm

private void assertTimestampSource(Class<?> clazz, Class<?> expectedTypeClass) throws Exception {
    PersistentClass persistentClass = metadata.getEntityBinding( clazz.getName() );
    assertNotNull( persistentClass );
    Property versionProperty = persistentClass.getVersion();
    assertNotNull( versionProperty );
    assertEquals( "Wrong timestamp type", expectedTypeClass, versionProperty.getType().getClass() );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

private void dump(PersistentClass entityBinding, TheEntity theEntity) {
  final Iterator propertyBindingIterator = entityBinding.getPropertyClosureIterator();
  while ( propertyBindingIterator.hasNext() ) {
    final Property propertyBinding = (Property) propertyBindingIterator.next();
    final JavaTypeDescriptor javaTypeDescriptor = ( (AbstractStandardBasicType) propertyBinding.getType() ).getJavaTypeDescriptor();
    System.out.println(
        String.format(
            "%s (%s) -> %s",
            propertyBinding.getName(),
            javaTypeDescriptor.getJavaType().getSimpleName(),
            javaTypeDescriptor.toString( propertyBinding.getGetter( TheEntity.class ).get( theEntity ) )
        )
    );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public Member resolveMember(AttributeContext attributeContext) {
    final EmbeddedTypeDescriptor embeddableType = (EmbeddedTypeDescriptor<?>) attributeContext.getOwnerType();
    final String attributeName = attributeContext.getPropertyMapping().getName();
    final Getter getter = embeddableType.getHibernateType()
        .getComponentTuplizer()
        .getGetter( embeddableType.getHibernateType().getPropertyIndex( attributeName ) );
    return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter )
        ? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() )
        : getter.getMember();
  }
};

代码示例来源:origin: hibernate/hibernate-orm

@Override
public void prepare(MetadataImplementor metadata) {
  if ( callbackBuilder == null ) {
    // TODO : not needed anymore when the deprecate constructor will be removed
    this.callbackBuilder = CallbacksFactory.buildCallbackBuilder( sessionFactory, metadata.getMetadataBuildingOptions().getReflectionManager()
    );
  }
  for ( PersistentClass persistentClass : metadata.getEntityBindings() ) {
    if ( persistentClass.getClassName() == null ) {
      // we can have non java class persisted by hibernate
      continue;
    }
    callbackBuilder.buildCallbacksForEntity( persistentClass.getClassName(), callbackRegistry );
    for ( Iterator propertyIterator = persistentClass.getDeclaredPropertyIterator();
        propertyIterator.hasNext(); ) {
      Property property = (Property) propertyIterator.next();
      if ( property.getType().isComponentType() ) {
        callbackBuilder.buildCallbacksForEmbeddable(
            property,
            persistentClass.getClassName(),
            callbackRegistry
        );
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testTypeDefinition() {
  PersistentClass pc = metadata().getEntityBinding( EntitySerialize.class.getName() );
  // explicitLob of SerializableToBlobType
  Type explicitLobType = pc.getProperty( "explicitLob" ).getType();
  assertEquals( ExplicitSerializable.class, explicitLobType.getReturnedClass() );
  assertEquals( SerializableToBlobType.class.getName(), explicitLobType.getName() );
  // explicit of ExplicitSerializableType
  Type explicitType = pc.getProperty( "explicit" ).getType();
  assertEquals( ExplicitSerializable.class, explicitType.getReturnedClass() );
  assertEquals( ExplicitSerializableType.class.getName(), explicitType.getName() );
  // implicit of ImplicitSerializableType
  Type implicitType = pc.getProperty( "implicit" ).getType();
  assertEquals( ImplicitSerializable.class, implicitType.getReturnedClass() );
  assertEquals( ImplicitSerializableType.class.getName(), implicitType.getName() );
  // explicitOverridingImplicit ExplicitSerializableType overrides ImplicitSerializableType
  Type overrideType = pc.getProperty( "explicitOverridingImplicit" ).getType();
  assertEquals( ImplicitSerializable.class, overrideType.getReturnedClass() );
  assertEquals( ExplicitSerializableType.class.getName(), overrideType.getName() );
}

代码示例来源:origin: hibernate/hibernate-orm

private void check(
    Class<? extends Dialect> dialectClass,
    Class entityClass,
    Class<? extends Type> binaryTypeClass,
    Class<? extends Type> charTypeClass,
    boolean preferLongRaw) {
  StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
      .applySetting( AvailableSettings.DIALECT, dialectClass.getName() )
      .applySetting( Oracle12cDialect.PREFER_LONG_RAW, Boolean.toString( preferLongRaw ) )
      .applySetting( "hibernate.temp.use_jdbc_metadata_defaults", false )
      .build();
  try {
    final MetadataImplementor mappings = (MetadataImplementor) new MetadataSources( ssr )
        .addAnnotatedClass( entityClass )
        .buildMetadata();
    mappings.validate();
    final PersistentClass entityBinding = mappings.getEntityBinding( entityClass.getName() );
    assertThat( entityBinding.getProperty( "binaryData" ).getType(), instanceOf( binaryTypeClass ) );
    assertThat( entityBinding.getProperty( "characterData" ).getType(), instanceOf( charTypeClass ) );
  }
  finally {
    StandardServiceRegistryBuilder.destroy( ssr );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testMappingAttributeWithLobAndAttributeConverter() {
  final Metadata metadata = new MetadataSources( ssr )
      .addAnnotatedClass( EntityImpl.class )
      .buildMetadata();
  final Type type = metadata.getEntityBinding( EntityImpl.class.getName() ).getProperty( "status" ).getType();
  final AttributeConverterTypeAdapter concreteType = assertTyping( AttributeConverterTypeAdapter.class, type );
  assertEquals( Types.BLOB, concreteType.getSqlTypeDescriptor().getSqlType() );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-9599")
public void basicTest() {
  StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
  try {
    Metadata metadata = new MetadataSources( ssr ).addAnnotatedClass( TestEntity.class ).buildMetadata();
    ( (MetadataImpl) metadata ).validate();
    final PersistentClass entityBinding = metadata.getEntityBinding( TestEntity.class.getName() );
    if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect
        || metadata.getDatabase().getDialect() instanceof DB2Dialect){
      // See issue HHH-10693 for PostgreSQL, HHH-12753 for DB2
      assertEquals(
          Types.VARCHAR,
          entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0]
      );
    }else {
      assertEquals(
          Types.NVARCHAR,
          entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0]
      );
    }
  }
  finally {
    StandardServiceRegistryBuilder.destroy( ssr );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
  public void testOrmXmlDefinedEnumType() {
    StandardServiceRegistry ssr = ServiceRegistryBuilder.buildServiceRegistry();

    try {
      MetadataSources ms = new MetadataSources( ssr );
      ms.addResource( "org/hibernate/test/annotations/enumerated/ormXml/orm.xml" );

      Metadata metadata = ms.buildMetadata();

      Type bindingPropertyType = metadata.getEntityBinding( BookWithOrmEnum.class.getName() )
          .getProperty( "bindingStringEnum" )
          .getType();
      CustomType customType = ExtraAssertions.assertTyping( CustomType.class, bindingPropertyType );
      EnumType enumType = ExtraAssertions.assertTyping( EnumType.class, customType.getUserType() );
      assertFalse( enumType.isOrdinal() );
    }
    finally {
      ServiceRegistryBuilder.destroy( ssr );
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testHHH10128() {
  final Metadata metadata = new MetadataSources( ssr )
      .addAnnotatedClass( Entity.class )
      .addAnnotatedClass( DescriptionEntity.class )
      .addAnnotatedClass( AddressLevel.class )
      .buildMetadata();
  final PersistentClass addressLevelBinding = metadata.getEntityBinding( AddressLevel.class.getName() );
  final Property natureProperty = addressLevelBinding.getProperty( "nature" );
  CustomType customType = assertTyping( CustomType.class, natureProperty.getType() );
  EnumType enumType = assertTyping( EnumType.class, customType.getUserType() );
  assertEquals( Types.VARCHAR, enumType.sqlTypes()[0] );
  SessionFactoryImplementor sf = (SessionFactoryImplementor) metadata.buildSessionFactory();
  try {
    EntityPersister p = sf.getEntityPersister( AddressLevel.class.getName() );
    CustomType runtimeType = assertTyping( CustomType.class, p.getPropertyType( "nature" ) );
    EnumType runtimeEnumType = assertTyping( EnumType.class, runtimeType.getUserType() );
    assertEquals( Types.VARCHAR, runtimeEnumType.sqlTypes()[0] );
  }
  finally {
    sf.close();
  }
}

相关文章

微信公众号

最新文章

更多