类org.hibernate.type.BasicType源码实例Demo

下面列出了怎么用org.hibernate.type.BasicType的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: ModelBinder.java
private void resolveLob(final SingularAttributeSourceBasic attributeSource, SimpleValue value) {
	// Resolves whether the property is LOB based on the type attribute on the attribute property source.
	// Essentially this expects the type to map to a CLOB/NCLOB/BLOB sql type internally and compares.
	if ( !value.isLob() && value.getTypeName() != null ) {
		final TypeResolver typeResolver = attributeSource.getBuildingContext().getMetadataCollector().getTypeResolver();
		final BasicType basicType = typeResolver.basic( value.getTypeName() );
		if ( basicType instanceof AbstractSingleColumnStandardBasicType ) {
			if ( isLob( ( (AbstractSingleColumnStandardBasicType) basicType ).getSqlTypeDescriptor().getSqlType(), null ) ) {
				value.makeLob();
			}
		}
	}

	// If the prior check didn't set the lob flag, this will inspect the column sql-type attribute value and
	// if this maps to CLOB/NCLOB/BLOB then the value will be marked as lob.
	if ( !value.isLob() ) {
		for ( RelationalValueSource relationalValueSource : attributeSource.getRelationalValueSources() ) {
			if ( ColumnSource.class.isInstance( relationalValueSource ) ) {
				if ( isLob( null, ( (ColumnSource) relationalValueSource ).getSqlType() ) ) {
					value.makeLob();
				}
			}
		}
	}
}
 
源代码2 项目: lams   文件: BindingTypeHelper.java
public BasicType resolveTimestampTemporalTypeVariant(Class javaType, Type baseType) {
	// prefer to use any Type already known - interprets TIMESTAMP as "no narrowing"
	if ( baseType != null && baseType instanceof BasicType ) {
		return (BasicType) baseType;
	}

	if ( Calendar.class.isAssignableFrom( javaType ) ) {
		return CalendarType.INSTANCE;
	}

	if ( java.util.Date.class.isAssignableFrom( javaType ) ) {
		return TimestampType.INSTANCE;
	}

	if ( Instant.class.isAssignableFrom( javaType ) ) {
		return InstantType.INSTANCE;
	}

	if ( OffsetDateTime.class.isAssignableFrom( javaType ) ) {
		return OffsetDateTimeType.INSTANCE;
	}

	if ( ZonedDateTime.class.isAssignableFrom( javaType ) ) {
		return ZonedDateTimeType.INSTANCE;
	}

	if ( OffsetTime.class.isAssignableFrom( javaType ) ) {
		return OffsetTimeType.INSTANCE;
	}

	throw new IllegalArgumentException( "Unsure how to handle given Java type [" + javaType.getName() + "] as TemporalType#TIMESTAMP" );
}
 
源代码3 项目: lams   文件: BindingTypeHelper.java
@SuppressWarnings("unchecked")
public BasicType resolveDateTemporalTypeVariant(Class javaType, Type baseType) {
	// prefer to use any Type already known
	if ( baseType != null && baseType instanceof BasicType ) {
		if ( baseType.getReturnedClass().isAssignableFrom( javaType ) ) {
			return (BasicType) baseType;
		}
	}

	if ( Calendar.class.isAssignableFrom( javaType ) ) {
		return CalendarDateType.INSTANCE;
	}

	if ( java.util.Date.class.isAssignableFrom( javaType ) ) {
		return TimestampType.INSTANCE;
	}

	if ( Instant.class.isAssignableFrom( javaType ) ) {
		return OffsetDateTimeType.INSTANCE;
	}

	if ( OffsetDateTime.class.isAssignableFrom( javaType ) ) {
		return OffsetDateTimeType.INSTANCE;
	}

	if ( ZonedDateTime.class.isAssignableFrom( javaType ) ) {
		return ZonedDateTimeType.INSTANCE;
	}

	throw new IllegalArgumentException( "Unsure how to handle given Java type [" + javaType.getName() + "] as TemporalType#DATE" );
}
 
源代码4 项目: lams   文件: BindingTypeHelper.java
public BasicType resolveTimeTemporalTypeVariant(Class javaType, Type baseType) {
	if ( Calendar.class.isAssignableFrom( javaType ) ) {
		return CalendarTimeType.INSTANCE;
	}

	if ( java.util.Date.class.isAssignableFrom( javaType ) ) {
		return TimestampType.INSTANCE;
	}

	throw new IllegalArgumentException( "Unsure how to handle given Java type [" + javaType.getName() + "] as TemporalType#TIME" );
}
 
