DATACMNS-919 - Removed deprecated DomainClassPropertyEditor and -Registrar.
This commit is contained in:
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008-2013 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.springframework.data.repository.support;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.beans.PropertyEditorRegistry;
|
||||
import org.springframework.beans.SimpleTypeConverter;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Generic {@link PropertyEditor} to map entities handled by a {@link CrudRepository} to their id's and vice versa.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class DomainClassPropertyEditor<T, ID extends Serializable> extends PropertyEditorSupport {
|
||||
|
||||
private final RepositoryInvoker invoker;
|
||||
private final EntityInformation<T, ID> information;
|
||||
private final PropertyEditorRegistry registry;
|
||||
|
||||
/**
|
||||
* Creates a new {@link DomainClassPropertyEditor} for the given repository, {@link EntityInformation} and
|
||||
* {@link PropertyEditorRegistry}.
|
||||
*
|
||||
* @param invoker must not be {@literal null}.
|
||||
* @param information must not be {@literal null}.
|
||||
* @param registry must not be {@literal null}.
|
||||
*/
|
||||
public DomainClassPropertyEditor(RepositoryInvoker invoker, EntityInformation<T, ID> information,
|
||||
PropertyEditorRegistry registry) {
|
||||
|
||||
Assert.notNull(invoker);
|
||||
Assert.notNull(information);
|
||||
Assert.notNull(registry);
|
||||
|
||||
this.invoker = invoker;
|
||||
this.information = information;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String idAsString) {
|
||||
|
||||
if (!StringUtils.hasText(idAsString)) {
|
||||
setValue(null);
|
||||
return;
|
||||
}
|
||||
|
||||
setValue(invoker.invokeFindOne(getId(idAsString)));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#getAsText()
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getAsText() {
|
||||
|
||||
T entity = (T) getValue();
|
||||
|
||||
if (null == entity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object id = getId(entity);
|
||||
return id == null ? null : id.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the id of the given entity using one of the {@link org.synyx.hades.dao.orm.GenericDaoSupport.IdAware}
|
||||
* implementations of Hades.
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
private ID getId(T entity) {
|
||||
|
||||
return information.getId(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the actual typed id. Looks up an available customly registered {@link PropertyEditor} from the
|
||||
* {@link PropertyEditorRegistry} before falling back on a {@link SimpleTypeConverter} to translate the {@link String}
|
||||
* id into the type one.
|
||||
*
|
||||
* @param idAsString
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private ID getId(String idAsString) {
|
||||
|
||||
Class<ID> idClass = information.getIdType();
|
||||
|
||||
PropertyEditor idEditor = registry.findCustomEditor(idClass, null);
|
||||
|
||||
if (idEditor != null) {
|
||||
idEditor.setAsText(idAsString);
|
||||
return (ID) idEditor.getValue();
|
||||
}
|
||||
|
||||
return new SimpleTypeConverter().convertIfNecessary(idAsString, idClass);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obj == null || this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DomainClassPropertyEditor<?, ?> that = (DomainClassPropertyEditor<?, ?>) obj;
|
||||
|
||||
return this.invoker.equals(that.invoker) && this.registry.equals(that.registry)
|
||||
&& this.information.equals(that.information);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int hashCode = 17;
|
||||
hashCode += invoker.hashCode() * 32;
|
||||
hashCode += information.hashCode() * 32;
|
||||
hashCode += registry.hashCode() * 32;
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008-2013 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.springframework.data.repository.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.beans.PropertyEditorRegistrar;
|
||||
import org.springframework.beans.PropertyEditorRegistry;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
/**
|
||||
* Simple helper class to use Hades DAOs to provide {@link java.beans.PropertyEditor}s for domain classes. To get this
|
||||
* working configure a {@link org.springframework.web.bind.support.ConfigurableWebBindingInitializer} for your
|
||||
* {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter} and register the
|
||||
* {@link DomainClassPropertyEditorRegistrar} there: <code>
|
||||
* <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
|
||||
* <property name="webBindingInitializer">
|
||||
* <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
|
||||
* <property name="propertyEditorRegistrars">
|
||||
* <bean class="org.springframework.data.extensions.beans.DomainClassPropertyEditorRegistrar" />
|
||||
* </property>
|
||||
* </bean>
|
||||
* </property>
|
||||
* </bean>
|
||||
* </code> Make sure this bean declaration is in the {@link ApplicationContext} created by the {@link DispatcherServlet}
|
||||
* whereas the repositories need to be declared in the root
|
||||
* {@link org.springframework.web.context.WebApplicationContext}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @deprecated use {@link DomainClassConverter} instead, will be removed in 1.10
|
||||
*/
|
||||
@Deprecated
|
||||
public class DomainClassPropertyEditorRegistrar implements PropertyEditorRegistrar, ApplicationContextAware {
|
||||
|
||||
private Repositories repositories = Repositories.NONE;
|
||||
private RepositoryInvokerFactory repositoryInvokerFactory;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.PropertyEditorRegistrar#registerCustomEditors(org.springframework.beans.PropertyEditorRegistry)
|
||||
*/
|
||||
public void registerCustomEditors(PropertyEditorRegistry registry) {
|
||||
|
||||
for (Class<?> domainClass : repositories) {
|
||||
|
||||
RepositoryInformation repositoryInformation = repositories.getRepositoryInformationFor(domainClass);
|
||||
RepositoryInvoker invoker = repositoryInvokerFactory.getInvokerFor(domainClass);
|
||||
|
||||
DomainClassPropertyEditor<Object, Serializable> editor = new DomainClassPropertyEditor<Object, Serializable>(
|
||||
invoker, repositories.getEntityInformationFor(repositoryInformation.getDomainType()), registry);
|
||||
|
||||
registry.registerCustomEditor(repositoryInformation.getDomainType(), editor);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
public void setApplicationContext(ApplicationContext context) {
|
||||
|
||||
this.repositories = new Repositories(context);
|
||||
this.repositoryInvokerFactory = new DefaultRepositoryInvokerFactory(repositories);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user