private Block metadataBuilder() { return unit -> { MetadataBuilder mb = unit.get(MetadataBuilder.class); expect(mb.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)) .andReturn(mb); expect(mb.applyScanEnvironment(unit.get(ScanEnvironment.class))).andReturn(mb); SessionFactoryBuilder sfb = unit.mock(SessionFactoryBuilder.class); unit.registerMock(SessionFactoryBuilder.class, sfb); Metadata md = unit.mock(Metadata.class); expect(md.getSessionFactoryBuilder()).andReturn(sfb); expect(mb.build()).andReturn(md); unit.registerMock(Metadata.class, md); }; }
@Override public void contribute(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) { DialectResolver dialectResolver = serviceRegistry.getService(DialectResolver.class); if ((dialectResolver instanceof DialectResolverSet)) { ((DialectResolverSet) dialectResolver).addResolver(resolver); } }
@Before public void setup() { initializer = new SQLiteMetadataBuilderInitializer(); metadataBuilder = mock(MetadataBuilder.class); registry = mock(StandardServiceRegistry.class); resolver = mock(DialectResolverSet.class); when(registry.getService(DialectResolver.class)).thenReturn(resolver); }
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); MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build(); final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); Interceptor interceptor = interceptor(); if (interceptor != null) { sfb.applyInterceptor(interceptor); } return sfb.build(); }
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(); }
@SuppressWarnings("rawtypes") private Block metadataSources(final Object... resources) { return unit -> { StandardServiceRegistry ssr = unit.get(StandardServiceRegistry.class); MetadataSources sources = unit.constructor(MetadataSources.class) .build(ssr); unit.registerMock(MetadataSources.class, sources); List<String> packages = Arrays.asList(resources) .stream() .filter(String.class::isInstance) .map(s -> s.toString()) .collect(Collectors.toList()); List<Class> classes = Arrays.asList(resources) .stream() .filter(Class.class::isInstance) .map(it -> (Class) it) .collect(Collectors.toList()); MetadataBuilder mb = unit.mock(MetadataBuilder.class); unit.registerMock(MetadataBuilder.class, mb); expect(sources.getAnnotatedPackages()).andReturn(packages); expect(sources.getMetadataBuilder()).andReturn(mb); packages.forEach(c -> { expect(sources.addPackage(c)).andReturn(sources); }); classes.forEach(c -> { expect(sources.addAnnotatedClass(c)).andReturn(sources); }); List<URL> urls = packages .stream() .map(pkg -> getClass().getResource("/" + pkg.replace('.', '/'))) .collect(Collectors.toList()); ScanEnvImpl scanenv = unit.constructor(ScanEnvImpl.class) .build(urls); unit.registerMock(ScanEnvironment.class, scanenv); }; }