源代码5 项目: lams   文件: ExportableColumn.java
public ExportableColumn(Database database, Table table, String name, BasicType type) {
	this(
			database,
			table,
			name,
			type,
			database.getDialect().getTypeName( type.sqlTypes( null )[0] )
	);
}
 
源代码6 项目: lams   文件: ExportableColumn.java
public ExportableColumn(
		Database database,
		Table table,
		String name,
		BasicType type,
		String dbTypeDeclaration) {
	super( name );
	setValue( new ValueImpl( this, table, type, database ) );
	setSqlType( dbTypeDeclaration );
}
 
源代码7 项目: lams   文件: TypeLocatorImpl.java
@Override
public BasicType basic(Class javaType) {
	BasicType type = typeResolver.basic( javaType.getName() );
	if ( type == null ) {
		final Class variant = resolvePrimitiveOrPrimitiveWrapperVariantJavaType( javaType );
		if ( variant != null ) {
			type = typeResolver.basic( variant.getName() );
		}
	}
	return type;
}
 
源代码8 项目: hibernate-types   文件: AbstractTest.java
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<>();
    configuration.put(AvailableSettings.INTERCEPTOR, interceptor());
    Integrator integrator = integrator();
    if (integrator != null) {
        configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator));
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.put("hibernate.type_contributors", (TypeContributorList) () -> {
            List<TypeContributor> typeContributors = new ArrayList<>();

            for (Type additionalType : additionalTypes) {
                if (additionalType instanceof BasicType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((BasicType) additionalType));


                } else if (additionalType instanceof UserType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((UserType) additionalType));
                } else if (additionalType instanceof CompositeUserType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((CompositeUserType) additionalType));
                }
            }
            return typeContributors;
        });
    }

    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
            new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration
    );
    return entityManagerFactoryBuilder.build();
}
 
源代码9 项目: J2Cache   文件: J2CacheMessageLogger_$logger.java
public final void typeDefinedNoRegistrationKeys(final BasicType arg0) {
    super.log.logf(FQCN, (org.jboss.logging.Logger.Level.WARN), null, typeDefinedNoRegistrationKeys$str(), arg0);
}
 
源代码10 项目: J2Cache   文件: J2CacheMessageLogger_$logger.java
public final void typeDefinedNoRegistrationKeys(BasicType arg0) {
    super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.typeDefinedNoRegistrationKeys$str(), arg0);
}
 
源代码11 项目: lams   文件: Configuration.java
/**
 * Create a {@link SessionFactory} using the properties and mappings in this configuration. The
 * SessionFactory will be immutable, so changes made to this Configuration after building the
 * SessionFactory will not affect it.
 *
 * @param serviceRegistry The registry of services to be used in creating this session factory.
 *
 * @return The built {@link SessionFactory}
 *
 * @throws HibernateException usually indicates an invalid configuration or invalid mapping information
 */
public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException {
	log.debug( "Building session factory using provided StandardServiceRegistry" );
	final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder( (StandardServiceRegistry) serviceRegistry );
	if ( implicitNamingStrategy != null ) {
		metadataBuilder.applyImplicitNamingStrategy( implicitNamingStrategy );
	}
	if ( physicalNamingStrategy != null ) {
		metadataBuilder.applyPhysicalNamingStrategy( physicalNamingStrategy );
	}
	if ( sharedCacheMode != null ) {
		metadataBuilder.applySharedCacheMode( sharedCacheMode );
	}
	if ( !typeContributorRegistrations.isEmpty() ) {
		for ( TypeContributor typeContributor : typeContributorRegistrations ) {
			metadataBuilder.applyTypes( typeContributor );
		}
	}
	if ( !basicTypes.isEmpty() ) {
		for ( BasicType basicType : basicTypes ) {
			metadataBuilder.applyBasicType( basicType );
		}
	}
	if ( sqlFunctions != null ) {
		for ( Map.Entry<String, SQLFunction> entry : sqlFunctions.entrySet() ) {
			metadataBuilder.applySqlFunction( entry.getKey(), entry.getValue() );
		}
	}
	if ( auxiliaryDatabaseObjectList != null ) {
		for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : auxiliaryDatabaseObjectList ) {
			metadataBuilder.applyAuxiliaryDatabaseObject( auxiliaryDatabaseObject );
		}
	}
	if ( attributeConverterDefinitionsByClass != null ) {
		for ( AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitionsByClass.values() ) {
			metadataBuilder.applyAttributeConverter( attributeConverterDefinition );
		}
	}

	final Metadata metadata = metadataBuilder.build();

	final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
	if ( interceptor != null && interceptor != EmptyInterceptor.INSTANCE ) {
		sessionFactoryBuilder.applyInterceptor( interceptor );
	}
	if ( getSessionFactoryObserver() != null ) {
		sessionFactoryBuilder.addSessionFactoryObservers( getSessionFactoryObserver() );
	}
	if ( getEntityNotFoundDelegate() != null ) {
		sessionFactoryBuilder.applyEntityNotFoundDelegate( getEntityNotFoundDelegate() );
	}
	if ( getEntityTuplizerFactory() != null ) {
		sessionFactoryBuilder.applyEntityTuplizerFactory( getEntityTuplizerFactory() );
	}
	if ( getCurrentTenantIdentifierResolver() != null ) {
		sessionFactoryBuilder.applyCurrentTenantIdentifierResolver( getCurrentTenantIdentifierResolver() );
	}

	return sessionFactoryBuilder.build();
}
 
