Package org.hibernate.search.test

Examples of org.hibernate.search.test.Document


  public void testMultipleEntitiesPerIndex() throws Exception {

    Session s = getSessions().openSession();
    s.getTransaction().begin();
    Document document =
        new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" );
    s.persist( document );
    s.flush();
    s.persist(
        new AlternateDocument(
            document.getId(),
            "Hibernate in Action",
            "Object/relational mapping with Hibernate",
            "blah blah blah"
        )
    );
    s.getTransaction().commit();
    s.close();

    assertEquals( 0, getDocumentNbr() );

    s = getSessions().openSession();
    s.getTransaction().begin();
    s.delete( s.get( AlternateDocument.class, document.getId() ) );
    s.delete( s.createCriteria( Document.class ).uniqueResult() );
    s.getTransaction().commit();
    s.close();
  }
View Full Code Here


      LeakingLuceneBackend.reset();
      FullTextSession session = fullTextSessionBuilder.openFullTextSession();
      Assert.assertEquals( 0, LeakingOptimizer.getTotalOperations() );

      Transaction tx = session.beginTransaction();
      session.persist( new Document( "The Book", "many paper pages assembled together at one side", "[old language you don't understand]" ) );
      tx.commit();

      Assert.assertEquals( 1, LeakingOptimizer.getTotalOperations() );
      Assert.assertEquals( 1, LeakingLuceneBackend.getLastProcessedQueue().size() );

      tx = session.beginTransaction();
      List list = session.createFullTextQuery( new MatchAllDocsQuery() ).list();
      Document doc = (Document) list.get( 0 );
      doc.setSummary( "Example of what was used in ancient times to read" );
      tx.commit();

      Assert.assertEquals( 1, LeakingLuceneBackend.getLastProcessedQueue().size() );
      Assert.assertEquals( expectedBackendOperations, LeakingOptimizer.getTotalOperations() );
    }
View Full Code Here

  public void testMultipleEntitiesPerIndex() throws Exception {


    Session s = getSessions().openSession();
    s.getTransaction().begin();
    Document document =
        new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" );
    s.persist( document );
    s.flush();
    s.persist(
        new AlternateDocument( document.getId(), "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" )
    );
    s.getTransaction().commit();
    s.close();

    assertEquals( 0, getDocumentNbr() );

    s = getSessions().openSession();
    s.getTransaction().begin();
    s.delete( s.get( AlternateDocument.class, document.getId() ) );
    s.delete( s.createCriteria( Document.class ).uniqueResult() );
    s.getTransaction().commit();
    s.close();
  }
View Full Code Here

  public void testMultipleEntitiesPerIndex() throws Exception {

    Session s = getSessions().openSession();
    s.getTransaction().begin();
    Document document =
        new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" );
    s.persist( document );
    s.flush();
    s.persist(
        new AlternateDocument(
            document.getId(),
            "Hibernate in Action",
            "Object/relational mapping with Hibernate",
            "blah blah blah"
        )
    );
    s.getTransaction().commit();
    s.close();

    assertEquals( 0, getDocumentNbr() );

    s = getSessions().openSession();
    s.getTransaction().begin();
    s.delete( s.get( AlternateDocument.class, document.getId() ) );
    s.delete( s.createCriteria( Document.class ).uniqueResult() );
    s.getTransaction().commit();
    s.close();
  }
