Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-4153 Implement loading for the JavaBean mapper
Signed-off-by: Yoann Rodière <yoann@hibernate.org>
- Loading branch information
Showing
12 changed files
with
177 additions
and
13 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
mapper/javabean/src/main/java/org/hibernate/search/mapper/javabean/loading/EntityLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.javabean.loading; | ||
|
||
import java.util.List; | ||
|
||
public interface EntityLoader<E> { | ||
|
||
/** | ||
* Loads the entities corresponding to the given identifiers, blocking the current thread while doing so. | ||
* | ||
* @param identifiers A list of identifiers for objects to load. | ||
* @return A list of entities, in the same order the identifiers were given. | ||
* {@code null} is inserted when an object is not found or has the wrong concrete type. | ||
*/ | ||
List<E> load(List<?> identifiers); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...r/javabean/src/main/java/org/hibernate/search/mapper/javabean/loading/LoadingOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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.javabean.loading; | ||
|
||
public interface LoadingOptions { | ||
|
||
<T> LoadingOptions registerLoader(Class<T> type, EntityLoader<T> loader); | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...abean/src/main/java/org/hibernate/search/mapper/javabean/loading/impl/JavaBeanLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.javabean.loading.impl; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.search.engine.common.timing.spi.Deadline; | ||
import org.hibernate.search.mapper.javabean.loading.EntityLoader; | ||
import org.hibernate.search.mapper.pojo.loading.spi.PojoLoader; | ||
import org.hibernate.search.mapper.pojo.model.spi.PojoRawTypeIdentifier; | ||
|
||
public class JavaBeanLoader<E> implements PojoLoader<E> { | ||
|
||
private final EntityLoader<E> delegate; | ||
|
||
public JavaBeanLoader(EntityLoader<E> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public List<?> loadBlocking(List<?> identifiers, Deadline deadline) { | ||
return delegate.load( identifiers ); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <E2 extends E> E2 castToExactTypeOrNull(PojoRawTypeIdentifier<E2> expectedType, Object loadedObject) { | ||
if ( expectedType.javaClass().equals( loadedObject.getClass() ) ) { | ||
return (E2) loadedObject; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...n/src/main/java/org/hibernate/search/mapper/javabean/loading/impl/LoadingTypeContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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.javabean.loading.impl; | ||
|
||
import org.hibernate.search.mapper.pojo.model.spi.PojoRawTypeIdentifier; | ||
|
||
public interface LoadingTypeContext<E> { | ||
|
||
PojoRawTypeIdentifier<E> typeIdentifier(); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...in/java/org/hibernate/search/mapper/javabean/loading/impl/LoadingTypeContextProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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.javabean.loading.impl; | ||
|
||
public interface LoadingTypeContextProvider { | ||
|
||
<E> LoadingTypeContext<E> indexedForExactClass(Class<E> typeIdentifier); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters