DATAES-369 - Polishing.

Fix linebreaks.
This commit is contained in:
Mark Paluch 2017-06-30 11:42:38 +02:00
parent b5bab6b85e
commit 7dba0441bb
4 changed files with 1530 additions and 1530 deletions

View File

@ -1,52 +1,52 @@
/* /*
* Copyright 2013-2017 the original author or authors. * Copyright 2013-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.elasticsearch.core.mapping; package org.springframework.data.elasticsearch.core.mapping;
import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentEntity;
/** /**
* ElasticsearchPersistentEntity * ElasticsearchPersistentEntity
* *
* @author Rizwan Idrees * @author Rizwan Idrees
* @author Mohsin Husen * @author Mohsin Husen
* @author Mark Paluch * @author Mark Paluch
*/ */
public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, ElasticsearchPersistentProperty> { public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, ElasticsearchPersistentProperty> {
String getIndexName(); String getIndexName();
String getIndexType(); String getIndexType();
short getShards(); short getShards();
short getReplicas(); short getReplicas();
boolean isUseServerConfiguration(); boolean isUseServerConfiguration();
String getRefreshInterval(); String getRefreshInterval();
String getIndexStoreType(); String getIndexStoreType();
ElasticsearchPersistentProperty getVersionProperty(); ElasticsearchPersistentProperty getVersionProperty();
String getParentType(); String getParentType();
ElasticsearchPersistentProperty getParentIdProperty(); ElasticsearchPersistentProperty getParentIdProperty();
String settingPath(); String settingPath();
boolean isCreateIndexAndMapping(); boolean isCreateIndexAndMapping();
} }

View File

@ -1,171 +1,171 @@
/* /*
* Copyright 2013-2017 the original author or authors. * Copyright 2013-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.elasticsearch.core.mapping; package org.springframework.data.elasticsearch.core.mapping;
import static org.springframework.util.StringUtils.*; import static org.springframework.util.StringUtils.*;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.expression.BeanFactoryAccessor; import org.springframework.context.expression.BeanFactoryAccessor;
import org.springframework.context.expression.BeanFactoryResolver; import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Parent; import org.springframework.data.elasticsearch.annotations.Parent;
import org.springframework.data.elasticsearch.annotations.Setting; import org.springframework.data.elasticsearch.annotations.Setting;
import org.springframework.data.mapping.model.BasicPersistentEntity; import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.util.TypeInformation; import org.springframework.data.util.TypeInformation;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext; import org.springframework.expression.ParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Elasticsearch specific {@link org.springframework.data.mapping.PersistentEntity} implementation holding * Elasticsearch specific {@link org.springframework.data.mapping.PersistentEntity} implementation holding
* *
* @param <T> * @param <T>
* @author Rizwan Idrees * @author Rizwan Idrees
* @author Mohsin Husen * @author Mohsin Husen
* @author Mark Paluch * @author Mark Paluch
*/ */
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty> public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
implements ElasticsearchPersistentEntity<T>, ApplicationContextAware { implements ElasticsearchPersistentEntity<T>, ApplicationContextAware {
private final StandardEvaluationContext context; private final StandardEvaluationContext context;
private final SpelExpressionParser parser; private final SpelExpressionParser parser;
private String indexName; private String indexName;
private String indexType; private String indexType;
private boolean useServerConfiguration; private boolean useServerConfiguration;
private short shards; private short shards;
private short replicas; private short replicas;
private String refreshInterval; private String refreshInterval;
private String indexStoreType; private String indexStoreType;
private String parentType; private String parentType;
private ElasticsearchPersistentProperty parentIdProperty; private ElasticsearchPersistentProperty parentIdProperty;
private String settingPath; private String settingPath;
private boolean createIndexAndMapping; private boolean createIndexAndMapping;
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) { public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
super(typeInformation); super(typeInformation);
this.context = new StandardEvaluationContext(); this.context = new StandardEvaluationContext();
this.parser = new SpelExpressionParser(); this.parser = new SpelExpressionParser();
Class<T> clazz = typeInformation.getType(); Class<T> clazz = typeInformation.getType();
if (clazz.isAnnotationPresent(Document.class)) { if (clazz.isAnnotationPresent(Document.class)) {
Document document = clazz.getAnnotation(Document.class); Document document = clazz.getAnnotation(Document.class);
Assert.hasText(document.indexName(), Assert.hasText(document.indexName(),
" Unknown indexName. Make sure the indexName is defined. e.g @Document(indexName=\"foo\")"); " Unknown indexName. Make sure the indexName is defined. e.g @Document(indexName=\"foo\")");
this.indexName = document.indexName(); this.indexName = document.indexName();
this.indexType = hasText(document.type()) ? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH); this.indexType = hasText(document.type()) ? document.type() : clazz.getSimpleName().toLowerCase(Locale.ENGLISH);
this.useServerConfiguration = document.useServerConfiguration(); this.useServerConfiguration = document.useServerConfiguration();
this.shards = document.shards(); this.shards = document.shards();
this.replicas = document.replicas(); this.replicas = document.replicas();
this.refreshInterval = document.refreshInterval(); this.refreshInterval = document.refreshInterval();
this.indexStoreType = document.indexStoreType(); this.indexStoreType = document.indexStoreType();
this.createIndexAndMapping = document.createIndex(); this.createIndexAndMapping = document.createIndex();
} }
if (clazz.isAnnotationPresent(Setting.class)) { if (clazz.isAnnotationPresent(Setting.class)) {
this.settingPath = typeInformation.getType().getAnnotation(Setting.class).settingPath(); this.settingPath = typeInformation.getType().getAnnotation(Setting.class).settingPath();
} }
} }
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context.addPropertyAccessor(new BeanFactoryAccessor()); context.addPropertyAccessor(new BeanFactoryAccessor());
context.setBeanResolver(new BeanFactoryResolver(applicationContext)); context.setBeanResolver(new BeanFactoryResolver(applicationContext));
context.setRootObject(applicationContext); context.setRootObject(applicationContext);
} }
@Override @Override
public String getIndexName() { public String getIndexName() {
Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION); Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION);
return expression.getValue(context, String.class); return expression.getValue(context, String.class);
} }
@Override @Override
public String getIndexType() { public String getIndexType() {
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION); Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
return expression.getValue(context, String.class); return expression.getValue(context, String.class);
} }
@Override @Override
public String getIndexStoreType() { public String getIndexStoreType() {
return indexStoreType; return indexStoreType;
} }
@Override @Override
public short getShards() { public short getShards() {
return shards; return shards;
} }
@Override @Override
public short getReplicas() { public short getReplicas() {
return replicas; return replicas;
} }
@Override @Override
public boolean isUseServerConfiguration() { public boolean isUseServerConfiguration() {
return useServerConfiguration; return useServerConfiguration;
} }
@Override @Override
public String getRefreshInterval() { public String getRefreshInterval() {
return refreshInterval; return refreshInterval;
} }
@Override @Override
public String getParentType() { public String getParentType() {
return parentType; return parentType;
} }
@Override @Override
public ElasticsearchPersistentProperty getParentIdProperty() { public ElasticsearchPersistentProperty getParentIdProperty() {
return parentIdProperty; return parentIdProperty;
} }
@Override @Override
public String settingPath() { public String settingPath() {
return settingPath; return settingPath;
} }
@Override @Override
public boolean isCreateIndexAndMapping() { public boolean isCreateIndexAndMapping() {
return createIndexAndMapping; return createIndexAndMapping;
} }
@Override @Override
public void addPersistentProperty(ElasticsearchPersistentProperty property) { public void addPersistentProperty(ElasticsearchPersistentProperty property) {
super.addPersistentProperty(property); super.addPersistentProperty(property);
Parent annotation = property.findAnnotation(Parent.class); Parent annotation = property.findAnnotation(Parent.class);
if (annotation != null) { if (annotation != null) {
Assert.isNull(this.parentIdProperty, "Only one field can hold a @Parent annotation"); Assert.isNull(this.parentIdProperty, "Only one field can hold a @Parent annotation");
Assert.isNull(this.parentType, "Only one field can hold a @Parent annotation"); Assert.isNull(this.parentType, "Only one field can hold a @Parent annotation");
Assert.isTrue(property.getType() == String.class, "Parent ID property should be String"); Assert.isTrue(property.getType() == String.class, "Parent ID property should be String");
this.parentIdProperty = property; this.parentIdProperty = property;
this.parentType = annotation.type(); this.parentType = annotation.type();
} }
if (property.isVersionProperty()) { if (property.isVersionProperty()) {
Assert.isTrue(property.getType() == Long.class, "Version property should be Long"); Assert.isTrue(property.getType() == Long.class, "Version property should be Long");
} }
} }
} }