源代码12 项目: lams   文件: BindingTypeHelper.java
public BasicType determineTypeForTemporalType(TemporalType temporalType, Type baseType, Object bindValue) {
	// todo : for 6.0 make TemporalType part of org.hibernate.type.descriptor.java.JdbcRecommendedSqlTypeMappingContext
	//		then we can just ask the org.hibernate.type.basic.BasicTypeFactory to handle this based on its registry
	//
	//   - or for 6.0 make TemporalType part of the state for those BasicType impls dealing with date/time types
	//
	// 	 - or for 6.0 make TemporalType part of Binder contract
	//
	//   - or add a org.hibernate.type.TemporalType#getVariant(TemporalType)
	//
	//	 - or ...

	// todo : (5.2) review Java type handling for sanity.  This part was done quickly ;)

	final Class javaType;

	// Determine the "value java type" :
	// 		prefer to leverage the bindValue java type (if bindValue not null),
	// 		followed by the java type reported by the baseType,
	// 		fallback to java.sql.Timestamp

	if ( bindValue != null ) {
		javaType = bindValue.getClass();
	}
	else if ( baseType != null ) {
		javaType = baseType.getReturnedClass();
	}
	else {
		javaType = java.sql.Timestamp.class;
	}

	switch ( temporalType ) {
		case TIMESTAMP: {
			return resolveTimestampTemporalTypeVariant( javaType, baseType );
		}
		case DATE: {
			return resolveDateTemporalTypeVariant( javaType, baseType );
		}
		case TIME: {
			return resolveTimeTemporalTypeVariant( javaType, baseType );
		}
		default: {
			throw new IllegalArgumentException( "Unexpected TemporalType [" + temporalType + "]; expecting TIMESTAMP, DATE or TIME" );
		}
	}
}
 
源代码13 项目: lams   文件: ExportableColumn.java
public ValueImpl(ExportableColumn column, Table table, BasicType type, Database database) {
	this.column = column;
	this.table = table;
	this.type = type;
	this.database = database;
}
 
源代码14 项目: lams   文件: TypeLocatorImpl.java
@Override
public BasicType basic(String name) {
	return typeResolver.basic( name );
}
 
源代码15 项目: lams   文件: CoreMessageLogger.java
@LogMessage(level = WARN)
@Message(value = "Type [%s] defined no registration keys; ignoring", id = 269)
void typeDefinedNoRegistrationKeys(BasicType type);
 
@Override
public MetadataBuilder applyBasicType(BasicType type) {
	delegate.applyBasicType( type );
	return getThis();
}
 
@Override
public MetadataBuilder applyBasicType(BasicType type, String... keys) {
	delegate.applyBasicType( type, keys );
	return getThis();
}
 
源代码18 项目: lams   文件: BasicTypeRegistration.java
public BasicTypeRegistration(BasicType basicType) {
	this( basicType, basicType.getRegistrationKeys() );
}
 
源代码19 项目: lams   文件: BasicTypeRegistration.java
public BasicTypeRegistration(BasicType basicType, String[] registrationKeys) {
	this.basicType = basicType;
	this.registrationKeys = registrationKeys;
}
 
源代码20 项目: lams   文件: BasicTypeRegistration.java
public BasicType getBasicType() {
	return basicType;
}
 
源代码21 项目: lams   文件: MetadataBuilderImpl.java
@Override
public MetadataBuilder applyBasicType(BasicType type) {
	options.basicTypeRegistrations.add( new BasicTypeRegistration( type ) );
	return this;
}
 
源代码22 项目: lams   文件: MetadataBuilderImpl.java
@Override
public MetadataBuilder applyBasicType(BasicType type, String... keys) {
	options.basicTypeRegistrations.add( new BasicTypeRegistration( type, keys ) );
	return this;
}
 
源代码23 项目: lams   文件: MetadataBuilderImpl.java
@Override
public void contributeType(BasicType type) {
	options.basicTypeRegistrations.add( new BasicTypeRegistration( type ) );
}
 
源代码24 项目: lams   文件: MetadataBuilderImpl.java
@Override
public void contributeType(BasicType type, String... keys) {
	options.basicTypeRegistrations.add( new BasicTypeRegistration( type, keys ) );
}
 
源代码25 项目: hibernate-types   文件: AbstractTest.java
private SessionFactory newSessionFactory() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
            .enableAutoClose();

    Integrator integrator = integrator();
    if (integrator != null) {
        bsrb.applyIntegrator(integrator);
    }

    final BootstrapServiceRegistry bsr = bsrb.build();

    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
            .applySettings(properties())
            .build();

    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    for (Class annotatedClass : entities()) {
        metadataSources.addAnnotatedClass(annotatedClass);
    }

    String[] packages = packages();
    if (packages != null) {
        for (String annotatedPackage : packages) {
            metadataSources.addPackage(annotatedPackage);
        }
    }

    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            metadataSources.addResource(resource);
        }
    }

    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
    metadataBuilder.enableNewIdentifierGeneratorSupport(true);
    metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        additionalTypes.stream().forEach(type -> {
            metadataBuilder.applyTypes((typeContributions, serviceRegistry1) -> {
                if(type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType ){
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}
 
源代码26 项目: hibernate-types   文件: AbstractTest.java
private SessionFactory newLegacySessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor((typeContributions, serviceRegistry) -> {
            additionalTypes.stream().forEach(type -> {
                if (type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType) {
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
源代码27 项目: hibernate-types   文件: AbstractTest.java
private SessionFactory newSessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor(new TypeContributor() {
            @Override
            public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                for (Type type : additionalTypes) {
                    if (type instanceof BasicType) {
                        typeContributions.contributeType((BasicType) type);
                    } else if (type instanceof UserType) {
                        typeContributions.contributeType((UserType) type, new String[]{type.getName()});
                    } else if (type instanceof CompositeUserType) {
                        typeContributions.contributeType((CompositeUserType) type, new String[]{type.getName()});
                    }
                }
            }
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
源代码28 项目: hibernate-types   文件: AbstractTest.java
private SessionFactory newLegacySessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor(new TypeContributor() {
            @Override
            public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                for (Type type : additionalTypes) {
                    if (type instanceof BasicType) {
                        typeContributions.contributeType((BasicType) type);
                    } else if (type instanceof UserType) {
                        typeContributions.contributeType((UserType) type);
                    } else if (type instanceof CompositeUserType) {
                        typeContributions.contributeType((CompositeUserType) type);
                    }
                }
            }
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
源代码29 项目: gorm-hibernate5   文件: HibernateQuery.java
protected String render(BasicType basic, List<String> columns, SessionFactory sessionFactory, SQLFunction sqlFunction) {
    return sqlFunction.render(basic, columns, (SessionFactoryImplementor) sessionFactory);
}
 
private SessionFactory newSessionFactory() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
        .enableAutoClose();

    Integrator integrator = integrator();
    if (integrator != null) {
        bsrb.applyIntegrator( integrator );
    }

    final BootstrapServiceRegistry bsr = bsrb.build();

    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
        .applySettings(properties())
        .build();

    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    for (Class annotatedClass : entities()) {
        metadataSources.addAnnotatedClass(annotatedClass);
    }

    String[] packages = packages();
    if (packages != null) {
        for (String annotatedPackage : packages) {
            metadataSources.addPackage(annotatedPackage);
        }
    }

    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            metadataSources.addResource(resource);
        }
    }

    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder()
    .enableNewIdentifierGeneratorSupport(true)
    .applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        additionalTypes.stream().forEach(type -> {
            metadataBuilder.applyTypes((typeContributions, sr) -> {
                if(type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType ){
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }

    additionalMetadata(metadataBuilder);

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if(interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}
 
 类所在包
 类方法
 同包方法