Skip to content

Commit

Permalink
Issue #122: Added warning logging in case of an incompatible Spring-D…
Browse files Browse the repository at this point in the history
…ata version is detected on the classpath
  • Loading branch information
derjust committed Jan 31, 2018
1 parent 1143090 commit 2ccb10b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Expand Up @@ -18,6 +18,6 @@
- Java Version:
- Platform Details:

All those information are logged by `org.socialsignin.spring.data.dynamodb.repository.cdi.DynamoDBRepositoryBean` on `INFO` level on startup.
All those information are logged by `org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory` on `INFO` level on startup.
Or use `java -version` and `mvn dependency:tree | grep -E 'spring|aws'` to provide those version numbers.

Expand Up @@ -15,6 +15,9 @@
*/
package org.socialsignin.spring.data.dynamodb.repository.support;

import com.amazonaws.util.VersionInfoUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
import org.socialsignin.spring.data.dynamodb.repository.DynamoDBCrudRepository;
import org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBQueryLookupStrategy;
Expand All @@ -25,16 +28,61 @@
import org.springframework.data.repository.query.EvaluationContextProvider;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.data.util.Version;

import java.io.Serializable;
import java.util.Optional;
import java.util.StringTokenizer;

import static org.springframework.data.querydsl.QuerydslUtils.QUERY_DSL_PRESENT;

/**
* @author Michael Lavelle
*/
public class DynamoDBRepositoryFactory extends RepositoryFactorySupport {
private static final Logger LOGGER = LoggerFactory.getLogger(DynamoDBRepositoryFactory.class);

static {
String awsSdkVersion = VersionInfoUtils.getVersion();
String springDataVersion = Version.class.getPackage().getImplementationVersion();

String thisSpecVersion = DynamoDBRepositoryFactory.class.getPackage().getSpecificationVersion();
String thisImplVersion = DynamoDBRepositoryFactory.class.getPackage().getImplementationVersion();

LOGGER.info("Spring Data DynamoDB Version: {} ({})", thisImplVersion, thisSpecVersion);
LOGGER.info("Spring Data Version: {}", springDataVersion);
LOGGER.info("AWS SDK Version: {}", awsSdkVersion);
LOGGER.info("Java Version: {} - {} {}", System.getProperty("java.version"),
System.getProperty("java.vm.name"), System.getProperty("java.vm.version"));
LOGGER.info("Platform Details: {} {}", System.getProperty("os.name"),
System.getProperty("os.version"));

if (!isCompatible(springDataVersion, thisSpecVersion)) {
LOGGER.warn("This Spring Data DynamoDB implementation might not be compatible with the available Spring Data classes on the classpath!"
+ System.getProperty("line.separator") + "NoDefClassFoundExceptions or similar might occur!");
}
}

protected static boolean isCompatible(String spec, String impl) {
if (spec == null && impl == null) {
return false;
} else if (spec == null) {
spec = "";
} else if (impl == null) {
impl = "";
}
StringTokenizer specTokenizer = new StringTokenizer(spec, ".");
StringTokenizer implTokenizer = new StringTokenizer(impl, ".");

String specMajor = specTokenizer.hasMoreTokens() ? specTokenizer.nextToken() : "0";
String specMinor = specTokenizer.hasMoreTokens() ? specTokenizer.nextToken() : "0";

String implMajor = implTokenizer.hasMoreTokens() ? implTokenizer.nextToken() : "0";
String implMinor = implTokenizer.hasMoreTokens() ? implTokenizer.nextToken() : "0";

return specMajor.equals(implMajor) && specMinor.equals(implMinor);
}


private final DynamoDBOperations dynamoDBOperations;

Expand Down

0 comments on commit 2ccb10b

Please sign in to comment.