Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix jpa reject expressions and discard attribute transformer

  • Loading branch information...
commit e72a26a593007833ed88353333bd48f1c3c477e3 1 parent 34d1e2e
@kabir kabir authored bstansberry committed
View
60 jpa/core/src/main/java/org/jboss/as/jpa/subsystem/JPAExtension.java
@@ -22,18 +22,21 @@
package org.jboss.as.jpa.subsystem;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
import static org.jboss.as.jpa.JpaLogger.JPA_LOGGER;
import java.util.Collections;
import java.util.List;
+
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.ModelVersion;
+import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SubsystemRegistration;
@@ -44,10 +47,16 @@
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
+import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.transform.AbstractOperationTransformer;
-import org.jboss.as.controller.transform.RejectExpressionValuesTransformer;
+import org.jboss.as.controller.transform.OperationTransformer;
+import org.jboss.as.controller.transform.RejectExpressionValuesChainedTransformer;
import org.jboss.as.controller.transform.TransformationContext;
import org.jboss.as.controller.transform.TransformersSubRegistration;
+import org.jboss.as.controller.transform.chained.ChainedOperationTransformer;
+import org.jboss.as.controller.transform.chained.ChainedResourceTransformationContext;
+import org.jboss.as.controller.transform.chained.ChainedResourceTransformer;
+import org.jboss.as.controller.transform.chained.ChainedResourceTransformerEntry;
import org.jboss.as.jpa.config.Configuration;
import org.jboss.as.jpa.persistenceprovider.PersistenceProviderLoader;
import org.jboss.as.jpa.processor.PersistenceProviderAdaptorLoader;
@@ -126,25 +135,46 @@ private void initializeTransformers_1_1_0(SubsystemRegistration subsystemRegistr
// We need to reject all expressions, since they can't be resolved on the client
// However, a slave running 1.1.0 has no way to tell us at registration that it has ignored a resource,
// so we can't agressively fail on resource transformation
- RejectExpressionValuesTransformer rejectNewerExpressions =
- new RejectExpressionValuesTransformer(
+ final RejectExpressionValuesChainedTransformer rejectNewerExpressions =
+ new RejectExpressionValuesChainedTransformer(
JPADefinition.DEFAULT_DATASOURCE,
JPADefinition.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE);
// Register the model transformers
- TransformersSubRegistration reg = subsystemRegistration.registerModelTransformers(ModelVersion.create(1, 1, 0), new JPASubsystemTransformer_1_1());
- //reg.registerOperationTransformer(ADD, rejectNewerExpressions);
- //todo add reject expression
- reg.registerOperationTransformer(ADD, new AbstractOperationTransformer() {
- @Override
- protected ModelNode transform(TransformationContext context, PathAddress address, ModelNode operation) {
- if (operation.has(JPADefinition.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE.getName())) {
- operation.remove(JPADefinition.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE.getName());
+ TransformersSubRegistration reg = subsystemRegistration.registerModelTransformers(
+ ModelVersion.create(1, 1, 0),
+ new ChainedResourceTransformer(
+ new ChainedResourceTransformerEntry() {
+ @Override
+ public void transformResource(ChainedResourceTransformationContext context, PathAddress address, Resource resource)
+ throws OperationFailedException {
+ resource.getModel().remove(JPADefinition.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE.getName());
+ }
+ },
+ rejectNewerExpressions));
+
+ reg.registerOperationTransformer(ADD, new ChainedOperationTransformer(
+ new AbstractOperationTransformer() {
+ @Override
+ protected ModelNode transform(TransformationContext context, PathAddress address, ModelNode operation) {
+ if (operation.has(JPADefinition.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE.getName())) {
+ operation.remove(JPADefinition.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE.getName());
+ }
+ return operation;
+ }
+ },
+ rejectNewerExpressions));
+
+ reg.registerOperationTransformer(WRITE_ATTRIBUTE_OPERATION, new ChainedOperationTransformer(new OperationTransformer() {
+ @Override
+ public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation)
+ throws OperationFailedException {
+ if (operation.get(NAME).equals(JPADefinition.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE.getName())) {
+ return OperationTransformer.DEFAULT.transformOperation(context, address, operation);
+ }
+ return rejectNewerExpressions.getWriteAttributeTransformer().transformOperation(context, address, operation);
}
- return operation;
- }
- });
- reg.registerOperationTransformer(WRITE_ATTRIBUTE_OPERATION, rejectNewerExpressions.getWriteAttributeTransformer());
+ }));
}
View
51 jpa/core/src/main/java/org/jboss/as/jpa/subsystem/JPASubsystemTransformer_1_1.java
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2012, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.as.jpa.subsystem;
-
-import org.jboss.as.controller.transform.AbstractSubsystemTransformer;
-import org.jboss.as.controller.transform.TransformationContext;
-import org.jboss.dmr.ModelNode;
-
-/**
- * @author <a href="mailto:tomaz.cerar@redhat.com">Tomaz Cerar</a>
- */
-public class JPASubsystemTransformer_1_1 extends AbstractSubsystemTransformer {
-
- public JPASubsystemTransformer_1_1() {
- super(CommonAttributes.JPA);
- }
-
- @Override
- public ModelNode transformModel(TransformationContext context, ModelNode model) {
- remove(model, CommonAttributes.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE);
- return model;
- }
-
- private void remove(ModelNode model, String name) {
- if (model.has(name)) {
- model.remove(name);
- }
-
- }
-
-}
View
19 jpa/core/src/test/java/org/jboss/as/jpa/subsystem/JPA10SubsystemTestCase.java
@@ -21,28 +21,9 @@
*/
package org.jboss.as.jpa.subsystem;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILED;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
-
import java.io.IOException;
-import junit.framework.Assert;
-import org.jboss.as.controller.ModelVersion;
-import org.jboss.as.controller.OperationFailedException;
-import org.jboss.as.controller.transform.OperationTransformer;
import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
-import org.jboss.as.subsystem.test.KernelServices;
-import org.jboss.as.subsystem.test.KernelServicesBuilder;
-import org.jboss.dmr.ModelNode;
-import org.junit.Ignore;
-import org.junit.Test;
/**
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
View
99 jpa/core/src/test/java/org/jboss/as/jpa/subsystem/JPA11SubsystemTestCase.java
@@ -21,21 +21,20 @@
*/
package org.jboss.as.jpa.subsystem;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILED;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
+import static org.jboss.as.jpa.subsystem.JPADefinition.DEFAULT_DATASOURCE;
+import static org.jboss.as.jpa.subsystem.JPADefinition.DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE;
import java.io.IOException;
+import java.util.List;
import junit.framework.Assert;
+
import org.jboss.as.controller.ModelVersion;
-import org.jboss.as.controller.transform.OperationTransformer;
+import org.jboss.as.controller.PathAddress;
+import org.jboss.as.controller.PathElement;
+import org.jboss.as.model.test.FailedOperationTransformationConfig;
+import org.jboss.as.model.test.ModelTestUtils;
import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.as.subsystem.test.KernelServicesBuilder;
@@ -57,42 +56,54 @@ protected String getSubsystemXml() throws IOException {
return readResource("subsystem-1.1.xml");
}
+
@Test
public void testTransformers_1_1_0() throws Exception {
- System.setProperty("org.jboss.as.jpa.testBadExpr", "hello");
-
- try {
- ModelVersion oldVersion = ModelVersion.create(1, 1, 0);
- KernelServicesBuilder builder = createKernelServicesBuilder(null)
- .setSubsystemXml(getSubsystemXml());
- builder.createLegacyKernelServicesBuilder(null, oldVersion)
- .setExtensionClassName(JPAExtension.class.getName())
- .addMavenResourceURL("org.jboss.as:jboss-as-jpa:7.1.2.Final")
- .addMavenResourceURL("org.jboss.as:jboss-as-controller:7.1.2.Final")
- .addParentFirstClassPattern("org.jboss.as.controller.*");
- KernelServices mainServices = builder.build();
- KernelServices legacyServices = mainServices.getLegacyServices(oldVersion);
- Assert.assertNotNull(legacyServices);
-
- checkSubsystemModelTransformation(mainServices, oldVersion);
-
- final ModelNode operation = new ModelNode();
- operation.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
- operation.get(OP_ADDR).add(SUBSYSTEM, JPAExtension.SUBSYSTEM_NAME);
- operation.get(NAME).set(JPADefinition.DEFAULT_DATASOURCE.getName());
- operation.get(VALUE).set("${org.jboss.as.jpa.testBadExpr}");
-
- final ModelNode mainResult = mainServices.executeOperation(operation);
- System.out.println(mainResult);
- Assert.assertTrue(SUCCESS.equals(mainResult.get(OUTCOME).asString()));
-
- final OperationTransformer.TransformedOperation op = mainServices.transformOperation(oldVersion, operation);
- final ModelNode result = mainServices.executeOperation(oldVersion, op);
- Assert.assertEquals(FAILED, result.get(OUTCOME).asString());
- } catch (Throwable t) {
- Assert.fail(t.getMessage());
- } finally {
- System.clearProperty("org.jboss.as.jpa.testBadExpr");
- }
+ ModelVersion oldVersion = ModelVersion.create(1, 1, 0);
+ KernelServicesBuilder builder = createKernelServicesBuilder(null)
+ .setSubsystemXmlResource("subsystem-1.1-no-expressions.xml");
+
+ builder.createLegacyKernelServicesBuilder(null, oldVersion)
+ .setExtensionClassName(JPAExtension.class.getName())
+ .addMavenResourceURL("org.jboss.as:jboss-as-jpa:7.1.2.Final")
+ .addMavenResourceURL("org.jboss.as:jboss-as-controller:7.1.2.Final")
+ .addParentFirstClassPattern("org.jboss.as.controller.*");
+
+ KernelServices mainServices = builder.build();
+ KernelServices legacyServices = mainServices.getLegacyServices(oldVersion);
+ Assert.assertNotNull(legacyServices);
+ Assert.assertTrue(mainServices.isSuccessfulBoot());
+ Assert.assertTrue(legacyServices.isSuccessfulBoot());
+
+ checkSubsystemModelTransformation(mainServices, oldVersion);
+ }
+
+ @Test
+ public void testTransformers_1_1_0_RejectExpressions() throws Exception {
+ ModelVersion oldVersion = ModelVersion.create(1, 1, 0);
+ KernelServicesBuilder builder = createKernelServicesBuilder(null);
+
+ builder.createLegacyKernelServicesBuilder(null, oldVersion)
+ .setExtensionClassName(JPAExtension.class.getName())
+ .addMavenResourceURL("org.jboss.as:jboss-as-jpa:7.1.2.Final")
+ .addMavenResourceURL("org.jboss.as:jboss-as-controller:7.1.2.Final")
+ .addParentFirstClassPattern("org.jboss.as.controller.*");
+
+ KernelServices mainServices = builder.build();
+ KernelServices legacyServices = mainServices.getLegacyServices(oldVersion);
+ Assert.assertNotNull(legacyServices);
+ Assert.assertTrue(mainServices.isSuccessfulBoot());
+ Assert.assertTrue(legacyServices.isSuccessfulBoot());
+
+ List<ModelNode> ops = builder.parseXml(getSubsystemXml());
+ ModelTestUtils.checkFailedTransformedBootOperations(mainServices, oldVersion, ops,
+ new FailedOperationTransformationConfig()
+ .addFailedAttribute(PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, JPAExtension.SUBSYSTEM_NAME)),
+ new FailedOperationTransformationConfig.RejectExpressionsConfig(DEFAULT_DATASOURCE, DEFAULT_EXTENDEDPERSISTENCE_INHERITANCE)));
+
+ ModelNode legacyModel = legacyServices.readWholeModel().require(SUBSYSTEM).require(JPAExtension.SUBSYSTEM_NAME);
+ Assert.assertEquals(1, legacyModel.keys().size());
+ Assert.assertEquals("test-ds", legacyModel.get(DEFAULT_DATASOURCE.getName()).asString());
+
}
}
View
3  jpa/core/src/test/resources/org/jboss/as/jpa/subsystem/subsystem-1.1-no-expressions.xml
@@ -0,0 +1,3 @@
+<subsystem xmlns="urn:jboss:domain:jpa:1.1">
+ <jpa default-datasource="test-ds" default-extended-persistence-inheritance="DEEP" />
+</subsystem>
View
2  jpa/core/src/test/resources/org/jboss/as/jpa/subsystem/subsystem-1.1.xml
@@ -1,3 +1,3 @@
<subsystem xmlns="urn:jboss:domain:jpa:1.1">
- <jpa default-datasource="" default-extended-persistence-inheritance="DEEP" />
+ <jpa default-datasource="${test:test-ds}" default-extended-persistence-inheritance="${test:DEEP}" />
</subsystem>
Please sign in to comment.
Something went wrong with that request. Please try again.