Skip to content

Commit

Permalink
HSEARCH-4134 Add entity to store the events for retries
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Mar 31, 2021
1 parent 8a8294b commit 9552453
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 5 deletions.
Expand Up @@ -35,6 +35,7 @@ public class OutboxAdditionalJaxbMappingProducer implements org.hibernate.boot.s
private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() );

private static final String OUTBOX_TABLE_NAME = "HIBERNATE_SEARCH_OUTBOX_TABLE";
private static final String OUTBOX_RETRY_TABLE_NAME = "HIBERNATE_SEARCH_OUTBOX_RETRY_TABLE";

private static final String OUTBOX_ENTITY_DEFINITION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"\n" +
Expand All @@ -57,6 +58,21 @@ public class OutboxAdditionalJaxbMappingProducer implements org.hibernate.boot.s
" </type>\n" +
" </property>\n" +
" </class>\n" +
"\n" +
" <class name=\"" + OutboxEventRetry.class.getName() + "\" table=\"" + OUTBOX_RETRY_TABLE_NAME + "\">\n" +
" <id name=\"id\" column=\"ID\" type=\"integer\">\n" +
" <generator class=\"org.hibernate.id.enhanced.SequenceStyleGenerator\">\n" +
" <param name=\"sequence_name\">" + OUTBOX_RETRY_TABLE_NAME + "_GENERATOR</param>\n" +
" <param name=\"table_name\">" + OUTBOX_RETRY_TABLE_NAME + "_GENERATOR</param>\n" +
" <param name=\"initial_value\">1</param>\n" +
" <param name=\"increment_size\">1</param>\n" +
" </generator>\n\r" +
" </id>\n\r" +
" <property name=\"entityName\" type=\"string\" />\n" +
" <property name=\"entityId\" type=\"string\" />\n" +
" <property name=\"retries\" type=\"integer\" />\n" +
" <property name=\"documentRoutes\" type=\"binary\" length=\"8192\" />\n" +
" </class>\n" +
"</hibernate-mapping>\n";

@Override
Expand Down
Expand Up @@ -13,11 +13,7 @@
import org.hibernate.search.mapper.pojo.route.DocumentRoutesDescriptor;
import org.hibernate.search.util.common.serialization.spi.SerializationUtils;

public final class OutboxEvent {

public enum Type {
ADD, ADD_OR_UPDATE, DELETE
}
public final class OutboxEvent implements OutboxEventBase {

private Integer id;
private Type type;
Expand All @@ -41,6 +37,7 @@ public OutboxEvent(
this.originalEntityId = originalEntityId;
}

@Override
public Integer getId() {
return id;
}
Expand All @@ -49,6 +46,7 @@ public void setId(Integer id) {
this.id = id;
}

@Override
public Type getType() {
return type;
}
Expand All @@ -57,6 +55,7 @@ public void setType(Type type) {
this.type = type;
}

@Override
public String getEntityName() {
return entityName;
}
Expand All @@ -65,6 +64,7 @@ public void setEntityName(String entityName) {
this.entityName = entityName;
}

@Override
public String getEntityId() {
return entityId;
}
Expand All @@ -73,6 +73,7 @@ public void setEntityId(String entityId) {
this.entityId = entityId;
}

@Override
public byte[] getDocumentRoutes() {
return documentRoutes;
}
Expand Down
@@ -0,0 +1,110 @@
/*
* Hibernate Search, full-text search for your domain model
*
* 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 org.hibernate.search.mapper.orm.outbox.impl;

import java.util.Arrays;
import java.util.Objects;

public class OutboxEventRetry implements OutboxEventBase {

private Integer id;

private String entityName;
private String entityId;
private byte[] documentRoutes;

private int retries = 0;

public OutboxEventRetry() {
}

public OutboxEventRetry(OutboxEventReference eventReference, byte[] documentRoutes) {
this.entityName = eventReference.getEntityName();
this.entityId = eventReference.getEntityId();
this.documentRoutes = documentRoutes;
}

@Override
public Integer getId() {
return id;
}

@Override
public Type getType() {
return Type.ADD_OR_UPDATE;
}

public void setId(Integer id) {
this.id = id;
}

@Override
public String getEntityName() {
return entityName;
}

public void setEntityName(String entityName) {
this.entityName = entityName;
}

@Override
public String getEntityId() {
return entityId;
}

public void setEntityId(String entityId) {
this.entityId = entityId;
}

@Override
public byte[] getDocumentRoutes() {
return documentRoutes;
}

public void setDocumentRoutes(byte[] documentRoutes) {
this.documentRoutes = documentRoutes;
}

public int getRetries() {
return retries;
}

public void setRetries(int retries) {
this.retries = retries;
}

@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
OutboxEventRetry that = (OutboxEventRetry) o;
return Objects.equals( entityName, that.entityName ) && Objects.equals(
entityId, that.entityId ) && Arrays.equals( documentRoutes, that.documentRoutes );
}

@Override
public int hashCode() {
int result = Objects.hash( entityName, entityId );
result = 31 * result + Arrays.hashCode( documentRoutes );
return result;
}

@Override
public String toString() {
return "OutboxEventRetry{" +
"id=" + id +
", entityName='" + entityName + '\'' +
", entityId='" + entityId + '\'' +
", documentRoutes=" + Arrays.toString( documentRoutes ) +
", retries=" + retries +
'}';
}
}

0 comments on commit 9552453

Please sign in to comment.