Java 类org.hibernate.usertype.UserType 实例源码

项目:lams    文件:TypeFactory.java   
public Type byClass(Class clazz, Properties parameters) {
    if ( Type.class.isAssignableFrom( clazz ) ) {
        return type( clazz, parameters );
    }

    if ( CompositeUserType.class.isAssignableFrom( clazz ) ) {
        return customComponent( clazz, parameters );
    }

    if ( UserType.class.isAssignableFrom( clazz ) ) {
        return custom( clazz, parameters );
    }

    if ( Lifecycle.class.isAssignableFrom( clazz ) ) {
        // not really a many-to-one association *necessarily*
        return manyToOne( clazz.getName() );
    }

    if ( Serializable.class.isAssignableFrom( clazz ) ) {
        return serializable( clazz );
    }

    return null;
}
项目:lams    文件:TypeFactory.java   
/**
 * @deprecated Only for use temporary use by {@link org.hibernate.Hibernate}
 */
@Deprecated
   public static CustomType custom(Class<UserType> typeClass, Properties parameters, TypeScope scope) {
    try {
        UserType userType = typeClass.newInstance();
        injectParameters( userType, parameters );
        return new CustomType( userType );
    }
    catch ( Exception e ) {
        throw new MappingException( "Unable to instantiate custom type: " + typeClass.getName(), e );
    }
}
项目:lams    文件:CustomType.java   
public CustomType(UserType userType, String[] registrationKeys) throws MappingException {
    this.userType = userType;
    this.name = userType.getClass().getName();
    this.types = userType.sqlTypes();
    this.dictatedSizes = Sized.class.isInstance( userType )
            ? ( (Sized) userType ).dictatedSizes()
            : new Size[ types.length ];
    this.defaultSizes = Sized.class.isInstance( userType )
            ? ( (Sized) userType ).defaultSizes()
            : new Size[ types.length ];
    this.customLogging = LoggableUserType.class.isInstance( userType );
    this.registrationKeys = registrationKeys;
}
项目:cacheonix-core    文件:CustomType.java   
public CustomType(Class userTypeClass, Properties parameters) throws MappingException {

        if ( !UserType.class.isAssignableFrom( userTypeClass ) ) {
            throw new MappingException(
                    "Custom type does not implement UserType: " +
                    userTypeClass.getName()
                );
        }

        name = userTypeClass.getName();

        try {
            userType = ( UserType ) userTypeClass.newInstance();
        }
        catch ( InstantiationException ie ) {
            throw new MappingException(
                    "Cannot instantiate custom type: " +
                    userTypeClass.getName()
                );
        }
        catch ( IllegalAccessException iae ) {
            throw new MappingException(
                    "IllegalAccessException trying to instantiate custom type: " +
                    userTypeClass.getName()
                );
        }

        TypeFactory.injectParameters( userType, parameters );
        types = userType.sqlTypes();

        customLogging = LoggableUserType.class.isAssignableFrom( userTypeClass );
    }
项目:openeos    文件:BundleModelClassConfigurator.java   
private void checkForCreateListTypeType(Configuration conf, final Class<?> propertyType) throws NoSuchMethodException,
        IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
    if (!listTypeProxyCreatedSet.contains(propertyType)) {
        ProxyFactory factory = new ProxyFactory();
        factory.setSuperclass(ListTypeUserType.class);
        factory.setFilter(new MethodFilter() {

            @Override
            public boolean isHandled(Method method) {
                return Modifier.isAbstract(method.getModifiers());
            }
        });
        MethodHandler handler = new MethodHandler() {

            @Override
            public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
                if (thisMethod.getName().equals("returnedClass") && args.length == 0) {
                    LOG.debug("Handling method returnedClass() of type ListTypeUserType", thisMethod);
                    return propertyType;
                } else {
                    throw new UnsupportedOperationException();
                }
            }

        };
        Object type = factory.create(new Class<?>[0], new Object[0], handler);
        conf.registerTypeOverride((UserType) type, new String[] { propertyType.getSimpleName(), propertyType.getName() });
        listTypeProxyCreatedSet.add(propertyType);
    }
}
项目:lams    文件:Configuration.java   
public void registerTypeOverride(UserType type, String[] keys) {
    getTypeResolver().registerTypeOverride( type, keys );
}
项目:lams    文件:TypeResolver.java   
public void registerTypeOverride(UserType type, String[] keys) {
    basicTypeRegistry.register( type, keys );
}
项目:lams    文件:TypeFactory.java   
public CustomType custom(Class<UserType> typeClass, Properties parameters) {
    return custom( typeClass, parameters, typeScope );
}
项目:lams    文件:CustomType.java   
public CustomType(UserType userType) throws MappingException {
    this( userType, ArrayHelper.EMPTY_STRING_ARRAY );
}
项目:lams    文件:CustomType.java   
public UserType getUserType() {
    return userType;
}
项目:lams    文件:BasicTypeRegistry.java   
public void register(UserType type, String[] keys) {
    register( new CustomType( type, keys ) );
}
项目: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()
    );
}
项目: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()
    );
}
项目: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()
    );
}
项目:cacheonix-core    文件:TypeFactory.java   
/**
 * Uses heuristics to deduce a Hibernate type given a string naming the type or Java class.
 * Return an instance of <tt>org.hibernate.type.Type</tt>.
 */
