Skip to content

Commit

Permalink
Support for Cayenne 5.0-M1 #114
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Sep 27, 2024
1 parent 2e7f28d commit 824933b
Show file tree
Hide file tree
Showing 110 changed files with 7,172 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* #112 Ensure Bootique-provided version of JCache is used
* #113 Upgrade Cayenne to 4.2.1
* #114 Support for Cayenne 5.0-M1

## 3.0-M3

Expand Down
134 changes: 134 additions & 0 deletions bootique-cayenne50-jcache/pom.xml
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>
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 {
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.bootique.cayenne.v50.jcache.CayenneJCacheModule
Loading

0 comments on commit 824933b

Please sign in to comment.