FullTextSession fullTextSession = Search.getFullTextSession(session); fullTextSession.openSession() Object customer = fullTextSession.load( Datasheet.class, datasheetDocument.getDatasheet.getId() ); fullTextSession.index(customer); fullTextSession.flushIndex();
/** * Adds all stored books to the Nation. * Needed to test for HSEARCH-534 and makes the dataset to index quite bigger. */ private static void storeAllBooksInNation() { FullTextSession fullTextSession = builder.openFullTextSession(); try { Transaction tx = fullTextSession.beginTransaction(); List<Book> allBooks = fullTextSession.createCriteria( Book.class ).list(); Nation italy = fullTextSession.load( Nation.class, 1 ); italy.getLibrariesHave().addAll( allBooks ); tx.commit(); } finally { fullTextSession.close(); } }
/** * rename a person having id to a new name */ private void renamePerson(Long id, String newName) { FullTextSession fullTextSession = Search.getFullTextSession( openSession() ); try { Transaction transaction = fullTextSession.beginTransaction(); Person kingJohn = fullTextSession.load( Person.class, id ); kingJohn.setName( newName ); transaction.commit(); } finally { fullTextSession.close(); } }
/** * rename a person having id to a new name */ private void renamePerson(Long id, String newName) { FullTextSession fullTextSession = Search.getFullTextSession( openSession() ); try { Transaction transaction = fullTextSession.beginTransaction(); SocialPerson person = fullTextSession.load( SocialPerson.class, id ); person.setName( newName ); transaction.commit(); } finally { fullTextSession.close(); } }
private static void createMany(Class<? extends TitleAble> entityType, int amount) throws InstantiationException, IllegalAccessException { FullTextSession fullTextSession = builder.openFullTextSession(); int totalEntitiesInDB = 0; try { Transaction tx = fullTextSession.beginTransaction(); fullTextSession.persist( new Nation( "Italy", "IT" ) ); tx.commit(); tx = fullTextSession.beginTransaction(); for ( int i = 0; i < amount; i++ ) { TitleAble instance = entityType.newInstance(); instance.setTitle( sentenceInventor.nextSentence() ); //to test for HSEARCH-512 we make all entities share some proxy Nation country = fullTextSession.load( Nation.class, 1 ); instance.setFirstPublishedIn( country ); fullTextSession.persist( instance ); totalEntitiesInDB++; if ( i % 250 == 249 ) { tx.commit(); fullTextSession.clear(); System.out.println( "Test preparation: " + totalEntitiesInDB + " entities persisted" ); tx = fullTextSession.beginTransaction(); } } tx.commit(); } finally { fullTextSession.close(); } }
@Test public void testMultipleUpdatesTriggeredByContainedIn() { PersonalContact contact = createTestData(); FullTextSession s = Search.getFullTextSession( openSession( ) ); s.getTransaction().begin(); contact = (PersonalContact) s.load( PersonalContact.class, contact.getId() ); contact.setEmail( "spam@hibernate.org" ); s.getTransaction().commit(); s.close(); }
line1 = fullTextSession.load( BusLine.class, line1.getId() ); line1.setBusLineCode( 2 ); line1.setOperating( true ); // boolean set to same value: might receive a different instance of Boolean fullTextSession.clear(); tx = fullTextSession.beginTransaction(); busStop = fullTextSession.load( BusStop.class, busStop.getId() ); busStop.setRoadName( "Mill Road" ); tx.commit(); fullTextSession.clear(); tx = fullTextSession.beginTransaction(); busStop = fullTextSession.load( BusStop.class, busStop.getId() );
Domain mysqlDomain = session.load( Domain.class, 8 ); session.delete( mysqlDomain ); Domain newDomain = new Domain( 8, "something.org" );