Skip to content

Commit

Permalink
Merge pull request #48 from mmnaseri/release-v1.0.3
Browse files Browse the repository at this point in the history
Release v1.0.3
  • Loading branch information
mmnaseri committed Apr 18, 2016
2 parents e2da430 + 77ad7be commit 185af08
Show file tree
Hide file tree
Showing 470 changed files with 747 additions and 220 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
language: java
jdk:
- oraclejdk8
- oraclejdk7
- oraclejdk8
script:
- cd spring-data-mock
- mvn test -B
after_success:
- cd spring-data-mock-parent
- mvn -P coverage clean cobertura:cobertura coveralls:report
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 8)" == "x8" ) ]] && sudo apt-get install gnupg2'
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 8)" == "x8" ) ]] && bash deploy.sh eb1a6f34f056 key.asc.enc settings.xml'
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 8)" == "x8" ) ]] && bash ../deployment/deploy.sh eb1a6f34f056 ../deployment/key.asc.enc ../deployment/settings.xml'
# SUDO should be set to `false` except when deploying to OSSRH to trigger container infrastructure
sudo: true
env:
global:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
84 changes: 84 additions & 0 deletions spring-data-mock-build/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2016 Milad Naseri
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this
~ software and associated documentation files (the "Software"), to deal in the Software
~ without restriction, including without limitation the rights to use, copy, modify, merge,
~ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
~ to whom the Software is furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all copies or
~ substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
~ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
~ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
~ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
~ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mmnaseri.utils</groupId>
<artifactId>spring-data-mock-build</artifactId>
<version>1.0.2</version>
<name>Spring Data Mock: Build Aggregator</name>
<description>This is the build module that will aggregate all reactors for the spring-data-mock project</description>
<url>https://mmnaseri.github.io/spring-data-mock</url>
<packaging>pom</packaging>

<licenses>
<license>
<name>MIT</name>
<url>http://mit-license.org</url>
</license>
</licenses>

<developers>
<developer>
<name>Milad Naseri</name>
<email>[email protected]</email>
<url>http://www.mmnaseri.com</url>
<roles>
<role>designer</role>
<role>developer</role>
</roles>
</developer>
</developers>

<scm>
<connection>scm:git:[email protected]:mmnaseri/spring-data-mock.git</connection>
<developerConnection>scm:git:[email protected]:mmnaseri/spring-data-mock.git</developerConnection>
<url>[email protected]:mmnaseri/spring-data-mock.git</url>
</scm>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${target-jdk.version}</source>
<target>${target-jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>

<modules>
<module>../spring-data-mock/</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<target-jdk.version>1.7</target-jdk.version>
</properties>

</project>
2 changes: 1 addition & 1 deletion pom.xml → spring-data-mock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<groupId>com.mmnaseri.utils</groupId>
<artifactId>spring-data-mock</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<name>Spring Data Mock</name>
<description>A framework for mocking Spring Data repositories</description>
<url>https://mmnaseri.github.io/spring-data-mock</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mmnaseri.utils.spring.data.domain;

/**
* Represents an operator that was picked because of a parse operation
*
* @author Mohammad Milad Naseri ([email protected])
* @since 1.0 (4/17/16, 12:36 PM)
*/
public interface MatchedOperator extends Operator {

/**
* @return the suffix that was matched when looking up this operator
*/
String getMatchedToken();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.mmnaseri.utils.spring.data.domain.impl;

import com.mmnaseri.utils.spring.data.domain.Operator;
import com.mmnaseri.utils.spring.data.domain.OperatorContext;
import com.mmnaseri.utils.spring.data.domain.impl.matchers.*;
import com.mmnaseri.utils.spring.data.error.DuplicateOperatorException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Arrays;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

/**
* This class is used to store the operators used in the name of a query method. Operators are matched by
* the "suffixes" eagerly (meaning that "EqualTo" will precede over "To").
*
* @author Milad Naseri ([email protected])
* @since 1.0 (9/29/15)
*/
public class DefaultOperatorContext implements OperatorContext {

private static final Log log = LogFactory.getLog(DefaultOperatorContext.class);
private final Set<Operator> operators;

public DefaultOperatorContext() {
this(true);
}

public DefaultOperatorContext(boolean registerDefaults) {
operators = new CopyOnWriteArraySet<>();
if (registerDefaults) {
log.info("Registering all the default operators");
operators.add(new ImmutableOperator("AFTER", 1, new IsGreaterThanMatcher(), "After", "IsAfter"));
operators.add(new ImmutableOperator("BEFORE", 1, new IsLessThanMatcher(), "Before", "IsBefore"));
operators.add(new ImmutableOperator("CONTAINING", 1, new ContainingMatcher(), "Containing", "IsContaining", "Contains"));
operators.add(new ImmutableOperator("BETWEEN", 2, new IsBetweenMatcher(), "Between", "IsBetween"));
operators.add(new ImmutableOperator("NOT_BETWEEN", 2, new IsNotBetweenMatcher(), "NotBetween", "IsNotBetween"));
operators.add(new ImmutableOperator("ENDING_WITH", 1, new EndingWithMatcher(), "EndingWith", "IsEndingWith", "EndsWith"));
operators.add(new ImmutableOperator("FALSE", 0, new IsFalseMatcher(), "False", "IsFalse"));
operators.add(new ImmutableOperator("GREATER_THAN", 1, new IsGreaterThanMatcher(), "GreaterThan", "IsGreaterThan"));
operators.add(new ImmutableOperator("GREATER_THAN_EQUALS", 1, new IsGreaterThanOrEqualToMatcher(), "GreaterThanEqual", "IsGreaterThanEqual"));
operators.add(new ImmutableOperator("IN", 1, new IsInMatcher(), "In", "IsIn"));
operators.add(new ImmutableOperator("IS", 1, new IsEqualToMatcher(), "Is", "EqualTo", "IsEqualTo", "Equals"));
operators.add(new ImmutableOperator("NOT_NULL", 0, new IsNotNullMatcher(), "NotNull", "IsNotNull"));
operators.add(new ImmutableOperator("NULL", 0, new IsNullMatcher(), "Null", "IsNull"));
operators.add(new ImmutableOperator("LESS_THAN", 1, new IsLessThanMatcher(), "LessThan", "IsLessThan"));
operators.add(new ImmutableOperator("LESS_THAN_EQUAL", 1, new IsLessThanOrEqualToMatcher(), "LessThanEqual", "IsLessThanEqual"));
operators.add(new ImmutableOperator("LIKE", 1, new IsLikeMatcher(), "Like", "IsLike"));
operators.add(new ImmutableOperator("NEAR", 1, null, "Near", "IsNear"));
operators.add(new ImmutableOperator("NOT", 1, new IsNotMatcher(), "IsNot", "Not", "IsNotEqualTo", "DoesNotEqual"));
operators.add(new ImmutableOperator("NOT_IN", 1, new IsNotInMatcher(), "NotIn", "IsNotIn"));
operators.add(new ImmutableOperator("NOT_LIKE", 1, new IsNotLikeMatcher(), "NotLike", "IsNotLike"));
operators.add(new ImmutableOperator("REGEX", 1, new RegexMatcher(), "Regex", "MatchesRegex", "Matches"));
operators.add(new ImmutableOperator("STARTING_WITH", 1, new StartingWithMatcher(), "StartingWith", "IsStartingWith", "StartsWith"));
operators.add(new ImmutableOperator("TRUE", 0, new IsTrueMatcher(), "True", "IsTrue"));
}
}

@Override
public void register(Operator operator) {
log.info("Registering operator " + operator.getName() + " which will respond to suffixes " + Arrays.toString(operator.getTokens()));
for (Operator item : operators) {
for (String token : item.getTokens()) {
for (String newToken : operator.getTokens()) {
if (newToken.equals(token)) {
throw new DuplicateOperatorException(item, token);
}
}
}
}
operators.add(operator);
}

@Override
public Operator getBySuffix(String suffix) {
for (Operator operator : operators) {
for (String token : operator.getTokens()) {
if (token.equals(suffix)) {
return operator;
}
}
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mmnaseri.utils.spring.data.domain.impl;

import com.mmnaseri.utils.spring.data.domain.RepositoryMetadata;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.repository.RepositoryDefinition;

/**
Expand All @@ -18,14 +20,17 @@
*/
public class DefaultRepositoryMetadataResolver extends AbstractRepositoryMetadataResolver {

private static final Log log = LogFactory.getLog(DefaultRepositoryMetadataResolver.class);
private final AssignableRepositoryMetadataResolver assignableRepositoryMetadataResolver = new AssignableRepositoryMetadataResolver();
private final AnnotationRepositoryMetadataResolver annotationRepositoryMetadataResolver = new AnnotationRepositoryMetadataResolver();

@Override
protected RepositoryMetadata resolveFromInterface(Class<?> repositoryInterface) {
if (repositoryInterface.isAnnotationPresent(RepositoryDefinition.class)) {
log.info("Since the repository interface was annotated with @RepositoryDefinition we will try to resolve the metadata using the provided annotation");
return annotationRepositoryMetadataResolver.resolve(repositoryInterface);
}
log.info("Since no annotation was found on the repository, we will try to read the metadata from the generic type parameters derived from the Repository interface");
return assignableRepositoryMetadataResolver.resolve(repositoryInterface);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.mmnaseri.utils.spring.data.query.QueryDescriptor;
import com.mmnaseri.utils.spring.data.store.DataStore;
import com.mmnaseri.utils.spring.data.store.DataStoreOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Serializable;
import java.util.List;
Expand All @@ -19,7 +21,8 @@
* @since 1.0 (9/29/15)
*/
public class DescribedDataStoreOperation<K extends Serializable, E> implements DataStoreOperation<Object, K, E> {


private static final Log log = LogFactory.getLog(DescribedDataStoreOperation.class);
private final SelectDataStoreOperation<K, E> selectOperation;
private final DataFunctionRegistry functionRegistry;

Expand All @@ -30,11 +33,14 @@ public DescribedDataStoreOperation(SelectDataStoreOperation<K, E> selectOperatio

@Override
public Object execute(DataStore<K, E> store, RepositoryConfiguration configuration, Invocation invocation) {
log.info("Trying to select the data from the data store");
final List<E> selection = selectOperation.execute(store, configuration, invocation);
final QueryDescriptor descriptor = selectOperation.getDescriptor();
if (descriptor.getFunction() == null) {
log.info("No function was specified for the current selection");
return selection;
}
log.info("Executing function " + descriptor.getFunction() + " on the selected items");
final DataFunction<?> function = functionRegistry.getFunction(descriptor.getFunction());
return function.apply(store, descriptor, configuration, selection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mmnaseri.utils.spring.data.domain.Invocation;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
* This is an immutable invocation.
Expand All @@ -29,4 +30,10 @@ public Method getMethod() {
public Object[] getArguments() {
return arguments;
}

@Override
public String toString() {
return method + ", " + Arrays.toString(arguments);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.mmnaseri.utils.spring.data.domain.impl;

import com.mmnaseri.utils.spring.data.domain.MatchedOperator;
import com.mmnaseri.utils.spring.data.domain.Matcher;
import com.mmnaseri.utils.spring.data.domain.Operator;

/**
* @author Mohammad Milad Naseri ([email protected])
* @since 1.0 (4/17/16, 12:37 PM)
*/
@SuppressWarnings("WeakerAccess")
public class ImmutableMatchedOperator implements MatchedOperator {

private final Operator original;
private final String matchedToken;

public ImmutableMatchedOperator(Operator original, String matchedToken) {
this.original = original;
this.matchedToken = matchedToken;
}

@Override
public String getName() {
return original.getName();
}

@Override
public int getOperands() {
return original.getOperands();
}

@Override
public Matcher getMatcher() {
return original.getMatcher();
}

@Override
public String[] getTokens() {
return original.getTokens();
}

@Override
public String getMatchedToken() {
return matchedToken;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.mmnaseri.utils.spring.data.proxy.RepositoryConfiguration;
import com.mmnaseri.utils.spring.data.store.DataStore;
import com.mmnaseri.utils.spring.data.store.DataStoreOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -19,6 +21,7 @@
*/
public class MethodInvocationDataStoreOperation<K extends Serializable, E> implements DataStoreOperation<Object, K, E> {

private static final Log log = LogFactory.getLog(MethodInvocationDataStoreOperation.class);
private final Object instance;
private final Method method;

Expand All @@ -31,6 +34,7 @@ public MethodInvocationDataStoreOperation(Object instance, Method method) {
public Object execute(DataStore<K, E> store, RepositoryConfiguration configuration, Invocation invocation) {
final Object result;
try {
log.info("Invoking method " + method + " to handle invocation " + invocation);
result = method.invoke(instance, invocation.getArguments());
} catch (IllegalAccessException e) {
throw new DataOperationExecutionException("Failed to access target method: " + method, e);
Expand Down
Loading

0 comments on commit 185af08

Please sign in to comment.