View Full Code Here

    SearchFactoryImplementor searchFactoryImpl = getSearchFactoryImpl();
    MockErrorHandler errorHandler = (MockErrorHandler) searchFactoryImpl.getErrorHandler();

    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    s.persist( new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" ) );
    s.getTransaction().commit();
    s.close();

    s = getSessionFactory().openSession();
    s.getTransaction().begin();
    Document entity = (Document) s.get( Document.class, Long.valueOf( 1 ) );
    Assert.assertNotNull( entity );
    s.delete( entity );
    s.getTransaction().commit();
    s.close();
    Assert.assertNull( "unexpected exception detected", errorHandler.getLastException() );
View Full Code Here

  @Test
  public void testTransactionCommit() throws Exception {
    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    s.persist(
        new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" )
    );
    s.persist(
        new Document( "Lucene in Action", "FullText search engine", "blah blah blah" )
    );
    s.persist(
        new Document( "Hibernate Search in Action", "ORM and FullText search engine", "blah blah blah" )
    );
    s.getTransaction().commit();
    s.close();

    assertEquals( "transaction.commit() should index", 3, getDocumentNumber() );

    s = getSessionFactory().openSession();
    s.getTransaction().begin();
    s.persist(
        new Document(
            "Java Persistence with Hibernate", "Object/relational mapping with Hibernate", "blah blah blah"
        )
    );
    s.flush();
    s.getTransaction().rollback();
    s.close();

    assertEquals( "rollback() should not index", 3, getDocumentNumber() );

    s = getSessionFactory().openSession();
    s.doWork( new Work() {
      @Override
      public void execute(Connection connection) throws SQLException {
        connection.setAutoCommit( true ); // www.hibernate.org/403.html
      }
    } );
    s.persist(
        new Document(
            "Java Persistence with Hibernate", "Object/relational mapping with Hibernate", "blah blah blah"
        )
    );
    s.flush();
    s.close();
View Full Code Here

  @Test
  public void testQueryObjectIsSerializable() throws IOException, ClassNotFoundException {
    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    Document document =
        new Document( "Hibernate OGM in Action", "Cloud mapping with Hibernate", "blah blah cloud blah cloud" );
    s.persist( document );
    s.getTransaction().commit();
    s.close();

    TermQuery query = new TermQuery( new Term( "Abstract", "hibernate" ) );
View Full Code Here

    Assert.assertTrue( documentsIndexManager.getClass().equals( org.hibernate.search.indexes.impl.NRTIndexManager.class ) );
    NRTIndexManager indexManager = (NRTIndexManager) documentsIndexManager;

    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    Document document =
        new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" );
    s.persist( document );
    s.flush();
    s.persist(
        new AlternateDocument(
            document.getId(),
            "Hibernate in Action",
            "Object/relational mapping with Hibernate",
            "blah blah blah"
        )
    );
    s.getTransaction().commit();
    s.close();

    assertEquals( 0, getDocumentNbrFromFilesystem( indexManager ) );
    assertEquals( 2, getDocumentNbrFromReaderProvider( indexManager ) );

    s = getSessionFactory().openSession();
    s.getTransaction().begin();
    TermQuery q = new TermQuery( new Term( "alt_title", "hibernate" ) );
    assertEquals(
        "does not properly filter", 0,
        Search.getFullTextSession( s ).createFullTextQuery( q, Document.class ).list().size()
    );
    assertEquals(
        "does not properly filter", 1,
        Search.getFullTextSession( s )
            .createFullTextQuery( q, Document.class, AlternateDocument.class )
            .list().size()
    );
    s.delete( s.get( AlternateDocument.class, document.getId() ) );
    s.getTransaction().commit();
    s.close();

    s = getSessionFactory().openSession();
    s.getTransaction().begin();
View Full Code Here

  @Test
  public void testMultipleEntitiesPerIndex() throws Exception {
    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    Document document =
        new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" );
    s.persist( document );
    s.flush();
    s.persist(
        new AlternateDocument(
            document.getId(),
            "Hibernate in Action",
            "Object/relational mapping with Hibernate",
            "blah blah blah"
        )
    );
    s.getTransaction().commit();
    s.close();

    assertEquals( 2, getDocumentNbr() );

    s = getSessionFactory().openSession();
    s.getTransaction().begin();
    TermQuery q = new TermQuery( new Term( "alt_title", "hibernate" ) );
    List hibernateDocuments = Search.getFullTextSession( s ).createFullTextQuery( q, Document.class ).list();
    assertEquals(
        "does not properly filter", 0,
        hibernateDocuments.size()
    );
    assertEquals(
        "does not properly filter", 1,
        Search.getFullTextSession( s )
            .createFullTextQuery( q, Document.class, AlternateDocument.class )
            .list().size()
    );
    s.delete( s.get( AlternateDocument.class, document.getId() ) );
    s.getTransaction().commit();
    s.close();

    assertEquals( 1, getDocumentNbr() );
View Full Code Here

  @Test
  public void testEventIntegration() throws Exception {
    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    s.persist(
        new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" )
    );
    s.getTransaction().commit();
    s.close();

    Directory dir = FSDirectory.open( new File( getBaseIndexDir().toString(), "Documents" ) );
    try {
      IndexReader reader = DirectoryReader.open( dir );
      try {
        int num = reader.numDocs();
        assertEquals( 1, num );
        assertEquals( 1, reader.docFreq( new Term( "Abstract", "hibernate" ) ) );
        assertEquals( 1, reader.docFreq( new Term( "title", "action" ) ) );
        assertEquals( "1", projectSingleField( reader, "id", new Term( "title", "action" ) ) );

      }
      finally {
        reader.close();
      }

      s = getSessionFactory().openSession();
      s.getTransaction().begin();
      Document entity = (Document) s.get( Document.class, Long.valueOf( 1 ) );
      entity.setSummary( "Object/relational mapping with EJB3" );
      s.persist( new Document( "Seam in Action", "", "blah blah blah blah" ) );
      s.getTransaction().commit();
      s.close();

      reader = DirectoryReader.open( dir );
      try {
View Full Code Here

TOP

Related Classes of org.hibernate.search.test.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.