-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
110 changed files
with
7,172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to ObjectStyle LLC under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ObjectStyle LLC licenses | ||
this file to you 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. | ||
--> | ||
|
||
<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/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.bootique.cayenne</groupId> | ||
<artifactId>bootique-cayenne-parent</artifactId> | ||
<version>3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>bootique-cayenne50-jcache</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>bootique-cayenne50-jcache: Integrates bootique-cayenne with bootique-jcache</name> | ||
<description>Integrates bootique-cayenne with bootique-jcache.</description> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.bootique.cayenne</groupId> | ||
<artifactId>bootique-cayenne50</artifactId> | ||
<version>${bootique.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cayenne</groupId> | ||
<artifactId>cayenne-jcache</artifactId> | ||
<version>${cayenne50.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cayenne</groupId> | ||
<artifactId>cayenne-cache-invalidation</artifactId> | ||
<version>${cayenne50.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!-- Compile dependencies --> | ||
<dependency> | ||
<groupId>io.bootique.cayenne</groupId> | ||
<artifactId>bootique-cayenne50</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cayenne</groupId> | ||
<artifactId>cayenne-jcache</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.cache</groupId> | ||
<artifactId>cache-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.bootique.jcache</groupId> | ||
<artifactId>bootique-jcache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cayenne</groupId> | ||
<artifactId>cayenne-cache-invalidation</artifactId> | ||
</dependency> | ||
|
||
<!-- Unit test dependencies --> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.ehcache</groupId> | ||
<artifactId>ehcache</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.bootique.cayenne</groupId> | ||
<artifactId>bootique-cayenne50-junit5</artifactId> | ||
<scope>test</scope> | ||
<version>${bootique.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.bootique.jdbc</groupId> | ||
<artifactId>bootique-jdbc-junit5-derby</artifactId> | ||
<scope>test</scope> | ||
<version>${bootique.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<!-- Optional profile used to sign artifacts --> | ||
<profiles> | ||
<profile> | ||
<id>gpg</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
96 changes: 96 additions & 0 deletions
96
...ue-cayenne50-jcache/src/main/java/io/bootique/cayenne/v50/jcache/CayenneJCacheModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Licensed to ObjectStyle LLC under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ObjectStyle LLC licenses | ||
* this file to you 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 io.bootique.cayenne.v50.jcache; | ||
|
||
import io.bootique.BQModule; | ||
import io.bootique.ModuleCrate; | ||
import io.bootique.cayenne.v50.CayenneModule; | ||
import io.bootique.di.Binder; | ||
import io.bootique.di.Key; | ||
import io.bootique.di.Provides; | ||
import org.apache.cayenne.cache.invalidation.CacheInvalidationModule; | ||
import org.apache.cayenne.cache.invalidation.CacheInvalidationModuleExtender; | ||
import org.apache.cayenne.cache.invalidation.InvalidationHandler; | ||
|
||
import javax.cache.CacheManager; | ||
import javax.inject.Qualifier; | ||
import javax.inject.Singleton; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.Set; | ||
|
||
/** | ||
* Bootique DI module integrating bootique-jcache to Cayenne. | ||
*/ | ||
public class CayenneJCacheModule implements BQModule { | ||
|
||
/** | ||
* @param binder DI binder passed to the Module that invokes this method. | ||
* @return an instance of {@link CayenneJCacheModuleExtender} that can be used to load Cayenne cache | ||
* custom extensions. | ||
*/ | ||
public static CayenneJCacheModuleExtender extend(Binder binder) { | ||
return new CayenneJCacheModuleExtender(binder); | ||
} | ||
|
||
@Override | ||
public ModuleCrate crate() { | ||
return ModuleCrate.of(this) | ||
.description("Integrates Apache Cayenne 4.2 JCache extensions") | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void configure(Binder binder) { | ||
extend(binder).initAllExtensions(); | ||
|
||
CayenneModule.extend(binder).addModule(Key.get(org.apache.cayenne.di.Module.class, DefinedInCayenneJCache.class)); | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
@DefinedInCayenneJCache | ||
org.apache.cayenne.di.Module provideDiJCacheModule(CacheManager cacheManager, Set<InvalidationHandler> invalidationHandlers) { | ||
// return module composition | ||
return b -> { | ||
createInvalidationModule(invalidationHandlers).configure(b); | ||
createOverridesModule(cacheManager).configure(b); | ||
}; | ||
} | ||
|
||
protected org.apache.cayenne.di.Module createInvalidationModule(Set<InvalidationHandler> invalidationHandlers) { | ||
return b -> { | ||
CacheInvalidationModuleExtender extender = CacheInvalidationModule.extend(b); | ||
invalidationHandlers.forEach(extender::addHandler); | ||
}; | ||
} | ||
|
||
protected org.apache.cayenne.di.Module createOverridesModule(CacheManager cacheManager) { | ||
return b -> b.bind(CacheManager.class).toInstance(cacheManager); | ||
} | ||
|
||
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Qualifier | ||
@interface DefinedInCayenneJCache { | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ne50-jcache/src/main/java/io/bootique/cayenne/v50/jcache/CayenneJCacheModuleExtender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to ObjectStyle LLC under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ObjectStyle LLC licenses | ||
* this file to you 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 io.bootique.cayenne.v50.jcache; | ||
|
||
import io.bootique.ModuleExtender; | ||
import io.bootique.di.Binder; | ||
import io.bootique.di.SetBuilder; | ||
import io.bootique.jcache.JCacheModule; | ||
import org.apache.cayenne.cache.invalidation.InvalidationHandler; | ||
import org.apache.cayenne.jcache.JCacheConstants; | ||
|
||
import javax.cache.configuration.Configuration; | ||
|
||
public class CayenneJCacheModuleExtender extends ModuleExtender<CayenneJCacheModuleExtender> { | ||
|
||
public CayenneJCacheModuleExtender(Binder binder) { | ||
super(binder); | ||
} | ||
|
||
@Override | ||
public CayenneJCacheModuleExtender initAllExtensions() { | ||
contributeInvalidationHandler(); | ||
return this; | ||
} | ||
|
||
public CayenneJCacheModuleExtender addInvalidationHandler(InvalidationHandler handler) { | ||
contributeInvalidationHandler().addInstance(handler); | ||
return this; | ||
} | ||
|
||
public CayenneJCacheModuleExtender addInvalidationHandler(Class<? extends InvalidationHandler> handlerType) { | ||
contributeInvalidationHandler().add(handlerType); | ||
return this; | ||
} | ||
|
||
// TODO: we actually know key and value types for Cayenne QueryCache config | ||
public CayenneJCacheModuleExtender setDefaultCacheConfiguration(Configuration<?, ?> config) { | ||
JCacheModule.extend(binder).setConfiguration(JCacheConstants.DEFAULT_CACHE_NAME, config); | ||
return this; | ||
} | ||
|
||
protected SetBuilder<InvalidationHandler> contributeInvalidationHandler() { | ||
return newSet(InvalidationHandler.class); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
bootique-cayenne50-jcache/src/main/resources/META-INF/services/io.bootique.BQModule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.bootique.cayenne.v50.jcache.CayenneJCacheModule |
Oops, something went wrong.