View File

@ -1,94 +1,94 @@
/* /*
* Copyright 2013-2017 the original author or authors. * Copyright 2013-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.elasticsearch.repository.support; package org.springframework.data.elasticsearch.repository.support;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
import org.springframework.data.repository.core.support.PersistentEntityInformation; import org.springframework.data.repository.core.support.PersistentEntityInformation;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Elasticsearch specific implementation of * Elasticsearch specific implementation of
* {@link org.springframework.data.repository.core.support.AbstractEntityInformation} * {@link org.springframework.data.repository.core.support.AbstractEntityInformation}
* *
* @param <T> * @param <T>
* @param <ID> * @param <ID>
* @author Rizwan Idrees * @author Rizwan Idrees
* @author Mohsin Husen * @author Mohsin Husen
* @author Ryan Henszey * @author Ryan Henszey
* @author Oliver Gierke * @author Oliver Gierke
* @author Mark Paluch * @author Mark Paluch
* @author Christoph Strobl * @author Christoph Strobl
*/ */
public class MappingElasticsearchEntityInformation<T, ID> extends PersistentEntityInformation<T, ID> public class MappingElasticsearchEntityInformation<T, ID> extends PersistentEntityInformation<T, ID>
implements ElasticsearchEntityInformation<T, ID> { implements ElasticsearchEntityInformation<T, ID> {
private final ElasticsearchPersistentEntity<T> entityMetadata; private final ElasticsearchPersistentEntity<T> entityMetadata;
private final String indexName; private final String indexName;
private final String type; private final String type;
public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity) { public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity) {
this(entity, entity.getIndexName(), entity.getIndexType()); this(entity, entity.getIndexName(), entity.getIndexType());
} }
public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity, String indexName, String type) { public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity, String indexName, String type) {
super(entity); super(entity);
Assert.notNull(indexName, "IndexName must not be null!"); Assert.notNull(indexName, "IndexName must not be null!");
Assert.notNull(type, "IndexType must not be null!"); Assert.notNull(type, "IndexType must not be null!");
this.entityMetadata = entity; this.entityMetadata = entity;
this.indexName = indexName; this.indexName = indexName;
this.type = type; this.type = type;
} }
@Override @Override
public String getIdAttribute() { public String getIdAttribute() {
return entityMetadata.getRequiredIdProperty().getFieldName(); return entityMetadata.getRequiredIdProperty().getFieldName();
} }
@Override @Override
public String getIndexName() { public String getIndexName() {
return indexName; return indexName;
} }
@Override @Override
public String getType() { public String getType() {
return type; return type;
} }
@Override @Override
public Long getVersion(T entity) { public Long getVersion(T entity) {
ElasticsearchPersistentProperty versionProperty = entityMetadata.getVersionProperty(); ElasticsearchPersistentProperty versionProperty = entityMetadata.getVersionProperty();
try { try {
return versionProperty != null ? (Long) entityMetadata.getPropertyAccessor(entity).getProperty(versionProperty) : null; return versionProperty != null ? (Long) entityMetadata.getPropertyAccessor(entity).getProperty(versionProperty) : null;
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("failed to load version field", e); throw new IllegalStateException("failed to load version field", e);
} }
} }
@Override @Override
public String getParentId(T entity) { public String getParentId(T entity) {
ElasticsearchPersistentProperty parentProperty = entityMetadata.getParentIdProperty(); ElasticsearchPersistentProperty parentProperty = entityMetadata.getParentIdProperty();
try { try {
return parentProperty != null ? (String) entityMetadata.getPropertyAccessor(entity).getProperty(parentProperty) : null; return parentProperty != null ? (String) entityMetadata.getPropertyAccessor(entity).getProperty(parentProperty) : null;
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("failed to load parent ID: " + e, e); throw new IllegalStateException("failed to load parent ID: " + e, e);
} }
} }
} }