Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.dropwizard.hibernate;
 
 
Extension of HibernateBundle that scans given package for entities instead of giving them by hand.
public abstract class ScanningHibernateBundle<T extends Configurationextends HibernateBundle<T> {
    

Parameters:
pckg string with package containing Hibernate entities (classes annotated with Hibernate @Entity annotation) e. g. com.codahale.fake.db.directory.entities
    protected ScanningHibernateBundle(String pckg) {
        this(pckgnew SessionFactoryFactory());
    }
    protected ScanningHibernateBundle(String pckgSessionFactoryFactory sessionFactoryFactory) {
        super(findEntityClassesFromDirectory(pckg), sessionFactoryFactory);
    }

    
Method scanning given directory for classes containing Hibernate

Parameters:
pckg string with package containing Hibernate entities (classes annotated with @Entity annotation) e.g. com.codahale.fake.db.directory.entities
Returns:
ImmutableList with classes from given directory annotated with Hibernate @Entity annotation
Entity:
annotation
    public static ImmutableList<Class<?>> findEntityClassesFromDirectory(String pckg) {
        @SuppressWarnings("unchecked")
        final AnnotationAcceptingListener asl = new AnnotationAcceptingListener(Entity.class);
        final PackageNamesScanner scanner = new PackageNamesScanner(new String[]{pckg}, true);
        while (scanner.hasNext()) {
            final String next = scanner.next();
            if (asl.accept(next)) {
                try (final InputStream in = scanner.open()) {
                    asl.process(nextin);
                } catch (IOException e) {
                    throw new RuntimeException("AnnotationAcceptingListener failed to process scanned resource: " + next);
                }
            }
        }
        final Builder<Class<?>> builder = ImmutableList.builder();
        for (Class<?> clazz : asl.getAnnotatedClasses()) {
            builder.add(clazz);
        }
        return builder.build();
    }
New to GrepCode? Check out our FAQ X