/** * Constructs a new {@link SessionFactory} by initialising the object-graph mapping meta-data from the given list of domain * object packages, and also sets the baseConfiguration to be used. * <p> * The package names passed to this constructor should not contain wildcards or trailing full stops, for example, * "org.springframework.data.neo4j.example.domain" would be fine. The default behaviour is for sub-packages to be scanned * and you can also specify fully-qualified class names if you want to cherry pick particular classes. * </p> * Indexes will also be checked or built unless auto index mode is set to <code>NONE</code>. * * @param configuration The baseConfiguration to use * @param packages The packages to scan for domain objects. They will be merged with the configuration. */ public SessionFactory(Configuration configuration, String... packages) { this(newConfiguredDriverInstance(configuration), configuration.mergeBasePackagesWith(packages)); if (configuration.getAutoIndex() != NONE) { runAutoIndexManager(configuration); } }
@Test public void testAutoIndexDumpCreatesIndex() throws IOException { File file = File.createTempFile("test", ".cql"); file.deleteOnExit(); Configuration configuration = getBaseConfiguration() .autoIndex("dump") .generatedIndexesOutputDir(file.getParent()) .generatedIndexesOutputFilename(file.getName()) .build(); sessionFactory.runAutoIndexManager(configuration); assertThat(file).exists().canRead(); assertThat(contentOf(file)) .contains(Arrays.stream(expectedIndexDefinitions).map(d -> "CREATE " + d).toArray(String[]::new)); }
void runAutoIndex(String mode) { Configuration configuration = getBaseConfiguration().autoIndex(mode).build(); sessionFactory.runAutoIndexManager(configuration); }
@Test public void indexesShouldBeCreatedForLoadableClassesInHierarchy() { final IndexDescription[] expectedIndexes = new IndexDescription[] { new IndexDescription("DefaultUser", "id"), new IndexDescription("Admin", "id"), new IndexDescription("ChildA", "uuid"), new IndexDescription("ChildB", "uuid"), new IndexDescription("ChildC", "uuid"), new IndexDescription("LabeledEntity", "uuid"), new IndexDescription("EntityWithImplicitPlusAdditionalLabels", "id") }; sessionFactory.runAutoIndexManager(getBaseConfiguration().autoIndex(AutoIndexMode.UPDATE.name()).build()); GraphDatabaseService service = getGraphDatabaseService(); try (Transaction tx = service.beginTx()) { IndexDescription[] indexes = StreamSupport.stream(service.schema().getIndexes().spliterator(), false) .map(IndexDescription::new).toArray(IndexDescription[]::new); assertThat(indexes).containsExactlyInAnyOrder(expectedIndexes); tx.success(); } }