Skip to content

Commit

Permalink
#37 formatting complete
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ke committed Apr 29, 2015
1 parent 7f688d8 commit ceedc5f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* a {@link UpdateSource} implementation that uses JPA to retrieve the updates from the database. For this to work the
* entities have to be setup with JPA annotations
*
*
* @author Martin Braun
*/
public class JPAUpdateSource implements UpdateSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

/**
* Base class to create SearchFactories in a EJB environment. Uses a JPAEventSource.
*
*
* @author Martin Braun
*/
public abstract class EJBSearchFactory implements SearchFactory, UpdateConsumer {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

import javax.persistence.Query;

import org.hibernate.search.exception.AssertionFailure;

/**
* Utility class that allows you to access multiple JPA queries at once. Data is retrieved from the database in batches
* and ordered by a given comparator. No need for messy Unions on the database level! <br>
* <br>
* This is particularily useful if you scroll all the data from the database incrementally and if you can compare in
* Code.
*
*
* @author Martin
*/
public class MultiQueryAccess {
Expand Down Expand Up @@ -78,7 +80,7 @@ public MultiQueryAccess(Map<Class<?>, Long> countMap, Map<Class<?>, Query> query

/**
* increments the value to be returned by {@link #get()}
*
*
* @return true if there is a value left to be visited in the database
*/
public boolean next() {
Expand Down Expand Up @@ -114,14 +116,14 @@ public boolean next() {
return old + 1;
} );
if ( Math.abs( newProcessed - processed ) != 1L ) {
throw new AssertionError( "the new processed count should be exactly 1 " + "greater than the old one" );
throw new AssertionFailure( "the new processed count should be exactly 1 " + "greater than the old one" );
}
Long count = this.currentCountMap.get( arr.clazz );
Long newCount = this.currentCountMap.computeIfPresent( arr.clazz, (clazz, old) -> {
return old - 1;
} );
if ( Math.abs( count - newCount ) != 1L ) {
throw new AssertionError( "the new old remaining count should be exactly 1 " + "greater than the new one" );
throw new AssertionFailure( "the new old remaining count should be exactly 1 " + "greater than the new one" );
}
}
return this.scheduled != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void updateEvent(List<UpdateInfo> updateInfos) {
for ( UpdateInfo updateInfo : updateInfos ) {
Object id = updateInfo.getId();
int eventType = updateInfo.getEventType();
if ( id.equals( 2 ) && updateInfo.getEntityClass().equals( Place.class ) && eventType == EventType.INSERT ) {
if ( id.equals( 2 ) && Place.class.equals( updateInfo.getEntityClass() ) && EventType.INSERT == eventType ) {
gotEvent[0] = true;
}
else if ( id.equals( 3 ) && updateInfo.getEntityClass().equals( Sorcerer.class ) && eventType == EventType.INSERT ) {
Expand Down Expand Up @@ -115,7 +115,7 @@ else if ( id.equals( 3 ) && updateInfo.getEntityClass().equals( Sorcerer.class )
/**
* this is needed in other tests because the query method of JPAUpdateSource has package access
*/
public static MultiQueryAccess query(EntityManagerFactory emf, EntityManager em) throws NoSuchFieldException, SecurityException {
public static MultiQueryAccess query(EntityManagerFactory emf, EntityManager em) throws NoSuchFieldException {
EventModelParser parser = new EventModelParser();
JPAUpdateSource updateSource = new JPAUpdateSource( parser.parse( new HashSet<>( Arrays.asList( PlaceSorcererUpdates.class, PlaceUpdates.class ) ) ),
emf, false, 1, TimeUnit.SECONDS, 2, 2 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.persistence.metamodel.PluralAttribute;
import javax.persistence.metamodel.SingularAttribute;

import org.hibernate.search.exception.AssertionFailure;
import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
Expand All @@ -42,7 +43,7 @@
* This could be used to propagate events up to the top entity, but Hibernate-Search takes care of this via the @ContainedIn
* events, which is neat :). Either way, we still need this class to check whether the classes are annotated properly
* (every entity has to know its parent via {@link org.hibernate.search.annotations.ContainedIn}
*
*
* @author Martin Braun
*/
@Deprecated
Expand Down Expand Up @@ -129,7 +130,7 @@ private void parse(EntityType<?> curEntType, Class<?> cameFrom, Set<EntityType<?
field = entType.getJavaType().getDeclaredField( propertyName );
}
catch (NoSuchFieldException e) {
throw new AssertionError( "expected to find a Field but didn't: " + propertyName );
throw new AssertionFailure( "expected to find a Field but didn't: " + propertyName );
}
Method method = null;
try {
Expand Down Expand Up @@ -227,7 +228,7 @@ else if ( attribute instanceof SingularAttribute<?, ?> ) {
entityTypeClass = ( ( (SingularAttribute<?, ?>) attribute ).getType().getJavaType() );
}
else {
throw new AssertionError( "attributes have to either be " + "instanceof PluralAttribute or SingularAttribute " + "at this point" );
throw new AssertionFailure( "attributes have to either be " + "instanceof PluralAttribute or SingularAttribute " + "at this point" );
}
return entityTypeClass;
}
Expand Down Expand Up @@ -259,7 +260,7 @@ else if ( member instanceof Field ) {
ret = field.isAnnotationPresent( annotationClass );
}
else {
throw new AssertionError( "member should either be Field or Member" );
throw new AssertionFailure( "member should either be Field or Member" );
}
return ret;
}
Expand All @@ -278,7 +279,7 @@ else if ( member instanceof Field ) {
ret = field.get( object );
}
else {
throw new AssertionError( "member should either be Field or Member" );
throw new AssertionFailure( "member should either be Field or Member" );
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
package com.github.hotware.hsearch.jpa;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
import com.github.hotware.hsearch.db.events.jpa.JPAUpdateSourceTest;
import com.github.hotware.hsearch.jpa.test.entities.PlaceSorcererUpdates;
import com.github.hotware.hsearch.jpa.test.entities.PlaceUpdates;
import com.github.hotware.hsearch.jpa.util.MultiQueryAccess;

/**
* @author Martin
*/
public class MultiQueryAccessTest extends DatabaseIntegrationTest {

@Before
public void setup() throws NoSuchFieldException, SecurityException, SQLException {
public void setup() throws NoSuchFieldException, SQLException {
this.setup( "EclipseLink" );

EntityManager em = null;
Expand Down Expand Up @@ -136,7 +135,7 @@ public void setup() throws NoSuchFieldException, SecurityException, SQLException
}

@Test
public void test() throws NoSuchFieldException, SecurityException, SQLException, IllegalAccessException, IllegalArgumentException,
public void test() throws NoSuchFieldException, SQLException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
EntityManager em = null;
try {
Expand Down Expand Up @@ -180,7 +179,7 @@ public void shutDown() {
}
}

private MultiQueryAccess query(EntityManager em) throws NoSuchFieldException, SecurityException {
private MultiQueryAccess query(EntityManager em) throws NoSuchFieldException {
return JPAUpdateSourceTest.query( this.emf, em );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;

import org.hibernate.search.exception.AssertionFailure;

/**
* most (or all code) is from <a href=
* "http://normalengineering.com.au/normality/c-and-java-code-snippets/java-runtime-compilation-in-memory/" >here</a>
*
*
* @author Martin Braun
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class InMemoryCompiler {

private InMemoryCompiler() {
throw new AssertionFailure("can't touch this!");
}

/* Compiles the provided source code and returns the resulting Class object. */
public static Class compile(String source, String className) {

Expand Down

0 comments on commit ceedc5f

Please sign in to comment.