private void indexTestData() { Transaction tx = fullTextSession.beginTransaction(); University wogharts = new University( 1, "Wogharts" ); fullTextSession.persist( wogharts ); College golfCollege = new College( 1L, "Southern Florida College of Golf" ); fullTextSession.persist( golfCollege ); College stLucieCommunityCollege = new CommunityCollege( 2L, "St. Lucie Community College" ); fullTextSession.persist( stLucieCommunityCollege ); School homesteadPrimary = new PrimarySchool( (short) 1, "Homestead Elementary School" ); fullTextSession.persist( homesteadPrimary ); School cutlerBayHigh = new HighSchool( 1L, "Cutler Bay High School" ); fullTextSession.persist( cutlerBayHigh ); tx.commit(); fullTextSession.clear(); }
private void addToCollectionAndPersist(EntityExtendingMappedSuperclassWithCollectionField entity, String value) { Transaction transaction = fullTextSession.beginTransaction(); entity.getCollection().add( value ); fullTextSession.persist( entity ); transaction.commit(); fullTextSession.clear(); }
private void indexTestData(FullTextSessionBuilder builder) { FullTextSession session = builder.openFullTextSession(); Transaction transaction = session.beginTransaction(); // need to index at least two instances. In the single instance case a search will not go via the object initializer Foo foo = new Foo(); session.persist( foo ); Foo snafu = new Foo(); session.persist( snafu ); transaction.commit(); session.close(); }
private void persistElmo(FullTextSession fullTextSession) { Transaction transaction = fullTextSession.beginTransaction(); Muppet elmo = new Muppet( "Elmo" ); fullTextSession.persist( elmo ); transaction.commit(); fullTextSession.clear(); }
/** * Use to add some initial data * * @param fts the fulltext session */ private static void storeClocks(FullTextSession fts) { Transaction tx = fts.beginTransaction(); for ( long i = 0; i < 1000; i++ ) { Clock clock = new Clock( Long.valueOf( i ), "Model cat A" + i, ( i % 2 == 0 ) ? "Seiko" : "Swatch", Long.valueOf( i + 2000 ) ); fts.persist( clock ); } tx.commit(); fts.clear(); }
private void createPersistAndIndexTestData() { Level1 level1 = new Level1(); level1.id = 1L; level1.text = "Level 1"; Level2 level2 = new Level2(); level2.id = 2L; level2.text = "Level 2" ; Level3 level3 = new Level3(); level3.id = 3L; level3.text = "Level 3"; fullTextSession = Search.getFullTextSession( openSession() ); Transaction tx = fullTextSession.beginTransaction(); fullTextSession.persist( level1 ); fullTextSession.persist( level2 ); fullTextSession.persist( level3 ); tx.commit(); fullTextSession.clear(); }
/** * 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(); }
private static void initializeData(FullTextSession fullTextSession) { final Transaction transaction = fullTextSession.beginTransaction(); LegacyCar[] cars = new LegacyCar[10]; for ( int i = 0; i < cars.length; i++ ) { cars[i] = new LegacyCar(); cars[i].setId( "" + i ); cars[i].setModel( "model" + i ); fullTextSession.persist( cars[i] ); } transaction.commit(); }
/** * Update a non-indexed collection of an entity contained in a collection. No indexing work should be created. */ private void updateCatalogsCollection(FullTextSession fullTextSession, Catalog catalog) { final Transaction transaction = fullTextSession.beginTransaction(); Consumer consumer = new Consumer(); consumer.setName( "consumer" ); consumer.getCatalogs().add( catalog ); fullTextSession.persist( consumer ); catalog.getConsumers().add( consumer ); fullTextSession.merge( catalog ); transaction.commit(); }
/** * Initialize the test data. * * @param fulltextSessionBuilder */ private void initializeData(FullTextSessionBuilder fulltextSessionBuilder) { FullTextSession fullTextSession = fulltextSessionBuilder.openFullTextSession(); try { final Transaction transaction = fullTextSession.beginTransaction(); LocationGroup group = new LocationGroup( "Floor 1" ); fullTextSession.persist( group ); for ( int i = 0; i < 5; i++ ) { Location location = new Location( "Room 10" + i ); fullTextSession.persist( location ); group.getLocations().add( location ); location.setLocationGroup( group ); fullTextSession.merge( group ); } transaction.commit(); } finally { fullTextSession.close(); } }
public Long setupTestData(FullTextSessionBuilder builder) { FullTextSession s = builder.openFullTextSession(); Transaction tx = s.beginTransaction(); Address bobsPlace = new Address(); bobsPlace.setOwner( "Bob McRobb" ); Address alicesPlace = new Address(); alicesPlace.setOwner( "Alice Donellis" ); Country scotland = new Country(); scotland.setName( "Scotland" ); bobsPlace.setCountry( scotland ); scotland.getAddresses().add( bobsPlace ); s.persist( bobsPlace ); s.persist( alicesPlace ); s.persist( scotland ); Long scotlandId = scotland.getId(); tx.commit(); s.close(); return scotlandId; } }
private void createPersistAndIndexTestData() { blog = new Blog(); blog.setTitle( "Hibernate Search now has soft deletes!" ); blog.setStatus( BlogStatus.DRAFT ); article = new Article(); article.setTitle( "Hibernate Search: detailed description of soft deletes" ); article.setStatus( BlogStatus.DRAFT ); totalArticle = new TotalArticle(); totalArticle.setTitle( "Hibernate Search: the total truth about soft deletes" ); totalArticle.setStatus( BlogStatus.DRAFT ); fullTextSession = Search.getFullTextSession( openSession() ); Transaction tx = fullTextSession.beginTransaction(); fullTextSession.persist( blog ); fullTextSession.persist( article ); fullTextSession.persist( totalArticle ); tx.commit(); fullTextSession.clear(); }
@Override @Before public void setUp() throws Exception { super.setUp(); FullTextSession fullTextSession = Search.getFullTextSession( openSession() ); Transaction tx = fullTextSession.beginTransaction(); for ( int i = 0; i < 100; i++ ) { TestEntity entity = new TestEntity( i, "document-" + i ); fullTextSession.persist( entity ); } tx.commit(); fullTextSession.close(); }
@Before public void setUp() { builder = new FullTextSessionBuilder(); builder .addAnnotatedClass( AlternateBook.class ) .addAnnotatedClass( Employee.class ) .setProperty( "hibernate.default_batch_fetch_size", "10" ) .build(); sess = builder.openFullTextSession(); Transaction tx = sess.beginTransaction(); //create some entities to query: for ( int i = 0; i < 324; i++ ) { sess.persist( new AlternateBook( i , "book about the number " + i ) ); } for ( int i = 0; i < 133; i++ ) { sess.persist( new Employee( i , "Rossi", "dept. num. " + i ) ); } tx.commit(); }
@Test public void testNormalizerDef() throws Exception { Address address = new Address(); address.setStreet1( "3340 Peachtree Rd NE" ); address.setStreet2( "JBoss" ); FullTextSession s = Search.getFullTextSession( openSession() ); Transaction tx = s.beginTransaction(); s.persist( address ); tx.commit(); s.clear(); tx = s.beginTransaction(); org.apache.lucene.search.Query luceneQuery = new TermQuery( new Term( "street1_normalized", "3340 peachtree rd ne" ) ); final FullTextQuery query = s.createFullTextQuery( luceneQuery ); assertEquals( "Normalizer inoperant", 1, query.getResultSize() ); s.delete( query.list().get( 0 ) ); tx.commit(); s.close(); }
private void createBusLines(int number, boolean rollback) { FullTextSession fullTextSession = Search.getFullTextSession( openSession() ); Transaction tx = fullTextSession.beginTransaction(); for ( int i = 0; i < number; i++ ) { BusLine line = new BusLine(); line.setBusLineName( "line " + i ); fullTextSession.persist( line ); } if ( rollback ) { tx.rollback(); } else { tx.commit(); } fullTextSession.close(); }
@Override protected void doAction(FullTextSession s, int jobSeed) { Detective detective = new Detective(); detective.setName( "John Doe " + jobSeed ); detective.setBadge( "123455" + jobSeed ); detective.setPhysicalDescription( "Blond green eye etc etc" ); s.persist( detective ); Suspect suspect = new Suspect(); suspect.setName( "Jane Doe " + jobSeed ); suspect.setPhysicalDescription( "brunette, short, 30-ish" ); if ( jobSeed % 20 == 0 ) { suspect.setSuspectCharge( "thief liar " ); } else { suspect.setSuspectCharge( " It's 1875 in London. The police have captured career criminal Montmorency. In the process he has been grievously wounded and it is up to a young surgeon to treat his wounds. During his recovery Montmorency learns of the city's new sewer system and sees in it the perfect underground highway for his thievery. Washington Post columnist John Kelly recommends this title for middle schoolers, especially to be read aloud." ); } s.persist( suspect ); } }
private void initializeData(FullTextSession fullTextSession) { final Transaction transaction = fullTextSession.beginTransaction(); LegacyCar[] cars = new LegacyCar[3]; for ( int i = 1; i < 4; i++ ) { cars[i - 1] = new LegacyCar(); cars[i - 1].setId( "" + i ); cars[i - 1].setModel( "model" + i ); fullTextSession.persist( cars[i - 1] ); } LegacyCarPlant plant = new LegacyCarPlant(); plant.setCar( cars[0] ); plant.setName( "plant12" ); plant.setId( new LegacyCarPlantPK() ); plant.getId().setCarId( cars[0].getId() ); plant.getId().setPlantId( "2" ); fullTextSession.persist( plant ); transaction.commit(); }
@Test public void testAnalyzerDef() throws Exception { Address address = new Address(); address.setStreet1( "3340 Peachtree Rd NE" ); address.setStreet2( "JBoss" ); FullTextSession s = Search.getFullTextSession( openSession() ); Transaction tx = s.beginTransaction(); s.persist( address ); tx.commit(); s.clear(); tx = s.beginTransaction(); QueryParser parser = new QueryParser( "id", TestConstants.standardAnalyzer ); org.apache.lucene.search.Query luceneQuery = parser.parse( "street1_ngram:pea" ); final FullTextQuery query = s.createFullTextQuery( luceneQuery ); assertEquals( "Analyzer inoperant", 1, query.getResultSize() ); s.delete( query.list().get( 0 ) ); tx.commit(); s.close(); }
@Test public void testBridgeMapping() throws Exception { Address address = new Address(); address.setStreet1( "Peachtree Rd NE" ); address.setStreet2( "JBoss" ); FullTextSession s = Search.getFullTextSession( openSession() ); Transaction tx = s.beginTransaction(); s.persist( address ); tx.commit(); s.clear(); tx = s.beginTransaction(); QueryParser parser = new QueryParser( "id", TestConstants.standardAnalyzer ); org.apache.lucene.search.Query luceneQuery = parser.parse( "street1:peac" ); FullTextQuery query = s.createFullTextQuery( luceneQuery ); assertEquals( "PrefixQuery should not be on", 0, query.getResultSize() ); luceneQuery = parser.parse( "street1_abridged:peac" ); query = s.createFullTextQuery( luceneQuery ); assertEquals( "Bridge not used", 1, query.getResultSize() ); s.delete( query.list().get( 0 ) ); tx.commit(); s.close(); }