@Override protected void execute(FullTextSession fts) { long bookId = ctx.getRandomBookId(); // See HSEARCH-2916, we often had concurrent write errors here Book book = (Book) fts.get( Book.class, bookId, LockMode.PESSIMISTIC_WRITE ); if ( book != null ) { book.setRating( Math.abs( RANDOM_RATING.nextFloat() ) * MAX_RATING ); } }
@Test public void testDoubleInsert() throws Exception { PersonalContact contact = createTestData(); FullTextSession s = Search.getFullTextSession( openSession( ) ); s.getTransaction().begin(); Term term = new Term( "county", "county" ); TermQuery termQuery = new TermQuery( term ); Query query = s.createFullTextQuery( termQuery ); assertEquals( 1, query.list().size() ); contact = (PersonalContact) s.get( PersonalContact.class, contact.getId() ); contact.getPhoneNumbers().clear(); contact.getAddresses().clear(); s.flush(); s.clear(); s.createQuery( "delete " + Address.class.getName() ).executeUpdate(); s.createQuery( "delete " + Phone.class.getName() ).executeUpdate(); s.createQuery( "delete " + Contact.class.getName() ).executeUpdate(); s.getTransaction().commit(); s.close(); }
/** * Changes the parent LocationGroup's name to "Airport" */ private void updateLocationGroupName(FullTextSession fullTextSession) { final Transaction transaction = fullTextSession.beginTransaction(); LocationGroup group = fullTextSession.get( LocationGroup.class, 1L ); LocationGroup locationGroup = (LocationGroup) fullTextSession.merge( group ); locationGroup.setName( "Airport" ); transaction.commit(); }
Entity1ForUnindexed toDelete = (Entity1ForUnindexed) fts.get( Entity1ForUnindexed.class, otherId );
private void setAllBlogEntriesToStatus(BlogStatus status) { Transaction tx = fullTextSession.beginTransaction(); blog = (Blog) fullTextSession.get( Blog.class, blog.getId() ); blog.setStatus( status ); article = (Article) fullTextSession.get( Article.class, article.getId() ); article.setStatus( status ); totalArticle = (TotalArticle) fullTextSession.get( TotalArticle.class, totalArticle.getId() ); totalArticle.setStatus( status ); tx.commit(); fullTextSession.clear(); }
session.persist( new Domain( 6, "mysql.com" ) ); session.persist( new Domain( 7, "oracle.com" ) ); Domain hibernateDomain = session.get( Domain.class, 3 ); session.delete( hibernateDomain ); Domain geocitiesDomain = session.get( Domain.class, 4 ); session.delete( geocitiesDomain ); session.getTransaction().commit(); Domain mysqlDomain = session.get( Domain.class, 6 ); session.delete( mysqlDomain ); Domain sunDomain = session.get( Domain.class, 5 ); sunDomain.setName( "community.oracle.com" ); session.getTransaction().commit();
private void clearData(FullTextSession fullTextSession) { final Transaction transaction = fullTextSession.beginTransaction(); final LegacyCarPlantPK id = new LegacyCarPlantPK(); id.setCarId( "1" ); id.setPlantId( "2" ); fullTextSession.delete( fullTextSession.get( LegacyCarPlant.class, id ) ); for ( int i = 1; i < 4; i++ ) { fullTextSession.delete( fullTextSession.get( LegacyCar.class, "" + i ) ); } transaction.commit(); }
/** * Adds a single Location to the LocationGroup#1 */ private void addLocationToGroupCollection(FullTextSession fullTextSession) { final Transaction transaction = fullTextSession.beginTransaction(); LocationGroup group = fullTextSession.get( LocationGroup.class, 1L ); Location location = new Location( "New Room" ); fullTextSession.persist( location ); group.getLocations().add( location ); location.setLocationGroup( group ); transaction.commit(); }
@Override protected void execute(FullTextSession fts) { long bookId = ctx.getRandomBookId(); // See HSEARCH-2916, we often had concurrent write errors here Book book = (Book) fts.get( Book.class, bookId, LockMode.PESSIMISTIC_WRITE ); if ( book != null ) { book.setTotalSold( book.getTotalSold() + 1 ); } }
@Override @After public void tearDown() throws Exception { if ( getTransactionStatus( fullTextSession ) != TransactionStatus.ACTIVE ) { Transaction tx = fullTextSession.beginTransaction(); blog = (Blog) fullTextSession.get( Blog.class, blog.getId() ); fullTextSession.delete( blog ); blog = (Blog) fullTextSession.get( Article.class, article.getId() ); fullTextSession.delete( blog ); blog = (Blog) fullTextSession.get( TotalArticle.class, totalArticle.getId() ); fullTextSession.delete( blog ); tx.commit(); } fullTextSession.close(); super.tearDown(); }
@Test public void testUpdateOfCollectionInMappedSuperclass() { EntityExtendingMappedSuperclassWithCollectionField entity = new EntityExtendingMappedSuperclassWithCollectionField(); addToCollectionAndPersist( entity, FIRST_COLLECTION_VALUE ); assertEquals( "First collection value is persisted and should be indexed", 1, searchEntityByCollectionValue( FIRST_COLLECTION_VALUE ).size() ); assertEquals( "Second collection value is not yet added and should not be indexed", 0, searchEntityByCollectionValue( SECOND_COLLECTION_VALUE ).size() ); fullTextSession.clear(); // re-get the entity entity = (EntityExtendingMappedSuperclassWithCollectionField) fullTextSession.get( EntityExtendingMappedSuperclassWithCollectionField.class, entity.getId() ); addToCollectionAndPersist( entity, SECOND_COLLECTION_VALUE ); assertEquals( "Second collection value is persisted and should be indexed", 1, searchEntityByCollectionValue( SECOND_COLLECTION_VALUE ).size() ); }
@Test public void testName() throws Exception { try ( FullTextSession s = Search.getFullTextSession( openSession() ) ) { Transaction tx = s.beginTransaction(); { CheeseRollingCompetitor cheeser = new CheeseRollingCompetitor(); cheeser.id = 1; cheeser.nickname = "Jimmy Fontina"; s.persist( cheeser ); } tx.commit(); s.clear(); assertExists( s, "Jimmy", "Jimmy Fontina" ); tx = s.beginTransaction(); CheeseRollingCompetitor johnny = s.get( CheeseRollingCompetitor.class, 1 ); johnny.nickname = "Johnny Fontina"; tx.commit(); s.clear(); assertExists( s, "Johnny", "Johnny Fontina" ); tx = s.beginTransaction(); s.delete( johnny ); tx.commit(); } }
@Test public void writeThenPurge() throws Exception { flush(); List<Level1> all = getAll(); assertEquals( "Wrong total number of entries", 3, all.size() ); // Expect 0 failure in the backend threads logged.expectLevelMissing( Level.ERROR ); Transaction tx = fullTextSession.beginTransaction(); fullTextSession.index( fullTextSession.get( Level1.class, 1L ) ); tx.commit(); tx = fullTextSession.beginTransaction(); fullTextSession.purgeAll( Level1.class ); tx.commit(); flush(); all = getAll(); assertEquals( "Wrong total number of entries. Index should be empty after purge.", 0, all.size() ); tx = fullTextSession.beginTransaction(); fullTextSession.createIndexer() .batchSizeToLoadObjects( 25 ) .threadsToLoadObjects( 1 ) .optimizeOnFinish( true ) .startAndWait(); tx.commit(); flush(); all = getAll(); assertEquals( "Wrong total number of entries.", 3, all.size() ); }
counter++; assertEquals( "dept incorrect", "ITech", projection[2] ); assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, (Serializable) projection[0] ) ); assertTrue( "SCORE incorrect", projection[4] instanceof Float );
person = s.get( SpecialPerson.class, id ); s.delete( person ); tx.commit();
assertEquals( "dept incorrect", "Accounting", projection[2] ); assertEquals( "THIS incorrect", "Jackson", ( (Employee) projection[3] ).getLastname() ); assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, (Serializable) projection[0] ) ); assertTrue( "SCORE incorrect", projection[4] instanceof Float ); assertFalse( "SCORE should not be a NaN", Float.isNaN( (Float) projection[4] ) ); assertNotNull( projection ); assertEquals( "THIS incorrect", projection[0], s.get( Employee.class, (Serializable) projection[4] ) ); assertTrue( "SCORE incorrect", projection[1] instanceof Float ); assertNull( "BOOST not removed", projection[2] );
Item loaded = s.get( Item.class, item.getId() ); loaded.setDescription( "Ferrari" );
FullTextSession fullTextSession = fulltextSessionBuilder.openFullTextSession(); try { Catalog catalog = (Catalog) fullTextSession.get( Catalog.class, 1L ); PersistentSet catalogItems = (PersistentSet) catalog.getCatalogItems(); PersistentBag consumers = (PersistentBag) catalog.getConsumers();