Skip to content

Commit

Permalink
code style and optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
axholo committed Jul 9, 2020
1 parent 382fdab commit 97f9707
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public DefaultJpaDatastore() {
super(JpaDatastoreCommodityFactory.class, JpaDatastoreExpressionResolver.class);

// EntityManager lifecycle
setEntityManagerInitializer((emf) -> emf.createEntityManager());
setEntityManagerFinalizer((em) -> em.close());
setEntityManagerInitializer(emf -> emf.createEntityManager());
setEntityManagerFinalizer(em -> em.close());

// register resolvers
addExpressionResolver(NullExpressionResolver.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public class DefaultJPQLContextParametersHandler implements JPQLContextParameter

private static final long serialVersionUID = 3466242242359565279L;

private final static Logger LOGGER = JpqlDatastoreLogger.create();
private static final Logger LOGGER = JpqlDatastoreLogger.create();

/**
* Named parameters
*/
private final Map<String, JPQLParameter<?>> namedParameters = new HashMap<>();
private final transient Map<String, JPQLParameter<?>> namedParameters = new HashMap<>();

@Override
public <T> String addNamedParameter(JPQLParameter<T> parameter) {
Expand All @@ -63,7 +63,8 @@ public Map<String, JPQLParameter<?>> getNamedParameters() {
}

/**
* Generate a named parameter name. By default, the pattern <code>:[001]</code> is used.
* Generate a named parameter name. By default, the pattern <code>:[001]</code>
* is used.
* @param index Parameter index
* @return Parameter name
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class DefaultJpaEntity<T> implements JpaEntity<T> {
/**
* Logger
*/
private final static Logger LOGGER = JpaDatastoreLogger.create();
private static final Logger LOGGER = JpaDatastoreLogger.create();

/**
* Entity class
Expand All @@ -66,21 +66,21 @@ public class DefaultJpaEntity<T> implements JpaEntity<T> {
/**
* Identifier metadata
*/
private IdMetadata<T> idMetadata;
private transient IdMetadata<T> idMetadata;

/**
* Version attribute
*/
private SingularAttribute<? super T, ?> versionAttribute;
private transient SingularAttribute<? super T, ?> versionAttribute;

/**
* Entity class property set
*/
private final BeanPropertySet<T> beanPropertySet;
private final transient BeanPropertySet<T> beanPropertySet;

/**
* Constructor.
* @param metamodel JPA Metamodel (not null)
* @param metamodel JPA Metamodel (not null)
* @param entityClass Entity class (not null)
*/
public DefaultJpaEntity(Metamodel metamodel, Class<T> entityClass) {
Expand Down Expand Up @@ -122,6 +122,7 @@ public DefaultJpaEntity(Metamodel metamodel, Class<T> entityClass) {

/*
* (non-Javadoc)
*
* @see com.holonplatform.datastore.jpa.internal.JpaEntity#getEntityClass()
*/
@Override
Expand All @@ -131,6 +132,7 @@ public Class<T> getEntityClass() {

/*
* (non-Javadoc)
*
* @see com.holonplatform.datastore.jpa.internal.JpaEntity#getEntityName()
*/
@Override
Expand All @@ -140,6 +142,7 @@ public String getEntityName() {

/*
* (non-Javadoc)
*
* @see com.holonplatform.core.Expression#validate()
*/
@Override
Expand All @@ -154,6 +157,7 @@ public void validate() throws InvalidExpressionException {

/*
* (non-Javadoc)
*
* @see com.holonplatform.datastore.jpa.jpql.expression.JpaEntity#getIdType()
*/
@Override
Expand All @@ -163,7 +167,9 @@ public Optional<Class<?>> getIdType() {

/*
* (non-Javadoc)
* @see com.holonplatform.datastore.jpa.jpql.expression.JpaEntity#hasCompositeId()
*
* @see
* com.holonplatform.datastore.jpa.jpql.expression.JpaEntity#hasCompositeId()
*/
@Override
public boolean hasCompositeId() {
Expand All @@ -172,7 +178,10 @@ public boolean hasCompositeId() {

/*
* (non-Javadoc)
* @see com.holonplatform.datastore.jpa.jpql.expression.JpaEntity#getId(java.lang.Object)
*
* @see
* com.holonplatform.datastore.jpa.jpql.expression.JpaEntity#getId(java.lang.
* Object)
*/
@Override
public Optional<Object> getId(T entity) {
Expand Down Expand Up @@ -206,7 +215,10 @@ public Optional<Object> getId(T entity) {

/*
* (non-Javadoc)
* @see com.holonplatform.datastore.jpa.jpql.expression.JpaEntity#isNew(java.lang.Object)
*
* @see
* com.holonplatform.datastore.jpa.jpql.expression.JpaEntity#isNew(java.lang.
* Object)
*/
@Override
public boolean isNew(T entity) {
Expand Down Expand Up @@ -263,7 +275,8 @@ public boolean isNew(T entity) {
/**
* Get the entity identifier metadata
* @return The entity identifier metadata
* @throws IllegalStateException if the entity identifier metadata is not available
* @throws IllegalStateException if the entity identifier metadata is not
* available
*/
protected IdMetadata<T> getIdMetadata() {
if (idMetadata == null) {
Expand All @@ -275,7 +288,7 @@ protected IdMetadata<T> getIdMetadata() {

/**
* Checks whether given identifier value is to be considered <code>null</code>.
* @param id Identifier value
* @param id Identifier value
* @param type Identifier value type
* @return <code>true</code> if it is to be considered <code>null</code>
*/
Expand All @@ -287,10 +300,12 @@ private static boolean isNullIdValue(Object id, Class<?> type) {
}

/**
* Get the entity name using {@link Entity#name()} annotation attribute, if available.
* Get the entity name using {@link Entity#name()} annotation attribute, if
* available.
* @param entityClass Entity class (not null)
* @return The entity name as specified using {@link Entity#name()} annotation attribute, or an empty Optional if
* the {@link Entity} annotation is not present or the <code>name</code> attribute has no value
* @return The entity name as specified using {@link Entity#name()} annotation
* attribute, or an empty Optional if the {@link Entity} annotation is
* not present or the <code>name</code> attribute has no value
*/
private static Optional<String> getEntityNameFromAnnotation(Class<?> entityClass) {
if (entityClass.isAnnotationPresent(Entity.class)) {
Expand All @@ -303,9 +318,10 @@ private static Optional<String> getEntityNameFromAnnotation(Class<?> entityClass
}

/**
* Try to obtain the <em>version</em> attribute of the entity type, if available.
* Try to obtain the <em>version</em> attribute of the entity type, if
* available.
* @param metamodel JPA Metamodel
* @param type Entity type
* @param type Entity type
* @return Optional version attribute
*/
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Optional<JPQLProjection> resolve(BeanProjection expression, JPQLResolutio

final BeanPropertySet<?> bps = BeanIntrospector.get().getPropertySet(expression.getBeanClass());

List<Path> selection = ((BeanProjection<?>) expression).getSelection().map(s -> Arrays.asList(s)).orElse(null);
List<Path> selection = ((BeanProjection<?>) expression).getSelection().map(Arrays::asList).orElse(null);
if (selection == null) {
// use bean property set
selection = bps.stream().map(p -> (Path) p).collect(Collectors.toList());
Expand All @@ -91,7 +91,7 @@ public Optional<JPQLProjection> resolve(BeanProjection expression, JPQLResolutio
final List<Path<?>> selectionPaths = new ArrayList<>(selection.size());
final Map<Path<?>, String> selectionAlias = new LinkedHashMap<>();

for (Path<?> path : selection) {
for (Path path : selection) {
if (QueryExpression.class.isAssignableFrom(path.getClass())) {
selectionPaths.add(path);
final String alias = projection.addSelection(
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<bytebuddy.version>1.10.13</bytebuddy.version>

<!-- Test: H2 -->
<h2.version>1.4.200</h2.version>
<h2.version>1.4.198</h2.version>

</properties>

Expand Down

0 comments on commit 97f9707

Please sign in to comment.