public static Type heuristicType(String typeName, Properties parameters)
        throws MappingException {
    Type type = TypeFactory.basic( typeName );
    if ( type == null ) {
        Class typeClass;
        try {
            typeClass = ReflectHelper.classForName( typeName );
        }
        catch (ClassNotFoundException cnfe) {
            typeClass = null;
        }
        if ( typeClass != null ) {
            if ( Type.class.isAssignableFrom( typeClass ) ) {
                try {
                    type = (Type) typeClass.newInstance();
                }
                catch (Exception e) {
                    throw new MappingException( 
                            "Could not instantiate Type: " + typeClass.getName(),
                            e 
                        );
                }
                injectParameters(type, parameters);
            }
            else if ( CompositeUserType.class.isAssignableFrom( typeClass ) ) {
                type = new CompositeCustomType( typeClass, parameters );
            }
            else if ( UserType.class.isAssignableFrom( typeClass ) ) {
                type = new CustomType( typeClass, parameters );
            }
            else if ( Lifecycle.class.isAssignableFrom( typeClass ) ) {
                type = Hibernate.entity( typeClass );
            }
            else if ( Serializable.class.isAssignableFrom( typeClass ) ) {
                type = Hibernate.serializable( typeClass );
            }
        }
    }
    return type;

}
项目:gisgraphy    文件:PostgisDialectNG.java   
public UserType getGeometryUserType() {
    return new PGGeometryUserType();
}
项目:gisgraphy    文件:PostgisDialectNG2.java   
public UserType getGeometryUserType() {
    return new PGGeometryUserType();
}
项目:high-performance-java-persistence    文件: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();
}
项目:high-performance-java-persistence    文件: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()
    );
}
项目:jadira    文件:AbstractUserTypeHibernateIntegrator.java   
private void registerType(Configuration configuration, UserType type) {
    String className = type.returnedClass().getName();
    configuration.registerTypeOverride(type, new String[] {className});
}
项目:jadira    文件:AbstractUserTypeHibernateIntegrator.java   
private void registerType(MetadataImplementor mi, UserType type) {
    String className = type.returnedClass().getName();
    mi.getTypeResolver().registerTypeOverride(type, new String[] {className});
}
项目:jadira    文件:UserTypeJodaTimeHibernateIntegrator.java   
/**
 * {@inheritDoc}
 */
@Override
protected UserType[] getUserTypes() {
    return userTypes;
}
项目:jadira    文件:UserTypeThreeTenHibernateIntegrator.java   
/**
 * {@inheritDoc}
 */
@Override
protected UserType[] getUserTypes() {
    return userTypes;
}
项目:jadira    文件:UserTypeJodaMoneyHibernateIntegrator.java   
/**
 * {@inheritDoc}
 */
@Override
protected UserType[] getUserTypes() {
    return userTypes;
}
项目:jadira    文件:UserTypeMonetaMoneyHibernateIntegrator.java   
/**
 * {@inheritDoc}
 */
@Override
protected UserType[] getUserTypes() {
    return userTypes;
}
项目:jadira    文件:UserTypeLegacyJdkMoneyHibernateIntegrator.java   
/**
 * {@inheritDoc}
 */
@Override
protected UserType[] getUserTypes() {
    return userTypes;
}
项目:stdlib    文件:HibernateModule.java   
private void registerType(Configuration configuration, UserType type)
{
    String className = type.returnedClass().getName();
    configuration.registerTypeOverride(type, new String[]{className});
}
项目:geomajas-project-server    文件:HSQLSpatialDialect.java   
public UserType getGeometryUserType() {
    return new HsqlGeometryUserType();
}
项目:lams    文件:TypeContributions.java   
public void contributeType(UserType type, String[] keys);
项目:jadira    文件:AbstractUserTypeHibernateIntegrator.java   
protected abstract UserType[] getUserTypes();