Skip to content

Commit

Permalink
#37 hibernate-search-db formatted right
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ke committed Apr 29, 2015
1 parent 0cc3ff1 commit 1781743
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/**
* contains information about the EventModel. Instances of this class can be obtained by a {@link EventModelParser}.
*
*
* @author Martin
*/
public class EventModelInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.Set;
import java.util.function.Function;

import org.hibernate.search.exception.AssertionFailure;

import com.github.hotware.hsearch.db.events.annotations.Event;
import com.github.hotware.hsearch.db.events.annotations.IdFor;
import com.github.hotware.hsearch.db.events.annotations.Updates;
Expand All @@ -26,7 +28,7 @@
* {@link EventModelInfo}. <br>
* <br>
* It also checks the classes for the right annotations and does basic integrity checking of this information
*
*
* @author Martin
*/
public class EventModelParser {
Expand Down Expand Up @@ -114,7 +116,7 @@ else if ( eventTypeMemberFinal instanceof Field ) {
return (Integer) ( (Field) eventTypeMemberFinal ).get( object );
}
else {
throw new AssertionError();
throw new AssertionFailure("");
}
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
Expand Down Expand Up @@ -182,7 +184,7 @@ else if ( member instanceof Field ) {
val = ( (Field) member ).get( object );
}
else {
throw new AssertionError();
throw new AssertionFailure("");
}
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
Expand Down Expand Up @@ -213,7 +215,7 @@ else if ( member instanceof Field ) {
ret = field.getAnnotation( 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 @@ -229,7 +231,7 @@ else if ( member instanceof Field ) {
ret = field.getType();
}
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,15 +6,17 @@
*/
package com.github.hotware.hsearch.db.events;

import org.hibernate.search.exception.AssertionFailure;

/**
* Contains constants that describe the different Database-Events that are relevant to the index
*
*
* @author Martin Braun
*/
public final class EventType {

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

public static final int DELETE = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* This class is the "glue" between a {@link com.github.hotware.hsearch.db.events.UpdateSource} and the actual
* Hibernate-Search index. It consumes Events coming from the UpdateSource and updates the Hibernate-Search index
* accordingly
*
*
* @author Martin Braun
*/
public class IndexUpdater implements UpdateConsumer {
Expand Down Expand Up @@ -114,13 +114,13 @@ public void updateEvent(List<UpdateInfo> updateInfos) {
}
}

public static interface IndexWrapper {
public interface IndexWrapper {

public void delete(Class<?> entityClass, List<Class<?>> inIndexOf, Object id, Transaction tx);
void delete(Class<?> entityClass, List<Class<?>> inIndexOf, Object id, Transaction tx);

public void update(Object entity, Transaction tx);
void update(Object entity, Transaction tx);

public void index(Object entity, Transaction tx);
void index(Object entity, Transaction tx);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* In order to provide uniqueness between the Update tables it uses a procedure that generates unique ids. This
* procedure does this with auxilliary table that only has a autoincrement id. A row is inserted everytime a unique id
* is needed and that id is retrieved via MySQLs last_insert_id() and then returned
*
*
* @author Martin Braun
*/
public class MySQLTriggerSQLStringSource implements TriggerSQLStringSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Classes that implement this interface provide means to create the Triggers needed on the database to write C_UD
* information about entities in the index into the specific Updates-Table.
*
*
* @author Martin Braun
*/
public interface TriggerSQLStringSource {
Expand All @@ -22,41 +22,41 @@ public interface TriggerSQLStringSource {
* only be done if your database is running out of ids for all the update instances. However, this shouldn't be a
* real world problem :D http://stackoverflow.com/questions/277608/is-bigint-large-enough-for-an- event-log-table
*/
public String[] getRecreateUniqueIdTableCode();
String[] getRecreateUniqueIdTableCode();

/**
* this is executed first
*/
public String[] getSetupCode();
String[] getSetupCode();

/**
* this has to be executed before every call to getTriggerCreationCode
*
*
* @param eventModelInfo the EventModelInfo/type this corresponds to
*/
public String[] getSpecificSetupCode(EventModelInfo eventModelInfo);
String[] getSpecificSetupCode(EventModelInfo eventModelInfo);

/**
* this removes all changes made by {@link #getSpecificSetupCode(EventModelInfo)}
*
*
* @param eventModelInfo the EventModelInfo/type this corresponds to
*/
public String[] getSpecificUnSetupCode(EventModelInfo eventModelInfo);
String[] getSpecificUnSetupCode(EventModelInfo eventModelInfo);

/**
* this creates a specific trigger
*
*
* @param eventModelInfo the EventModelInfo/type this corresponds to
* @param eventType see {@link EventType}
*/
public String[] getTriggerCreationCode(EventModelInfo eventModelInfo, int eventType);
String[] getTriggerCreationCode(EventModelInfo eventModelInfo, int eventType);

/**
* this removes a specific trigger created by {@link #getTriggerCreationCode(EventModelInfo, int)}
*
*
* @param eventModelInfo the EventModelInfo/type this corresponds to
* @param eventType see {@link EventType}
*/
public String[] getTriggerDropCode(EventModelInfo eventModelInfo, int eventType);
String[] getTriggerDropCode(EventModelInfo eventModelInfo, int eventType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public interface UpdateConsumer {

/**
* called everytime an update is found in the database
*
*
* @param updateInfo a list of objects describing the several updates in the order they occured in the database
*/
public void updateEvent(List<UpdateInfo> updateInfo);
void updateEvent(List<UpdateInfo> updateInfo);

public static class UpdateInfo {
public class UpdateInfo {

private final Class<?> entityClass;
private final Object id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
/**
* Source for updates on entities. This does no hierarchy checks, it just delivers information about which entry in
* which table has changed
*
*
* @author Martin Braun
*/
public interface UpdateSource {

public void setUpdateConsumers(List<UpdateConsumer> updateConsumers);
void setUpdateConsumers(List<UpdateConsumer> updateConsumers);

public void start();
void start();

public void stop();
void stop();

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

/**
* used to identify the field which contains the information about what operation happened on the database
*
*
* @author Martin
*/
@Target({ FIELD, METHOD })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
* <br>
* the class returned has to be annotated with @InIndex
*/
public Class<?> entityClass();
Class<?> entityClass();

/**
* @return the column names of the id in the Updates table.<br>
* <b>has to be in the same order as columnsInOriginal</b>
*/
public String[] columns();
String[] columns();

/**
* @return the column names of the id in the original table.<br>
* <b>has to be in the same order as columns</b>
*/
public String[] columnsInOriginal();
String[] columnsInOriginal();

public Class<? extends ToOriginalIdBridge> bridge() default DefaultToOriginalIdBridge.class;
Class<? extends ToOriginalIdBridge> bridge() default DefaultToOriginalIdBridge.class;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
/**
* @return the name of the updates-table
*/
public String tableName();
String tableName();

/**
* @return the name of the table the updates correspond to
*/
public String originalTableName();
String originalTableName();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* This package contains the annotations that are used to describe Updates classes.
* These Updates classes contain information about changes in Database
* and only provide information that something has changed and not what.
*
*
* @author Martin Braun
*/
package com.github.hotware.hsearch.db.events.annotations;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
// TODO: maybe move this?
public interface ToOriginalIdBridge {

public Object toOriginal(Object object);
Object toOriginal(Object object);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
public interface TableInfoSource {

public default List<TableInfo> getTableInfos(Set<Class<?>> classesInIndex) {
default List<TableInfo> getTableInfos(Set<Class<?>> classesInIndex) {
List<Class<?>> list = new ArrayList<>( classesInIndex.size() );
list.addAll( classesInIndex );
return this.getTableInfos( list );
}

public List<TableInfo> getTableInfos(List<Class<?>> classesInIndex);
List<TableInfo> getTableInfos(List<Class<?>> classesInIndex);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/
package com.github.hotware.hsearch.db.events;

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

import java.util.Arrays;
import java.util.Comparator;
Expand All @@ -15,9 +16,7 @@

import org.junit.Test;

import com.github.hotware.hsearch.db.events.EventModelInfo;
import com.github.hotware.hsearch.db.events.EventModelInfo.IdInfo;
import com.github.hotware.hsearch.db.events.EventModelParser;
import com.github.hotware.hsearch.db.events.annotations.Event;
import com.github.hotware.hsearch.db.events.annotations.IdFor;
import com.github.hotware.hsearch.db.events.annotations.Updates;
Expand All @@ -32,7 +31,7 @@
public class EventModelParserTest {

@Test
public void test() throws IllegalArgumentException, IllegalAccessException {
public void test() throws IllegalAccessException {

{
EventModelParser parser = new EventModelParser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hibernate.search.cfg.spi.SearchConfiguration;
import org.hibernate.search.engine.integration.impl.ExtendedSearchIntegrator;
import org.hibernate.search.engine.metadata.impl.MetadataProvider;
import org.hibernate.search.exception.AssertionFailure;
import org.hibernate.search.spi.SearchIntegratorBuilder;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void setup() {
@SuppressWarnings("rawtypes")
@Override
public List getBatch(Class<?> entityClass, List<Object> ids) {
throw new AssertionError( "not to be used in this test!" );
throw new AssertionFailure( "not to be used in this test!" );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
/*
* Copyright 2015 Martin Braun
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Hibernate Search, full-text search for your domain model
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package com.github.hotware.hsearch.db.events;

Expand Down

0 comments on commit 1781743

Please sign in to comment.