DATACMNS-525 - Removed Hazelcast implementation.
Original pull request: #95.
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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.keyvalue.hazelcast;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.keyvalue.core.AbstractKeyValueAdapter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.IMap;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class HazelcastKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
|
||||
private HazelcastInstance hzInstance;
|
||||
|
||||
public HazelcastKeyValueAdapter() {
|
||||
this(Hazelcast.newHazelcastInstance());
|
||||
}
|
||||
|
||||
public HazelcastKeyValueAdapter(HazelcastInstance hzInstance) {
|
||||
|
||||
super(new HazelcastQueryEngine());
|
||||
Assert.notNull(hzInstance, "hzInstance must not be 'null'.");
|
||||
this.hzInstance = hzInstance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object put(Serializable id, Object item, Serializable keyspace) {
|
||||
|
||||
Assert.notNull(id, "Id must not be 'null' for adding.");
|
||||
Assert.notNull(item, "Item must not be 'null' for adding.");
|
||||
|
||||
return getMap(keyspace).put(id, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Serializable id, Serializable keyspace) {
|
||||
return getMap(keyspace).containsKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(Serializable id, Serializable keyspace) {
|
||||
return getMap(keyspace).get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object delete(Serializable id, Serializable keyspace) {
|
||||
return getMap(keyspace).remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> getAllOf(Serializable keyspace) {
|
||||
return getMap(keyspace).values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllOf(Serializable keyspace) {
|
||||
getMap(keyspace).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
// TODO: remove all elements
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected IMap getMap(final Serializable keyspace) {
|
||||
|
||||
Assert.isInstanceOf(String.class, keyspace, "Keyspace identifier must of of type String.");
|
||||
return hzInstance.getMap((String) keyspace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
hzInstance.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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.keyvalue.hazelcast;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.data.keyvalue.core.CriteriaAccessor;
|
||||
import org.springframework.data.keyvalue.core.QueryEngine;
|
||||
import org.springframework.data.keyvalue.core.SortAccessor;
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
|
||||
import com.hazelcast.query.PagingPredicate;
|
||||
import com.hazelcast.query.Predicate;
|
||||
import com.hazelcast.query.PredicateBuilder;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class HazelcastQueryEngine extends QueryEngine<HazelcastKeyValueAdapter, Predicate<?, ?>, Comparator<Entry>> {
|
||||
|
||||
public HazelcastQueryEngine() {
|
||||
super(HazelcastCriteriaAccessor.INSTANCE, HazelcastSortAccessor.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> execute(Predicate<?, ?> criteria, Comparator<Entry> sort, int offset, int rows,
|
||||
Serializable keyspace) {
|
||||
|
||||
Predicate<?, ?> predicateToUse = criteria;
|
||||
|
||||
if (sort != null || offset > 0 || rows > 0) {
|
||||
PagingPredicate pp = new PagingPredicate(criteria, (Comparator<Entry>) sort, rows);
|
||||
if (offset > 0 && rows > 0) {
|
||||
int x = offset / rows;
|
||||
while (x > 0) {
|
||||
pp.nextPage();
|
||||
x--;
|
||||
}
|
||||
}
|
||||
predicateToUse = pp;
|
||||
}
|
||||
|
||||
return this.getAdapter().getMap(keyspace).values(predicateToUse);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count(Predicate<?, ?> criteria, Serializable keyspace) {
|
||||
return this.getAdapter().getMap(keyspace).keySet(criteria).size();
|
||||
}
|
||||
|
||||
static enum HazelcastCriteriaAccessor implements CriteriaAccessor<Predicate<?, ?>> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public Predicate<?, ?> resolve(KeyValueQuery<?> query) {
|
||||
|
||||
if (query == null || query.getCritieria() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (query.getCritieria() instanceof Predicate) {
|
||||
return (Predicate<?, ?>) query.getCritieria();
|
||||
}
|
||||
|
||||
if (query.getCritieria() instanceof PredicateBuilder) {
|
||||
return (PredicateBuilder) query.getCritieria();
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static enum HazelcastSortAccessor implements SortAccessor<Comparator<Entry>> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public Comparator<Entry> resolve(KeyValueQuery<?> query) {
|
||||
|
||||
if (query == null || query.getSort() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: create serializable sorter;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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.keyvalue.hazelcast.repository.config;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.keyvalue.core.KeyValueOperations;
|
||||
import org.springframework.data.keyvalue.hazelcast.repository.query.HazelcastQueryCreator;
|
||||
import org.springframework.data.keyvalue.repository.config.QueryCreatorType;
|
||||
import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactoryBean;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||
|
||||
/**
|
||||
* Annotation to activate Hazelcast repositories. If no base package is configured through either {@link #value()},
|
||||
* {@link #basePackages()} or {@link #basePackageClasses()} it will trigger scanning of the package of annotated class.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import(HazelcastRepositoriesRegistrar.class)
|
||||
@QueryCreatorType(HazelcastQueryCreator.class)
|
||||
public @interface EnableHazelcastRepositories {
|
||||
|
||||
/**
|
||||
* Alias for the {@link #basePackages()} attribute. Allows for more concise annotation declarations e.g.:
|
||||
* {@code @EnableJpaRepositories("org.my.pkg")} instead of {@code @EnableJpaRepositories(basePackages="org.my.pkg")}.
|
||||
*/
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Base packages to scan for annotated components. {@link #value()} is an alias for (and mutually exclusive with) this
|
||||
* attribute. Use {@link #basePackageClasses()} for a type-safe alternative to String-based package names.
|
||||
*/
|
||||
String[] basePackages() default {};
|
||||
|
||||
/**
|
||||
* Type-safe alternative to {@link #basePackages()} for specifying the packages to scan for annotated components. The
|
||||
* package of each class specified will be scanned. Consider creating a special no-op marker class or interface in
|
||||
* each package that serves no purpose other than being referenced by this attribute.
|
||||
*/
|
||||
Class<?>[] basePackageClasses() default {};
|
||||
|
||||
/**
|
||||
* Specifies which types are not eligible for component scanning.
|
||||
*/
|
||||
Filter[] excludeFilters() default {};
|
||||
|
||||
/**
|
||||
* Specifies which types are eligible for component scanning. Further narrows the set of candidate components from
|
||||
* everything in {@link #basePackages()} to everything in the base packages that matches the given filter or filters.
|
||||
*/
|
||||
Filter[] includeFilters() default {};
|
||||
|
||||
/**
|
||||
* Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So
|
||||
* for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning
|
||||
* for {@code PersonRepositoryImpl}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String repositoryImplementationPostfix() default "Impl";
|
||||
|
||||
/**
|
||||
* Configures the location of where to find the Spring Data named queries properties file.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String namedQueriesLocation() default "";
|
||||
|
||||
/**
|
||||
* Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to
|
||||
* {@link Key#CREATE_IF_NOT_FOUND}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND;
|
||||
|
||||
/**
|
||||
* Returns the {@link FactoryBean} class to be used for each repository instance. Defaults to
|
||||
* {@link KeyValueRepositoryFactoryBean}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<?> repositoryFactoryBeanClass() default KeyValueRepositoryFactoryBean.class;
|
||||
|
||||
/**
|
||||
* Configures the name of the {@link KeyValueOperations} bean to be used with the repositories detected.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String keyValueTemplateRef() default "keyValueTemplate";
|
||||
|
||||
/**
|
||||
* Configures whether nested repository-interfaces (e.g. defined as inner classes) should be discovered by the
|
||||
* repositories infrastructure.
|
||||
*/
|
||||
boolean considerNestedRepositories() default false;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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.keyvalue.hazelcast.repository.config;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.springframework.data.keyvalue.repository.config.KeyValueRepositoriesRegistrar;
|
||||
|
||||
/**
|
||||
* Special {@link KeyValueRepositoriesRegistrar} to point the infrastructure to inspect
|
||||
* {@link EnableHazelcastRepositories}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class HazelcastRepositoriesRegistrar extends KeyValueRepositoriesRegistrar {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.repository.config.KeyValueRepositoriesRegistrar#getAnnotation()
|
||||
*/
|
||||
@Override
|
||||
protected Class<? extends Annotation> getAnnotation() {
|
||||
return EnableHazelcastRepositories.class;
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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.keyvalue.hazelcast.repository.query;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
import org.springframework.data.keyvalue.ehcache.repository.query.EhCacheQueryCreator;
|
||||
import org.springframework.data.repository.query.ParameterAccessor;
|
||||
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
||||
import org.springframework.data.repository.query.parser.Part;
|
||||
import org.springframework.data.repository.query.parser.PartTree;
|
||||
|
||||
import com.hazelcast.query.EntryObject;
|
||||
import com.hazelcast.query.Predicate;
|
||||
import com.hazelcast.query.PredicateBuilder;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class HazelcastQueryCreator extends AbstractQueryCreator<KeyValueQuery<Predicate<?, ?>>, Predicate<?, ?>> {
|
||||
|
||||
private final PredicateBuilder predicateBuilder;
|
||||
|
||||
/**
|
||||
* Creates a new {@link EhCacheQueryCreator} for the given {@link PartTree}.
|
||||
*
|
||||
* @param tree must not be {@literal null}.
|
||||
*/
|
||||
public HazelcastQueryCreator(PartTree tree) {
|
||||
super(tree);
|
||||
this.predicateBuilder = new PredicateBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link HazelcastQueryCreator} for the given {@link PartTree} and {@link ParameterAccessor}. The
|
||||
* latter is used to hand actual parameter values into the callback methods as well as to apply dynamic sorting via a
|
||||
* {@link Sort} parameter.
|
||||
*
|
||||
* @param tree must not be {@literal null}.
|
||||
* @param parameters can be {@literal null}.
|
||||
*/
|
||||
public HazelcastQueryCreator(PartTree tree, ParameterAccessor parameters) {
|
||||
super(tree, parameters);
|
||||
this.predicateBuilder = new PredicateBuilder();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.parser.AbstractQueryCreator#create(org.springframework.data.repository.query.parser.Part, java.util.Iterator)
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<?, ?> create(Part part, Iterator<Object> iterator) {
|
||||
return from(predicateBuilder, part, iterator);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.parser.AbstractQueryCreator#and(org.springframework.data.repository.query.parser.Part, java.lang.Object, java.util.Iterator)
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<?, ?> and(Part part, Predicate<?, ?> base, Iterator<Object> iterator) {
|
||||
return predicateBuilder.and(from(predicateBuilder, part, iterator));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.parser.AbstractQueryCreator#or(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<?, ?> or(Predicate<?, ?> base, Predicate<?, ?> criteria) {
|
||||
return predicateBuilder.or(criteria);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.parser.AbstractQueryCreator#complete(java.lang.Object, org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
protected KeyValueQuery<Predicate<?, ?>> complete(Predicate<?, ?> criteria, Sort sort) {
|
||||
return new KeyValueQuery<Predicate<?, ?>>(criteria);
|
||||
}
|
||||
|
||||
private Predicate<?, ?> from(PredicateBuilder pb, Part part, Iterator<Object> iterator) {
|
||||
|
||||
EntryObject e = pb.getEntryObject();
|
||||
e.get(part.getProperty().toDotPath());
|
||||
|
||||
switch (part.getType()) {
|
||||
case TRUE:
|
||||
return e.equal(true);
|
||||
case FALSE:
|
||||
return e.equal(false);
|
||||
case SIMPLE_PROPERTY:
|
||||
return e.equal((Comparable<?>) iterator.next());
|
||||
case IS_NULL:
|
||||
return e.isNull();
|
||||
case GREATER_THAN:
|
||||
return e.greaterThan((Comparable<?>) iterator.next());
|
||||
|
||||
default:
|
||||
throw new InvalidDataAccessApiUsageException(String.format("Found invalid part '%s' in query", part.getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user