You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ra...@apache.org on 2014/12/08 22:11:43 UTC
deltaspike git commit: DELTASPIKE-588 - Repositories from Data module
should be deactivatable
Repository: deltaspike
Updated Branches:
refs/heads/master 3d66b6dd7 -> 7daf0a99e
DELTASPIKE-588 - Repositories from Data module should be deactivatable
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/7daf0a99
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/7daf0a99
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/7daf0a99
Branch: refs/heads/master
Commit: 7daf0a99e9fd72b11842c342f8daf37ab7ab1018
Parents: 3d66b6d
Author: Rafael Benevides <ra...@gmail.com>
Authored: Mon Dec 8 18:59:52 2014 -0200
Committer: Rafael Benevides <ra...@gmail.com>
Committed: Mon Dec 8 19:10:52 2014 -0200
----------------------------------------------------------------------
.../deltaspike/data/api/EntityRepository.java | 4 +-
.../data/impl/RepositoryExtension.java | 7 ++
.../data/impl/DisabledRepositoryTest.java | 91 ++++++++++++++++++++
.../data/impl/RepositoryDeactivator.java | 40 +++++++++
.../data/test/service/DisabledRepository.java | 29 +++++++
.../META-INF/apache-deltaspike.properties | 17 ++++
documentation/src/main/asciidoc/data.adoc | 20 +++++
7 files changed, 207 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7daf0a99/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/EntityRepository.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/EntityRepository.java b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/EntityRepository.java
index b31b96e..f879c38 100755
--- a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/EntityRepository.java
+++ b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/EntityRepository.java
@@ -23,13 +23,15 @@ import java.util.List;
import javax.persistence.metamodel.SingularAttribute;
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+
/**
* Base Repository interface. All methods are implemented by the CDI extension.
*
* @param <E> Entity type.
* @param <PK> Primary key type.
*/
-public interface EntityRepository<E, PK extends Serializable>
+public interface EntityRepository<E, PK extends Serializable> extends Deactivatable
{
/**
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7daf0a99/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
index a965e5a..6e2e447 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
@@ -74,6 +74,7 @@ public class RepositoryExtension implements Extension, Deactivatable
PersistenceUnits.instance().init();
}
+ @SuppressWarnings("unchecked")
<X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event)
{
if (!isActivated)
@@ -93,6 +94,12 @@ public class RepositoryExtension implements Extension, Deactivatable
{
log.log(Level.FINER, "getHandlerClass: Repository annotation detected on {0}",
event.getAnnotatedType());
+ if (Deactivatable.class.isAssignableFrom(repoClass)
+ && !ClassDeactivationUtils.isActivated((Class<? extends Deactivatable>) repoClass))
+ {
+ log.log(Level.FINER, "Class {0} is Deactivated", repoClass);
+ return;
+ }
RepositoryComponentsFactory.instance().add(repoClass);
}
catch (RepositoryDefinitionException e)
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7daf0a99/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/DisabledRepositoryTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/DisabledRepositoryTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/DisabledRepositoryTest.java
new file mode 100644
index 0000000..4c6ea14
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/DisabledRepositoryTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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 org.apache.deltaspike.data.impl;
+
+import static org.apache.deltaspike.data.test.util.TestDeployments.initDeployment;
+
+import javax.inject.Inject;
+
+import org.apache.deltaspike.data.test.service.DisabledRepository;
+import org.apache.deltaspike.data.test.service.SimpleRepository;
+import org.apache.deltaspike.test.category.WebProfileCategory;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+@RunWith(Arquillian.class)
+@Category(WebProfileCategory.class)
+public class DisabledRepositoryTest
+{
+
+ @Deployment
+ public static Archive<?> deployment()
+ {
+ WebArchive archive = initDeployment()
+ .addClasses(SimpleRepository.class,
+ RepositoryDeactivator.class,
+ DisabledRepository.class
+ )
+ .addAsWebInfResource("disabled/META-INF/apache-deltaspike.properties",
+ "classes/META-INF/apache-deltaspike.properties");
+ return archive;
+ }
+
+ @Inject
+ private SimpleRepository simpleRepository;
+
+ @Inject
+ private DisabledRepository disabledRepository;
+
+ @Test
+ public void disabledSimpleRepository()
+ {
+ try
+ {
+ simpleRepository.findAll();
+ Assert.fail("Should have been failed because SimpleRepository was disabled");
+ }
+ catch (RuntimeException e)
+ {
+ Assert.assertNotNull(e);
+ }
+
+ }
+
+ @Test
+ public void disabledRepository()
+ {
+ try
+ {
+ disabledRepository.findAll();
+ Assert.fail("Should have been failed because DisabledRepository was disabled");
+ }
+ catch (RuntimeException e)
+ {
+ Assert.assertNotNull(e);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7daf0a99/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/RepositoryDeactivator.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/RepositoryDeactivator.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/RepositoryDeactivator.java
new file mode 100644
index 0000000..f911af8
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/RepositoryDeactivator.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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 org.apache.deltaspike.data.impl;
+
+import org.apache.deltaspike.core.spi.activation.ClassDeactivator;
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.data.test.service.DisabledRepository;
+import org.apache.deltaspike.data.test.service.SimpleRepository;
+
+public class RepositoryDeactivator implements ClassDeactivator
+{
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Boolean isActivated(Class<? extends Deactivatable> targetClass)
+ {
+ if (targetClass.equals(SimpleRepository.class) || targetClass.equals(DisabledRepository.class))
+ {
+ return Boolean.FALSE;
+ }
+ return null; // no result for the given class
+ }
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7daf0a99/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/DisabledRepository.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/DisabledRepository.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/DisabledRepository.java
new file mode 100644
index 0000000..85c0802
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/DisabledRepository.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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 org.apache.deltaspike.data.test.service;
+
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.data.api.EntityRepository;
+import org.apache.deltaspike.data.api.Repository;
+import org.apache.deltaspike.data.test.domain.Simple;
+
+@Repository(forEntity = Simple.class)
+public interface DisabledRepository extends EntityRepository<Simple, Long>, Deactivatable
+{
+}
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7daf0a99/deltaspike/modules/data/impl/src/test/resources/disabled/META-INF/apache-deltaspike.properties
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/resources/disabled/META-INF/apache-deltaspike.properties b/deltaspike/modules/data/impl/src/test/resources/disabled/META-INF/apache-deltaspike.properties
new file mode 100644
index 0000000..9d9dc1e
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/resources/disabled/META-INF/apache-deltaspike.properties
@@ -0,0 +1,17 @@
+#
+# JBoss, Home of Professional Open Source
+# Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
+# contributors by the @authors tag. See the copyright.txt in the
+# distribution for a full listing of individual contributors.
+#
+# 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.
+#
+org.apache.deltaspike.core.spi.activation.ClassDeactivator=org.apache.deltaspike.data.impl.RepositoryDeactivator
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/7daf0a99/documentation/src/main/asciidoc/data.adoc
----------------------------------------------------------------------
diff --git a/documentation/src/main/asciidoc/data.adoc b/documentation/src/main/asciidoc/data.adoc
index 022322c..8be71d7 100644
--- a/documentation/src/main/asciidoc/data.adoc
+++ b/documentation/src/main/asciidoc/data.adoc
@@ -287,6 +287,26 @@ public abstract class PersonRepository extends AbstractEntityRepository<Person,
}
-------------------------------------------------------------------------------------
+==== Deactivating Repositories
+
+Repositories can be deactivated creating a <<spi.adoc#_classdeactivator,ClassDeactivator>>.
+
+The `EntityRepository` interface implements the <<core.adoc#_deactivatable,Deactivatable>> interface allowing it to be used in the ClassDeactivator.
+
+If your repository don't implement `EntityRepository` and you want to deactivate it, you will need to implement the <<core.adoc#_deactivatable,Deactivatable>> interface yourself.
+
+[source,java]
+----------------------------------------
+@Repository(forEntity = Person.class)
+public abstract class PersonRepository implements Deactivatable {
+ ...
+}
+
+@Repository(forEntity = Person.class)
+public interface PersonRepository implements Deactivatable{
+ ...
+}
+----------------------------------------
=== Using Multiple `EntityManager`