/** * Creates a new {@link Neo4jAuditingEventListener} using the given {@link MappingContext} and {@link AuditingHandler} * provided by the given {@link ObjectFactory}. This constructor does an additional registration to the * {@link SessionFactory}. Therefore the {@link SessionFactory} must already be instantiated. * * @deprecated this constructor could create a cyclic dependency to the session factory if this class gets registered * as a bean in the context. * @param auditingHandlerFactory must not be {@literal null}. */ @Deprecated public Neo4jAuditingEventListener(ObjectFactory<? extends IsNewAwareAuditingHandler> auditingHandlerFactory, SessionFactory sessionFactory) { Assert.notNull(auditingHandlerFactory, "IsNewAwareAuditingHandler must not be null!"); this.auditingHandlerFactory = auditingHandlerFactory; sessionFactory.register(this); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (!SessionFactory.class.isInstance(bean)) { return bean; } SessionFactory sessionFactory = (SessionFactory) bean; sessionFactory.register(new Neo4jAuditingEventListener(isNewAwareHandler)); return sessionFactory; } }
/** * Creates a new {@link Neo4jAuditingEventListener} using the given {@link MappingContext} and {@link AuditingHandler} * provided by the given {@link ObjectFactory}. This constructor does an additional registration to the * {@link SessionFactory}. Therefore the {@link SessionFactory} must already be instantiated. * * @deprecated this constructor could create a cyclic dependency to the session factory if this class gets registered * as a bean in the context. * @param auditingHandlerFactory must not be {@literal null}. */ @Deprecated public Neo4jAuditingEventListener(ObjectFactory<? extends IsNewAwareAuditingHandler> auditingHandlerFactory, SessionFactory sessionFactory) { Assert.notNull(auditingHandlerFactory, "IsNewAwareAuditingHandler must not be null!"); this.auditingHandlerFactory = auditingHandlerFactory; sessionFactory.register(this); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (!SessionFactory.class.isInstance(bean)) { return bean; } SessionFactory sessionFactory = (SessionFactory) bean; sessionFactory.register(new Neo4jAuditingEventListener(isNewAwareHandler)); return sessionFactory; } }
@BeforeClass public static void setUpClass() throws Exception { sf = new SessionFactory(driver, Beverage.class.getPackage().getName()); // register dummy listener to SaveEventDelegate code sf.register(new EventListenerAdapter()); }
@Test public void saveWithContextIdStrategy() throws Exception { CustomInstanceIdStrategy strategy = new CustomInstanceIdStrategy("test-custom-instance-id"); sessionFactory.register(strategy); ValidAnnotations.WithCustomInstanceIdStrategy entity = new ValidAnnotations.WithCustomInstanceIdStrategy(); session.save(entity); assertThat(entity.identifier).isEqualTo("test-custom-instance-id"); session.clear(); ValidAnnotations.WithCustomInstanceIdStrategy loaded = session .load(ValidAnnotations.WithCustomInstanceIdStrategy.class, "test-custom-instance-id"); assertThat(loaded).isNotNull(); assertThat(loaded.identifier).isEqualTo("test-custom-instance-id"); }
@BeforeClass public static void oneTimeSetUp() { sessionFactory = new SessionFactory(driver, "org.neo4j.ogm.domain.filesystem", "org.neo4j.ogm.domain.cineasts.annotated"); eventListener = new TestEventListener(); sessionFactory.register(eventListener); }