repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ds/DsXmlParser.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ds; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.metadata.api.ds.DsSecurity; import org.jboss.as.connector.metadata.common.CredentialImpl; import org.jboss.as.connector.metadata.ds.DsSecurityImpl; import org.jboss.jca.common.api.metadata.common.Extension; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.common.metadata.ParserException; import org.jboss.jca.common.metadata.ds.DsParser; import org.jboss.metadata.property.PropertyReplacer; /** * Parser for -ds.xml * */ public class DsXmlParser extends DsParser { private final PropertyReplacer propertyReplacer; public DsXmlParser(PropertyReplacer propertyReplacer) { this.propertyReplacer = propertyReplacer; } /** * Parse security * * @param reader The reader * @return The result * @throws XMLStreamException * XMLStreamException * @throws ParserException * ParserException * @throws ValidateException * ValidateException */ @Override protected DsSecurity parseDsSecurity(XMLStreamReader reader) throws XMLStreamException, ParserException, ValidateException { String userName = null; String password = null; String authenticationContext = null; Extension reauthPlugin = null; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY) { return new DsSecurityImpl(userName, password,authenticationContext, null, reauthPlugin); } else { if (DsSecurity.Tag.forName(reader.getLocalName()) == DsSecurity.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { DsSecurity.Tag tag = DsSecurity.Tag.forName(reader.getLocalName()); switch (tag) { case PASSWORD: { password = elementAsString(reader); boolean resolved = false; if (propertyReplacer != null && password != null && password.trim().length() != 0) { String resolvedPassword = propertyReplacer.replaceProperties(password); if (resolvedPassword != null) { password = resolvedPassword; resolved = true; } } break; } case USER_NAME: { userName = elementAsString(reader); break; } case SECURITY_DOMAIN: { throw new ParserException(ConnectorLogger.DS_DEPLOYER_LOGGER.legacySecurityNotSupported()); } case ELYTRON_ENABLED: { elementAsBoolean(reader); break; } case AUTHENTICATION_CONTEXT: { authenticationContext = elementAsString(reader); break; } case REAUTH_PLUGIN: { reauthPlugin = parseExtension(reader, tag.getLocalName()); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } /** * parse credential tag * * @param reader reader * @return the parse Object * @throws XMLStreamException in case of error * @throws ParserException in case of error * @throws ValidateException in case of error */ @Override protected Credential parseCredential(XMLStreamReader reader) throws XMLStreamException, ParserException, ValidateException { String userName = null; String password = null; String authenticationContext = null; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY || Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.RECOVER_CREDENTIAL) { return new CredentialImpl(userName, password, authenticationContext, null); } else { if (Credential.Tag.forName(reader.getLocalName()) == Credential.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (Credential.Tag.forName(reader.getLocalName())) { case PASSWORD: { password = elementAsString(reader); if (propertyReplacer != null && password != null) { String resolvedPassword = propertyReplacer.replaceProperties(password); if (resolvedPassword != null) password = resolvedPassword; } break; } case USER_NAME: { userName = elementAsString(reader); break; } case SECURITY_DOMAIN: { throw new ParserException(ConnectorLogger.SUBSYSTEM_RA_LOGGER.legacySecurityNotAvailable()); } case ELYTRON_ENABLED: { elementAsBoolean(reader); break; } case AUTHENTICATION_CONTEXT: { authenticationContext = elementAsString(reader); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } }
8,495
40.647059
120
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ds/DsDeploymentActivator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ds; import org.jboss.as.connector.deployers.datasource.DataSourceDefinitionAnnotationProcessor; import org.jboss.as.connector.deployers.datasource.DataSourceDefinitionDescriptorProcessor; import org.jboss.as.connector.deployers.ds.processors.DsXmlDeploymentInstallProcessor; import org.jboss.as.connector.deployers.ds.processors.DsXmlDeploymentParsingProcessor; import org.jboss.as.connector.deployers.ds.processors.JdbcDriverDeploymentProcessor; import org.jboss.as.connector.subsystems.datasources.DataSourcesExtension; import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.as.server.deployment.Phase; /** * Service activator which installs the various service required for datasource * deployments. * * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ public class DsDeploymentActivator { public void activateProcessors(final DeploymentProcessorTarget updateContext) { updateContext.addDeploymentProcessor(DataSourcesExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_DSXML_DEPLOYMENT, new DsXmlDeploymentParsingProcessor()); updateContext.addDeploymentProcessor(DataSourcesExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_RESOURCE_DEF_ANNOTATION_DATA_SOURCE, new DataSourceDefinitionAnnotationProcessor()); updateContext.addDeploymentProcessor(DataSourcesExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_JDBC_DRIVER, new JdbcDriverDeploymentProcessor()); updateContext.addDeploymentProcessor(DataSourcesExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_RESOURCE_DEF_XML_DATA_SOURCE, new DataSourceDefinitionDescriptorProcessor()); updateContext.addDeploymentProcessor(DataSourcesExtension.SUBSYSTEM_NAME, Phase.FIRST_MODULE_USE, Phase.FIRST_MODULE_USE_DSXML_DEPLOYMENT, new DsXmlDeploymentInstallProcessor()); } }
2,913
56.137255
196
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ds/processors/DsXmlDeploymentParsingProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ds.processors; import java.io.FileInputStream; import java.io.InputStream; import java.util.Collections; import java.util.HashSet; import java.util.Locale; import java.util.Set; import org.jboss.as.connector.deployers.Util; import org.jboss.as.connector.deployers.ds.DsXmlParser; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.as.server.deployment.AttachmentList; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.DataSources; import org.jboss.metadata.property.PropertyReplacer; import org.jboss.vfs.VFSUtils; import org.jboss.vfs.VirtualFile; /** * Picks up -ds.xml deployments * * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ public class DsXmlDeploymentParsingProcessor implements DeploymentUnitProcessor { static final AttachmentKey<AttachmentList<DataSources>> DATA_SOURCES_ATTACHMENT_KEY = AttachmentKey.createList(DataSources.class); private static final String[] LOCATIONS = {"WEB-INF", "META-INF"}; /** * Construct a new instance. */ public DsXmlDeploymentParsingProcessor() { } /** * Process a deployment for standard ra deployment files. Will parse the xml * file and attach a configuration discovered during processing. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException * */ @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); boolean resolveProperties = Util.shouldResolveJBoss(deploymentUnit); final PropertyReplacer propertyReplacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER); final Set<VirtualFile> files = dataSources(deploymentUnit); boolean loggedDeprication = false; for (VirtualFile f : files) { InputStream xmlStream = null; try { xmlStream = new FileInputStream(f.getPhysicalFile()); DsXmlParser parser = new DsXmlParser(propertyReplacer); parser.setSystemPropertiesResolved(resolveProperties); DataSources dataSources = parser.parse(xmlStream); if (dataSources != null) { if (!loggedDeprication) { loggedDeprication = true; ConnectorLogger.ROOT_LOGGER.deprecated(); } for (DataSource ds : dataSources.getDataSource()) { if (ds.getDriver() == null) { throw ConnectorLogger.ROOT_LOGGER.FailedDeployDriverNotSpecified(ds.getJndiName()); } } deploymentUnit.addToAttachmentList(DATA_SOURCES_ATTACHMENT_KEY, dataSources); } } catch (Exception e) { throw new DeploymentUnitProcessingException(e.getMessage(), e); } finally { VFSUtils.safeClose(xmlStream); } } } private Set<VirtualFile> dataSources(final DeploymentUnit deploymentUnit) { final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot(); if (deploymentRoot == null || !deploymentRoot.exists()) { return Collections.emptySet(); } final String deploymentRootName = deploymentRoot.getName().toLowerCase(Locale.ENGLISH); if (deploymentRootName.endsWith("-ds.xml")) { return Collections.singleton(deploymentRoot); } final Set<VirtualFile> ret = new HashSet<VirtualFile>(); for (String location : LOCATIONS) { final VirtualFile loc = deploymentRoot.getChild(location); if (loc.exists()) { for (final VirtualFile file : loc.getChildren()) { if (file.getName().endsWith("-ds.xml")) { ret.add(file); } } } } return ret; } }
5,606
40.533333
150
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ds/processors/DsXmlDeploymentInstallProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ds.processors; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER; import static org.jboss.as.connector.subsystems.jca.Constants.DEFAULT_NAME; import java.sql.Driver; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.api.ds.DsSecurity; import org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService; import org.jboss.as.connector.subsystems.datasources.CommonDeploymentService; import org.jboss.as.connector.subsystems.datasources.Constants; import org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService; import org.jboss.as.connector.subsystems.datasources.DataSourcesExtension; import org.jboss.as.connector.subsystems.datasources.DataSourcesSubsystemProviders; import org.jboss.as.connector.subsystems.datasources.LocalDataSourceService; import org.jboss.as.connector.subsystems.datasources.ModifiableDataSource; import org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource; import org.jboss.as.connector.subsystems.common.jndi.Util; import org.jboss.as.connector.subsystems.datasources.XMLDataSourceRuntimeHandler; import org.jboss.as.connector.subsystems.datasources.XMLXaDataSourceRuntimeHandler; import org.jboss.as.connector.subsystems.datasources.XaDataSourceService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.as.naming.ManagedReferenceFactory; import org.jboss.as.naming.ServiceBasedNamingStore; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.service.BinderService; import org.jboss.as.naming.service.NamingService; import org.jboss.as.server.Services; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentModelUtils; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentResourceSupport; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.jca.common.api.metadata.Defaults; import org.jboss.jca.common.api.metadata.common.Credential; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.DataSources; import org.jboss.jca.common.api.metadata.ds.DsXaPool; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import org.jboss.jca.common.metadata.ds.DsXaPoolImpl; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.jca.deployers.common.CommonDeployment; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * Picks up -ds.xml deployments * * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ public class DsXmlDeploymentInstallProcessor implements DeploymentUnitProcessor { private static final String DATA_SOURCE = "data-source"; private static final String XA_DATA_SOURCE = "xa-data-source"; private static final String CONNECTION_PROPERTIES = "connection-properties"; private static final String XA_CONNECTION_PROPERTIES = "xa-datasource-properties"; private static final PathAddress SUBSYSTEM_ADDRESS = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, DataSourcesExtension.SUBSYSTEM_NAME)); private static final PathAddress DATASOURCE_ADDRESS; private static final PathAddress XA_DATASOURCE_ADDRESS; static { XA_DATASOURCE_ADDRESS = SUBSYSTEM_ADDRESS.append(PathElement.pathElement(XA_DATA_SOURCE)); DATASOURCE_ADDRESS = SUBSYSTEM_ADDRESS.append(PathElement.pathElement(DATA_SOURCE)); } /** * Process a deployment for standard ra deployment files. Will parse the xml * file and attach a configuration discovered during processing. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException * */ @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); final List<DataSources> dataSourcesList = deploymentUnit.getAttachmentList(DsXmlDeploymentParsingProcessor.DATA_SOURCES_ATTACHMENT_KEY); for(DataSources dataSources : dataSourcesList) { if (dataSources.getDrivers() != null && !dataSources.getDrivers().isEmpty()) { ConnectorLogger.DS_DEPLOYER_LOGGER.driversElementNotSupported(deploymentUnit.getName()); } ServiceTarget serviceTarget = phaseContext.getServiceTarget(); if (dataSources.getDataSource() != null && !dataSources.getDataSource().isEmpty()) { for (int i = 0; i < dataSources.getDataSource().size(); i++) { DataSource ds = (DataSource)dataSources.getDataSource().get(i); if (ds.isEnabled() && ds.getDriver() != null) { try { final String jndiName = Util.cleanJndiName(ds.getJndiName(), ds.isUseJavaContext()); LocalDataSourceService lds = new LocalDataSourceService(jndiName, ContextNames.bindInfoFor(jndiName)); lds.getDataSourceConfigInjector().inject(buildDataSource(ds)); final String dsName = ds.getJndiName(); final PathAddress addr = getDataSourceAddress(dsName, deploymentUnit, false); installManagementModel(ds, deploymentUnit, addr); startDataSource(lds, jndiName, ds.getDriver(), serviceTarget, getRegistration(false, deploymentUnit), getResource(dsName, false, deploymentUnit), dsName, ds.isJTA(), support); } catch (DeploymentUnitProcessingException dupe) { throw dupe; } catch (Exception e) { throw ConnectorLogger.ROOT_LOGGER.exceptionDeployingDatasource(e, ds.getJndiName()); } } else { ConnectorLogger.DS_DEPLOYER_LOGGER.debugf("Ignoring: %s", ds.getJndiName()); } } } if (dataSources.getXaDataSource() != null && !dataSources.getXaDataSource().isEmpty()) { for (int i = 0; i < dataSources.getXaDataSource().size(); i++) { XaDataSource xads = (XaDataSource)dataSources.getXaDataSource().get(i); if (xads.isEnabled() && xads.getDriver() != null) { try { String jndiName = Util.cleanJndiName(xads.getJndiName(), xads.isUseJavaContext()); XaDataSourceService xds = new XaDataSourceService(jndiName, ContextNames.bindInfoFor(jndiName)); xds.getDataSourceConfigInjector().inject(buildXaDataSource(xads)); final String dsName = xads.getJndiName(); final PathAddress addr = getDataSourceAddress(dsName, deploymentUnit, true); installManagementModel(xads, deploymentUnit, addr); final Credential credential = xads.getRecovery() == null? null: xads.getRecovery().getCredential(); // TODO why have we been ignoring a configured legacy security domain but no legacy security present? startDataSource(xds, jndiName, xads.getDriver(), serviceTarget, getRegistration(true, deploymentUnit), getResource(dsName, true, deploymentUnit), dsName, true, support); } catch (Exception e) { throw ConnectorLogger.ROOT_LOGGER.exceptionDeployingDatasource(e, xads.getJndiName()); } } else { ConnectorLogger.DS_DEPLOYER_LOGGER.debugf("Ignoring %s", xads.getJndiName()); } } } } } private void installManagementModel(final DataSource ds, final DeploymentUnit deploymentUnit, final PathAddress addr) { XMLDataSourceRuntimeHandler.INSTANCE.registerDataSource(addr, ds); final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT); deploymentResourceSupport.getDeploymentSubModel(DataSourcesExtension.SUBSYSTEM_NAME, addr.getLastElement()); if (ds.getConnectionProperties() != null) { for (final Map.Entry<String, String> prop : ds.getConnectionProperties().entrySet()) { PathAddress registration = PathAddress.pathAddress(addr.getLastElement(), PathElement.pathElement(CONNECTION_PROPERTIES, prop.getKey())); deploymentResourceSupport.getDeploymentSubModel(DataSourcesExtension.SUBSYSTEM_NAME, registration); } } } private void installManagementModel(final XaDataSource ds, final DeploymentUnit deploymentUnit, final PathAddress addr) { XMLXaDataSourceRuntimeHandler.INSTANCE.registerDataSource(addr, ds); final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT); deploymentResourceSupport.getDeploymentSubModel(DataSourcesExtension.SUBSYSTEM_NAME, addr.getLastElement()); if (ds.getXaDataSourceProperty() != null) { for (final Map.Entry<String, String> prop : ds.getXaDataSourceProperty().entrySet()) { PathAddress registration = PathAddress.pathAddress(addr.getLastElement(), PathElement.pathElement(XA_CONNECTION_PROPERTIES, prop.getKey())); deploymentResourceSupport.getDeploymentSubModel(DataSourcesExtension.SUBSYSTEM_NAME, registration); } } } private void undeployDataSource(final DataSource ds, final DeploymentUnit deploymentUnit) { final PathAddress addr = getDataSourceAddress(ds.getJndiName(), deploymentUnit, false); XMLDataSourceRuntimeHandler.INSTANCE.unregisterDataSource(addr); } private void undeployXaDataSource(final XaDataSource ds, final DeploymentUnit deploymentUnit) { final PathAddress addr = getDataSourceAddress(ds.getJndiName(), deploymentUnit, true); XMLXaDataSourceRuntimeHandler.INSTANCE.unregisterDataSource(addr); } @Override public void undeploy(final DeploymentUnit deploymentUnit) { final List<DataSources> dataSourcesList = deploymentUnit.getAttachmentList(DsXmlDeploymentParsingProcessor.DATA_SOURCES_ATTACHMENT_KEY); for (final DataSources dataSources : dataSourcesList) { if (dataSources.getDataSource() != null) { for (int i = 0; i < dataSources.getDataSource().size(); i++) { DataSource ds = dataSources.getDataSource().get(i); undeployDataSource(ds, deploymentUnit); } } if (dataSources.getXaDataSource() != null) { for (int i = 0; i < dataSources.getXaDataSource().size(); i++) { XaDataSource xads = dataSources.getXaDataSource().get(i); undeployXaDataSource(xads, deploymentUnit); } } } deploymentUnit.removeAttachment(DsXmlDeploymentParsingProcessor.DATA_SOURCES_ATTACHMENT_KEY); } private ModifiableDataSource buildDataSource(DataSource ds) throws org.jboss.jca.common.api.validator.ValidateException { assert ds.getSecurity() == null || ds.getSecurity() instanceof DsSecurity; return new ModifiableDataSource(ds.getConnectionUrl(), ds.getDriverClass(), ds.getDataSourceClass(), ds.getDriver(), ds.getTransactionIsolation(), ds.getConnectionProperties(), ds.getTimeOut(), (DsSecurity) ds.getSecurity(), ds.getStatement(), ds.getValidation(), ds.getUrlDelimiter(), ds.getUrlSelectorStrategyClassName(), ds.getNewConnectionSql(), ds.isUseJavaContext(), ds.getPoolName(), ds.isEnabled(), ds.getJndiName(), ds.isSpy(), ds.isUseCcm(), ds.isJTA(), ds.isConnectable(), ds.isTracking(), ds.getMcp(), ds.isEnlistmentTrace(), ds.getPool()); } private ModifiableXaDataSource buildXaDataSource(XaDataSource xads) throws org.jboss.jca.common.api.validator.ValidateException { final DsXaPool xaPool; if (xads.getXaPool() == null) { xaPool = new DsXaPoolImpl(Defaults.MIN_POOL_SIZE, Defaults.INITIAL_POOL_SIZE, Defaults.MAX_POOL_SIZE, Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, Defaults.IS_SAME_RM_OVERRIDE, Defaults.INTERLEAVING, Defaults.PAD_XID, Defaults.WRAP_XA_RESOURCE, Defaults.NO_TX_SEPARATE_POOL, Defaults.ALLOW_MULTIPLE_USERS, null, Defaults.FAIR, null); } else { final DsXaPool p = xads.getXaPool(); xaPool = new DsXaPoolImpl(getDef(p.getMinPoolSize(), Defaults.MIN_POOL_SIZE), getDef(p.getInitialPoolSize(), Defaults.INITIAL_POOL_SIZE), getDef(p.getMaxPoolSize(), Defaults.MAX_POOL_SIZE), getDef(p.isPrefill(), Defaults.PREFILL), getDef(p.isUseStrictMin(), Defaults.USE_STRICT_MIN), getDef(p.getFlushStrategy(), Defaults.FLUSH_STRATEGY), getDef(p.isSameRmOverride(), Defaults.IS_SAME_RM_OVERRIDE), getDef(p.isInterleaving(), Defaults.INTERLEAVING), getDef(p.isPadXid(), Defaults.PAD_XID) , getDef(p.isWrapXaResource(), Defaults.WRAP_XA_RESOURCE), getDef(p.isNoTxSeparatePool(), Defaults.NO_TX_SEPARATE_POOL), getDef(p.isAllowMultipleUsers(), Defaults.ALLOW_MULTIPLE_USERS), p.getCapacity(), getDef(p.isFair(), Defaults.FAIR), p.getConnectionListener()); } return new ModifiableXaDataSource(xads.getTransactionIsolation(), xads.getTimeOut(), xads.getSecurity(), xads.getStatement(), xads.getValidation(), xads.getUrlDelimiter(), xads.getUrlProperty(), xads.getUrlSelectorStrategyClassName(), xads.isUseJavaContext(), xads.getPoolName(), xads.isEnabled(), xads.getJndiName(), xads.isSpy(), xads.isUseCcm(), xads.isConnectable(), xads.isTracking(), xads.getMcp(), xads.isEnlistmentTrace(), xads.getXaDataSourceProperty(), xads.getXaDataSourceClass(), xads.getDriver(), xads.getNewConnectionSql(), xaPool, xads.getRecovery()); } private <T> T getDef(T value, T def) { return value != null ? value : def; } private void startDataSource(final AbstractDataSourceService dataSourceService, final String jndiName, final String driverName, final ServiceTarget serviceTarget, final ManagementResourceRegistration registration, final Resource resource, final String managementName, final boolean isTransactional, final CapabilityServiceSupport support) throws DeploymentUnitProcessingException { final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName); final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo); final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency( serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector()) .addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector()) .addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()) .addDependency(support.getCapabilityServiceName(ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME), TransactionIntegration.class, dataSourceService.getTransactionIntegrationInjector()) .addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, dataSourceService.getManagementRepositoryInjector()) .addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector()) .addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, dataSourceService.getDriverRegistryInjector()); dataSourceServiceBuilder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME)); dataSourceServiceBuilder.requires(support.getCapabilityServiceName(NamingService.CAPABILITY_NAME)); //Register an empty override model regardless of we're enabled or not - the statistics listener will add the relevant childresources if (registration.isAllowsOverride()) { ManagementResourceRegistration overrideRegistration = registration.getOverrideModel(managementName); if (overrideRegistration == null || overrideRegistration.isAllowsOverride()) { overrideRegistration = registration.registerOverrideModel(managementName, DataSourcesSubsystemProviders.OVERRIDE_DS_DESC); } DataSourceStatisticsService statsService = new DataSourceStatisticsService(registration, false ); final ServiceBuilder statsServiceSB = serviceTarget.addService(dataSourceServiceName.append(Constants.STATISTICS), statsService); statsServiceSB.requires(dataSourceServiceName); statsServiceSB.addDependency(CommonDeploymentService.getServiceName(bindInfo), CommonDeployment.class, statsService.getCommonDeploymentInjector()); statsServiceSB.setInitialMode(ServiceController.Mode.PASSIVE); statsServiceSB.install(); DataSourceStatisticsService.registerStatisticsResources(resource); } // else should probably throw an ISE or something final ServiceName driverServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")); if (driverServiceName != null) { dataSourceServiceBuilder.addDependency(driverServiceName, Driver.class, dataSourceService.getDriverInjector()); } final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService(); final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE .append(jndiName); final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, javax.sql.DataSource.class, referenceFactoryService.getDataSourceInjector()); final BinderService binderService = new BinderService(bindInfo.getBindName()); final ServiceBuilder<?> binderBuilder = serviceTarget .addService(bindInfo.getBinderServiceName(), binderService) .addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()) .addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new LifecycleListener() { private volatile boolean bound; public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) { switch (event) { case UP: { if (isTransactional) { SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName); } else { SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName); } bound = true; break; } case DOWN: { if (bound) { if (isTransactional) { SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName); } else { SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName); } } break; } case REMOVED: { SUBSYSTEM_DATASOURCES_LOGGER.debugf("Removed JDBC Data-source [%s]", jndiName); break; } } } }); dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install(); referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install(); binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install(); } private static PathAddress getDataSourceAddress(final String jndiName, DeploymentUnit deploymentUnit, boolean xa) { List<PathElement> elements = new ArrayList<PathElement>(); if (deploymentUnit.getParent() == null) { elements.add(PathElement.pathElement(ModelDescriptionConstants.DEPLOYMENT, deploymentUnit.getName())); } else { elements.add(PathElement.pathElement(ModelDescriptionConstants.DEPLOYMENT, deploymentUnit.getParent().getName())); elements.add(PathElement.pathElement(ModelDescriptionConstants.SUBDEPLOYMENT, deploymentUnit.getName())); } elements.add(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, DataSourcesExtension.SUBSYSTEM_NAME)); if (xa) { elements.add(PathElement.pathElement(XA_DATA_SOURCE, jndiName)); } else { elements.add(PathElement.pathElement(DATA_SOURCE, jndiName)); } return PathAddress.pathAddress(elements); } static Resource getOrCreate(final Resource parent, final PathAddress address) { Resource current = parent; for (final PathElement element : address) { synchronized (current) { if (current.hasChild(element)) { current = current.requireChild(element); } else { final Resource resource = Resource.Factory.create(); current.registerChild(element, resource); current = resource; } } } return current; } private Resource getResource(final String dsName, final boolean xa, final DeploymentUnit unit) { final Resource root = unit.getAttachment(DeploymentModelUtils.DEPLOYMENT_RESOURCE); final String key = xa ? XA_DATA_SOURCE : DATA_SOURCE; final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(key, dsName)); synchronized (root) { final Resource subsystem = getOrCreate(root, SUBSYSTEM_ADDRESS); return getOrCreate(subsystem, address); } } private ManagementResourceRegistration getRegistration(final boolean xa, final DeploymentUnit unit) { final Resource root = unit.getAttachment(DeploymentModelUtils.DEPLOYMENT_RESOURCE); synchronized (root) { ManagementResourceRegistration registration = unit.getAttachment(DeploymentModelUtils.MUTABLE_REGISTRATION_ATTACHMENT); final PathAddress address = xa ? XA_DATASOURCE_ADDRESS : DATASOURCE_ADDRESS; ManagementResourceRegistration subModel = registration.getSubModel(address); if (subModel == null) { throw new IllegalStateException(address.toString()); } return subModel; } } }
26,615
59.353741
242
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ds/processors/DriverManagerAdapterProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, 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.connector.deployers.ds.processors; import org.jboss.as.connector._drivermanager.DriverManagerAdapter; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.module.ModuleSpecification; import org.jboss.modules.AbstractResourceLoader; import org.jboss.modules.ClassSpec; import org.jboss.modules.ResourceLoaderSpec; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.util.Collection; import java.util.Collections; /** * @author <a href="mailto:[email protected]">Tomasz Adamski</a> * <p> * https://issues.redhat.com/browse/WFLY-14114 * <p> * This is a hack that allows us to get access to {@link java.sql.Driver} registered by the driver code. Those objects are created by the * driver code and registered in {@link java.sql.DriverManager}. Driver objects are not guaranteed to be deregistered which leads to leaks. * {@link java.sql.DriverManager} allows for obtaining the list of drivers, and deregistering a driver but only in a give classloading context. * As a result, connector module can not neither list or deregister drivers from a deployed driver module. * <p> * To work this around, this hack modifies driver's module by injecting {@link DriverManagerAdapter} class to it. Because @{@link DriverManagerAdapter} * is loaded by driver module it allows to obtain and deregister the drivers. */ public class DriverManagerAdapterProcessor implements DeploymentUnitProcessor { @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final DriverAdapterResourceLoader resourceLoader = new DriverAdapterResourceLoader(); moduleSpecification.addResourceLoader(ResourceLoaderSpec.createResourceLoaderSpec(resourceLoader)); } static class DriverAdapterResourceLoader extends AbstractResourceLoader { @Override public ClassSpec getClassSpec(final String fileName) throws IOException { InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName); if (is == null) { return null; } final byte[] bytes = readAllBytesFromStream(is); final ClassSpec spec = new ClassSpec(); spec.setBytes(bytes); return spec; } @Override public Collection<String> getPaths() { return Collections.singletonList(DriverManagerAdapter.class.getPackage().getName().replace('.','/')); } private static byte[] readAllBytesFromStream(final InputStream is) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { final byte[] buffer = new byte[1024]; int read = 0; while ((read = is.read(buffer)) != -1) { bos.write(buffer, 0, read); } return bos.toByteArray(); } finally { safeClose(is); safeClose(bos); } } private static void safeClose(final Closeable c) { if (c != null) { try { c.close(); } catch (Throwable ignored) {} } } } }
4,840
43.824074
151
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ds/processors/DriverProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ds.processors; import static org.jboss.as.connector.logging.ConnectorLogger.DEPLOYER_JDBC_LOGGER; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.Driver; import java.util.Enumeration; import java.util.List; import org.jboss.as.connector._drivermanager.DriverManagerAdapter; import org.jboss.as.connector.services.driver.DriverService; import org.jboss.as.connector.services.driver.InstalledDriver; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.ServicesAttachment; import org.jboss.modules.Module; import org.jboss.modules.ModuleClassLoader; import org.jboss.msc.service.ServiceController.Mode; import org.jboss.msc.service.ServiceName; import org.wildfly.common.Assert; /** * Deploy any JDBC drivers in a deployment unit. * @author <a href="mailto:[email protected]">David M. Lloyd</a> */ public final class DriverProcessor implements DeploymentUnitProcessor { /** {@inheritDoc} */ @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final Module module = deploymentUnit.getAttachment(Attachments.MODULE); final ServicesAttachment servicesAttachment = deploymentUnit.getAttachment(Attachments.SERVICES); if (module != null && servicesAttachment != null) { final ModuleClassLoader classLoader = module.getClassLoader(); final List<String> driverNames = servicesAttachment.getServiceImplementations(Driver.class.getName()); int idx = 0; for (String driverClassName : driverNames) { try { final Class<? extends Driver> driverClass = classLoader.loadClass(driverClassName).asSubclass(Driver.class); final Constructor<? extends Driver> constructor = driverClass.getConstructor(); final Driver driver = constructor.newInstance(); final int majorVersion = driver.getMajorVersion(); final int minorVersion = driver.getMinorVersion(); final boolean compliant = driver.jdbcCompliant(); if (compliant) { DEPLOYER_JDBC_LOGGER.deployingCompliantJdbcDriver(driverClass, majorVersion, minorVersion); } else { DEPLOYER_JDBC_LOGGER.deployingNonCompliantJdbcDriver(driverClass, majorVersion, minorVersion); } String driverName = deploymentUnit.getName(); if ((driverName.contains(".") && ! driverName.endsWith(".jar")) || driverNames.size() != 1) { driverName += "_" + driverClassName + "_" + majorVersion + "_" + minorVersion; } InstalledDriver driverMetadata = new InstalledDriver(driverName, driverClass.getName(), null, null, majorVersion, minorVersion, compliant); DriverService driverService = new DriverService(driverMetadata, driver); phaseContext .getServiceTarget() .addService(ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")), driverService) .addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, driverService.getDriverRegistryServiceInjector()).setInitialMode(Mode.ACTIVE).install(); if (idx == 0 && driverNames.size() != 1) { // create short name driver service driverName = deploymentUnit.getName(); // reset driverName to the deployment unit name driverMetadata = new InstalledDriver(driverName, driverClass.getName(), null, null, majorVersion, minorVersion, compliant); driverService = new DriverService(driverMetadata, driver); phaseContext.getServiceTarget() .addService(ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")), driverService) .addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, driverService.getDriverRegistryServiceInjector()) .setInitialMode(Mode.ACTIVE).install(); } idx++; } catch (Throwable e) { DEPLOYER_JDBC_LOGGER.cannotInstantiateDriverClass(driverClassName, e); } } } } /** {@inheritDoc} */ @Override public void undeploy(final DeploymentUnit context) { /** * https://issues.redhat.com/browse/WFLY-14114 * * This hack allows to deregister all drivers registered by this module. See comments in {@link DriverManagerAdapterProcessor} */ final Module module = context.getAttachment(Attachments.MODULE); final ServicesAttachment servicesAttachment = context.getAttachment(Attachments.SERVICES); if (module != null && servicesAttachment != null) { final List<String> driverNames = servicesAttachment.getServiceImplementations(Driver.class.getName()); if (!driverNames.isEmpty()) { try { Class<?> driverManagerAdapterClass = module.getClassLoader().loadClass(DriverManagerAdapter.class.getName()); Method getDriversMethod = driverManagerAdapterClass.getDeclaredMethod("getDrivers"); Enumeration<Driver> drivers = (Enumeration<Driver>) getDriversMethod.invoke(null, null); Method deregisterDriverMethod = driverManagerAdapterClass.getDeclaredMethod("deregisterDriver", Driver.class); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); if(driverNames.contains(driver.getClass().getName())) { deregisterDriverMethod.invoke(null, driver); } } } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { Assert.unreachableCode(); } } } } }
8,000
53.80137
166
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ds/processors/StructureDriverProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ds.processors; import static org.jboss.as.connector.logging.ConnectorLogger.DEPLOYER_JDBC_LOGGER; import java.util.List; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.DeploymentUtils; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.vfs.VirtualFile; /** * Detects a JDBC driver at an early stage. * Currently this does nothig * * @author Jason T. Greene * @author [email protected] */ public final class StructureDriverProcessor implements DeploymentUnitProcessor { @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit); for (ResourceRoot resourceRoot : resourceRoots) { final VirtualFile deploymentRoot = resourceRoot.getRoot(); if (deploymentRoot.getChild("META-INF/services/java.sql.Driver").exists()) { DEPLOYER_JDBC_LOGGER.debugf("SQL driver detected: %s", deploymentUnit.getName()); break; } } } }
2,488
41.186441
108
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ds/processors/JdbcDriverDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2023, 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.connector.deployers.ds.processors; import java.util.List; import java.util.Locale; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.DeploymentUtils; import org.jboss.as.server.deployment.module.ModuleDependency; import org.jboss.as.server.deployment.module.ModuleSpecification; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.modules.Module; import org.jboss.modules.ModuleLoader; import org.jboss.vfs.VirtualFile; /** * Configures dependencies for JDBC driver deployments. */ public final class JdbcDriverDeploymentProcessor implements DeploymentUnitProcessor { private static final String JAR_SUFFIX = ".jar"; private static final String JDBC_DRIVER_CONFIG_FILE = "META-INF/services/java.sql.Driver"; private static final String JDK_SECURITY_JGSS_ID = "jdk.security.jgss"; public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final String deploymentName = deploymentUnit.getName().toLowerCase(Locale.ENGLISH); if (!deploymentName.endsWith(JAR_SUFFIX)) { return; } final ModuleLoader moduleLoader = Module.getBootModuleLoader(); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); boolean javaSqlDriverDetected = false; final List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit); for (ResourceRoot resourceRoot : resourceRoots) { final VirtualFile deploymentRoot = resourceRoot.getRoot(); if (deploymentRoot.getChild(JDBC_DRIVER_CONFIG_FILE).exists()) { javaSqlDriverDetected = true; break; } } if (javaSqlDriverDetected) { moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JDK_SECURITY_JGSS_ID, false, false, false, false)); } } }
3,358
43.197368
138
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/AdministeredObjectDefinitionInjectionSource.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.connector.deployers.ra; import org.jboss.as.connector.services.mdr.AS7MetadataRepository; import org.jboss.as.connector.services.resourceadapters.AdminObjectReferenceFactoryService; import org.jboss.as.connector.services.resourceadapters.DirectAdminObjectActivatorService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.naming.ManagedReferenceFactory; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.modules.Module; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import static org.jboss.as.connector.logging.ConnectorLogger.DEPLOYMENT_CONNECTOR_LOGGER; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; /** * A binding description for AdministeredObjectDefinition annotations. * <p/> * The referenced admin object must be directly visible to the * component declaring the annotation. * * @author Jesper Pedersen */ public class AdministeredObjectDefinitionInjectionSource extends ResourceDefinitionInjectionSource { public static final String DESCRIPTION = "description"; public static final String INTERFACE = "interfaceName"; public static final String PROPERTIES = "properties"; private final String className; private final String resourceAdapter; private String description; private String interfaceName; public AdministeredObjectDefinitionInjectionSource(final String jndiName, final String className, final String resourceAdapter) { super(jndiName); this.className = className; this.resourceAdapter = resourceAdapter; } public void addProperty(String key, String value) { properties.put(key, value); } public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); String raId = resourceAdapter; if (resourceAdapter.startsWith("#")) { raId = deploymentUnit.getParent().getName() + raId; } String deployerServiceName = raId; if (!raId.endsWith(".rar")) { deployerServiceName = deployerServiceName + ".rar"; raId = deployerServiceName; } SUBSYSTEM_RA_LOGGER.debugf("@AdministeredObjectDefinition: %s for %s binding to %s ", className, resourceAdapter, jndiName); ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName); DirectAdminObjectActivatorService service = new DirectAdminObjectActivatorService(jndiName, className, resourceAdapter, raId, properties, module, bindInfo); ServiceName serviceName = DirectAdminObjectActivatorService.SERVICE_NAME_BASE.append(jndiName); final ServiceBuilder sb = phaseContext.getServiceTarget().addService(serviceName, service); sb.addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, service.getMdrInjector()); sb.requires(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(deployerServiceName)); sb.setInitialMode(ServiceController.Mode.ACTIVE).install(); serviceBuilder.addDependency(AdminObjectReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName()), ManagedReferenceFactory.class, injector); serviceBuilder.addListener(new LifecycleListener() { private volatile boolean bound; public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) { switch (event) { case UP: { DEPLOYMENT_CONNECTOR_LOGGER.adminObjectAnnotation(jndiName); bound = true; break; } case DOWN: { if (bound) { DEPLOYMENT_CONNECTOR_LOGGER.unboundJca("AdminObject", jndiName); } break; } case REMOVED: { DEPLOYMENT_CONNECTOR_LOGGER.debugf("Removed JCA AdminObject [%s]", jndiName); } } } }); } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getInterface() { return interfaceName; } public void setInterface(String interfaceName) { this.interfaceName = interfaceName; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; AdministeredObjectDefinitionInjectionSource that = (AdministeredObjectDefinitionInjectionSource) o; if (className != null ? !className.equals(that.className) : that.className != null) return false; if (description != null ? !description.equals(that.description) : that.description != null) return false; if (interfaceName != null ? !interfaceName.equals(that.interfaceName) : that.interfaceName != null) return false; if (resourceAdapter != null ? !resourceAdapter.equals(that.resourceAdapter) : that.resourceAdapter != null) return false; return true; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (className != null ? className.hashCode() : 0); result = 31 * result + (resourceAdapter != null ? resourceAdapter.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (interfaceName != null ? interfaceName.hashCode() : 0); return result; } }
7,724
44.175439
241
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/ConnectionFactoryDefinitionAnnotationProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.connector.deployers.ra; import org.jboss.as.ee.resource.definition.ResourceDefinitionAnnotationProcessor; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.DotName; import org.jboss.metadata.property.PropertyReplacer; import jakarta.resource.ConnectionFactoryDefinition; import jakarta.resource.ConnectionFactoryDefinitions; import jakarta.resource.spi.TransactionSupport; /** * Deployment processor responsible for processing {@link jakarta.resource.ConnectionFactoryDefinition} and {@link jakarta.resource.ConnectionFactoryDefinitions}. * * @author Jesper Pedersen * @author Eduardo Martins */ public class ConnectionFactoryDefinitionAnnotationProcessor extends ResourceDefinitionAnnotationProcessor { private static final DotName CONNECTION_FACTORY_DEFINITION = DotName.createSimple(ConnectionFactoryDefinition.class.getName()); private static final DotName CONNECTION_FACTORY_DEFINITIONS = DotName.createSimple(ConnectionFactoryDefinitions.class.getName()); private final boolean legacySecurityAvailable; public ConnectionFactoryDefinitionAnnotationProcessor(boolean legacySecurityAvailable) { this.legacySecurityAvailable = legacySecurityAvailable; } @Override protected DotName getAnnotationDotName() { return CONNECTION_FACTORY_DEFINITION; } @Override protected DotName getAnnotationCollectionDotName() { return CONNECTION_FACTORY_DEFINITIONS; } @Override protected ResourceDefinitionInjectionSource processAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException { final String name = AnnotationElement.asRequiredString(annotationInstance, AnnotationElement.NAME); final String interfaceName = AnnotationElement.asRequiredString(annotationInstance, "interfaceName"); final String ra = AnnotationElement.asRequiredString(annotationInstance, "resourceAdapter"); final ConnectionFactoryDefinitionInjectionSource directConnectionFactoryInjectionSource = new ConnectionFactoryDefinitionInjectionSource(name, interfaceName, ra); directConnectionFactoryInjectionSource.setDescription(AnnotationElement.asOptionalString(annotationInstance, ConnectionFactoryDefinitionInjectionSource.DESCRIPTION)); directConnectionFactoryInjectionSource.setMaxPoolSize(AnnotationElement.asOptionalInt(annotationInstance, ConnectionFactoryDefinitionInjectionSource.MAX_POOL_SIZE)); directConnectionFactoryInjectionSource.setMinPoolSize(AnnotationElement.asOptionalInt(annotationInstance, ConnectionFactoryDefinitionInjectionSource.MIN_POOL_SIZE)); directConnectionFactoryInjectionSource.addProperties(AnnotationElement.asOptionalStringArray(annotationInstance, AnnotationElement.PROPERTIES)); directConnectionFactoryInjectionSource.setTransactionSupportLevel(asTransactionSupportLocal(annotationInstance, ConnectionFactoryDefinitionInjectionSource.TRANSACTION_SUPPORT)); directConnectionFactoryInjectionSource.setLegacySecurityAvailable(legacySecurityAvailable); return directConnectionFactoryInjectionSource; } private TransactionSupport.TransactionSupportLevel asTransactionSupportLocal(final AnnotationInstance annotation, String property) { AnnotationValue value = annotation.value(property); return value == null ? null : TransactionSupport.TransactionSupportLevel.valueOf((String)value.value()); } }
4,816
51.934066
182
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/AdministeredObjectDefinitionDescriptorProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.connector.deployers.ra; import org.jboss.as.ee.resource.definition.ResourceDefinitionDescriptorProcessor; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.metadata.javaee.spec.AdministeredObjectMetaData; import org.jboss.metadata.javaee.spec.AdministeredObjectsMetaData; import org.jboss.metadata.javaee.spec.RemoteEnvironment; import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER; /** * Deployment processor responsible for processing administered-object deployment descriptor elements * * @author Eduardo Martins */ public class AdministeredObjectDefinitionDescriptorProcessor extends ResourceDefinitionDescriptorProcessor { @Override protected void processEnvironment(RemoteEnvironment environment, ResourceDefinitionInjectionSources injectionSources) throws DeploymentUnitProcessingException { final AdministeredObjectsMetaData metaDatas = environment.getAdministeredObjects(); if (metaDatas != null) { for(AdministeredObjectMetaData metaData : metaDatas) { injectionSources.addResourceDefinitionInjectionSource(getResourceDefinitionInjectionSource(metaData)); } } } private ResourceDefinitionInjectionSource getResourceDefinitionInjectionSource(final AdministeredObjectMetaData metaData) { final String name = metaData.getName(); if (name == null || name.isEmpty()) { throw ROOT_LOGGER.elementAttributeMissing("<administered-object>", "name"); } final String className = metaData.getClassName(); if (className == null || className.isEmpty()) { throw ROOT_LOGGER.elementAttributeMissing("<administered-object>", "className"); } final String resourceAdapter = metaData.getResourceAdapter(); if (resourceAdapter == null || resourceAdapter.isEmpty()) { throw ROOT_LOGGER.elementAttributeMissing("<administered-object>", "resourceAdapter"); } final AdministeredObjectDefinitionInjectionSource resourceDefinitionInjectionSource = new AdministeredObjectDefinitionInjectionSource(name, className, resourceAdapter); resourceDefinitionInjectionSource.setInterface(metaData.getInterfaceName()); if (metaData.getDescriptions() != null) { resourceDefinitionInjectionSource.setDescription(metaData.getDescriptions().toString()); } resourceDefinitionInjectionSource.addProperties(metaData.getProperties()); return resourceDefinitionInjectionSource; } }
3,675
48.675676
176
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/ConnectionFactoryDefinitionInjectionSource.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.connector.deployers.ra; import org.jboss.as.connector.services.mdr.AS7MetadataRepository; import org.jboss.as.connector.services.resourceadapters.ConnectionFactoryReferenceFactoryService; import org.jboss.as.connector.services.resourceadapters.DirectConnectionFactoryActivatorService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.naming.ManagedReferenceFactory; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.modules.Module; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import jakarta.resource.spi.TransactionSupport; import static org.jboss.as.connector.logging.ConnectorLogger.DEPLOYMENT_CONNECTOR_LOGGER; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; /** * A binding description for ConnectionFactoryDefinition annotations. * <p/> * The referenced connection factory must be directly visible to the * component declaring the annotation. * * @author Jesper Pedersen */ public class ConnectionFactoryDefinitionInjectionSource extends ResourceDefinitionInjectionSource { public static final String DESCRIPTION = "description"; public static final String MAX_POOL_SIZE = "maxPoolSize"; public static final String MIN_POOL_SIZE = "minPoolSize"; public static final String TRANSACTION_SUPPORT = "transactionSupport"; private final String interfaceName; private final String resourceAdapter; private String description; private int maxPoolSize = -1; private int minPoolSize = -1; private TransactionSupport.TransactionSupportLevel transactionSupport; private boolean legacySecurityAvailable; public ConnectionFactoryDefinitionInjectionSource(final String jndiName, final String interfaceName, final String resourceAdapter) { super(jndiName); this.interfaceName = interfaceName; this.resourceAdapter = resourceAdapter; } public void addProperty(String key, String value) { properties.put(key, value); } public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); String raId = resourceAdapter; if (resourceAdapter.startsWith("#")) { raId = deploymentUnit.getParent().getName() + raId; } String deployerServiceName = raId; if(! raId.endsWith(".rar")) { deployerServiceName = deployerServiceName + ".rar"; raId = deployerServiceName; } SUBSYSTEM_RA_LOGGER.debugf("@ConnectionFactoryDefinition: %s for %s binding to %s ", interfaceName, resourceAdapter, jndiName); ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName); DirectConnectionFactoryActivatorService service = new DirectConnectionFactoryActivatorService(jndiName, interfaceName, resourceAdapter, raId, maxPoolSize, minPoolSize, properties, transactionSupport, module, bindInfo, legacySecurityAvailable); ServiceName serviceName = DirectConnectionFactoryActivatorService.SERVICE_NAME_BASE.append(jndiName); final ServiceBuilder sb = phaseContext.getServiceTarget().addService(serviceName, service); sb.addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, service.getMdrInjector()); sb.requires(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(deployerServiceName)); sb.setInitialMode(ServiceController.Mode.ACTIVE).install(); serviceBuilder.addDependency(ConnectionFactoryReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName()), ManagedReferenceFactory.class, injector); serviceBuilder.addListener(new LifecycleListener() { public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) { switch (event) { case UP: { DEPLOYMENT_CONNECTOR_LOGGER.connectionFactoryAnnotation(jndiName); break; } case DOWN: { break; } case REMOVED: { DEPLOYMENT_CONNECTOR_LOGGER.debugf("Removed JCA ConnectionFactory [%s]", jndiName); } } } }); } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getMaxPoolSize() { return maxPoolSize; } public void setMaxPoolSize(int maxPoolSize) { this.maxPoolSize = maxPoolSize; } public int getMinPoolSize() { return minPoolSize; } public void setMinPoolSize(int minPoolSize) { this.minPoolSize = minPoolSize; } public TransactionSupport.TransactionSupportLevel getTransactionSupportLevel() { return transactionSupport; } public void setTransactionSupportLevel(TransactionSupport.TransactionSupportLevel transactionSupport) { this.transactionSupport = transactionSupport; } public void setLegacySecurityAvailable(boolean legacySecurityAvailable) { this.legacySecurityAvailable = legacySecurityAvailable; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; ConnectionFactoryDefinitionInjectionSource that = (ConnectionFactoryDefinitionInjectionSource) o; if (maxPoolSize != that.maxPoolSize) return false; if (minPoolSize != that.minPoolSize) return false; if (description != null ? !description.equals(that.description) : that.description != null) return false; if (interfaceName != null ? !interfaceName.equals(that.interfaceName) : that.interfaceName != null) return false; if (resourceAdapter != null ? !resourceAdapter.equals(that.resourceAdapter) : that.resourceAdapter != null) return false; if (transactionSupport != that.transactionSupport) return false; return true; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (interfaceName != null ? interfaceName.hashCode() : 0); result = 31 * result + (resourceAdapter != null ? resourceAdapter.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + maxPoolSize; result = 31 * result + minPoolSize; result = 31 * result + (transactionSupport != null ? transactionSupport.hashCode() : 0); return result; } }
8,898
43.054455
241
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/ConnectionFactoryDefinitionDescriptorProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.connector.deployers.ra; import org.jboss.as.ee.resource.definition.ResourceDefinitionDescriptorProcessor; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.metadata.javaee.spec.ConnectionFactoriesMetaData; import org.jboss.metadata.javaee.spec.ConnectionFactoryMetaData; import org.jboss.metadata.javaee.spec.RemoteEnvironment; import jakarta.resource.spi.TransactionSupport; import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER; /** * Deployment processor responsible for processing connection-factory deployment descriptor elements * * @author Eduardo Martins */ public class ConnectionFactoryDefinitionDescriptorProcessor extends ResourceDefinitionDescriptorProcessor { private final boolean legacySecurityAvailable; public ConnectionFactoryDefinitionDescriptorProcessor(boolean legacySecurityAvailable) { this.legacySecurityAvailable = legacySecurityAvailable; } @Override protected void processEnvironment(RemoteEnvironment environment, ResourceDefinitionInjectionSources injectionSources) throws DeploymentUnitProcessingException { final ConnectionFactoriesMetaData metaDatas = environment.getConnectionFactories(); if (metaDatas != null) { for(ConnectionFactoryMetaData metaData : metaDatas) { injectionSources.addResourceDefinitionInjectionSource(getResourceDefinitionInjectionSource(metaData)); } } } private ResourceDefinitionInjectionSource getResourceDefinitionInjectionSource(final ConnectionFactoryMetaData metaData) { final String name = metaData.getName(); if (name == null || name.isEmpty()) { throw ROOT_LOGGER.elementAttributeMissing("<connection-factory>", "name"); } final String interfaceName = metaData.getInterfaceName(); if (interfaceName == null || interfaceName.isEmpty()) { throw ROOT_LOGGER.elementAttributeMissing("<connection-factory>", "interfaceName"); } final String resourceAdapter = metaData.getResourceAdapter(); if (resourceAdapter == null || resourceAdapter.isEmpty()) { throw ROOT_LOGGER.elementAttributeMissing("<connection-factory>", "resourceAdapter"); } final ConnectionFactoryDefinitionInjectionSource resourceDefinitionInjectionSource = new ConnectionFactoryDefinitionInjectionSource(name, interfaceName, resourceAdapter); if (metaData.getDescriptions() != null) { resourceDefinitionInjectionSource.setDescription(metaData.getDescriptions().toString()); } resourceDefinitionInjectionSource.setMaxPoolSize(metaData.getMaxPoolSize()); resourceDefinitionInjectionSource.setMinPoolSize(metaData.getMinPoolSize()); if (metaData.getTransactionSupport() != null) { // FIXME use TransactionSupport.TransactionSupportLevel in metadata object switch (metaData.getTransactionSupport()) { case NoTransaction: resourceDefinitionInjectionSource.setTransactionSupportLevel(TransactionSupport.TransactionSupportLevel.NoTransaction); break; case LocalTransaction: resourceDefinitionInjectionSource.setTransactionSupportLevel(TransactionSupport.TransactionSupportLevel.LocalTransaction); break; case XATransaction: resourceDefinitionInjectionSource.setTransactionSupportLevel(TransactionSupport.TransactionSupportLevel.XATransaction); break; } } resourceDefinitionInjectionSource.setLegacySecurityAvailable(legacySecurityAvailable); resourceDefinitionInjectionSource.addProperties(metaData.getProperties()); return resourceDefinitionInjectionSource; } }
4,972
49.744898
178
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/AdministeredObjectDefinitionAnnotationProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.connector.deployers.ra; import org.jboss.as.ee.resource.definition.ResourceDefinitionAnnotationProcessor; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.DotName; import org.jboss.metadata.property.PropertyReplacer; import jakarta.resource.AdministeredObjectDefinition; import jakarta.resource.AdministeredObjectDefinitions; /** * Deployment processor responsible for processing {@link jakarta.resource.AdministeredObjectDefinition} and {@link jakarta.resource.AdministeredObjectDefinitions}. * * @author Jesper Pedersen * @author Eduardo Martins */ public class AdministeredObjectDefinitionAnnotationProcessor extends ResourceDefinitionAnnotationProcessor { private static final DotName ANNOTATION_NAME = DotName.createSimple(AdministeredObjectDefinition.class.getName()); private static final DotName COLLECTION_ANNOTATION_NAME = DotName.createSimple(AdministeredObjectDefinitions.class.getName()); @Override protected DotName getAnnotationDotName() { return ANNOTATION_NAME; } @Override protected DotName getAnnotationCollectionDotName() { return COLLECTION_ANNOTATION_NAME; } @Override protected ResourceDefinitionInjectionSource processAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException { final String name = AnnotationElement.asRequiredString(annotationInstance, AnnotationElement.NAME); final String className = AnnotationElement.asRequiredString(annotationInstance, "className"); final String ra = AnnotationElement.asRequiredString(annotationInstance, "resourceAdapter"); final AdministeredObjectDefinitionInjectionSource directAdministeredObjectInjectionSource = new AdministeredObjectDefinitionInjectionSource(name, className, ra); directAdministeredObjectInjectionSource.setDescription(AnnotationElement.asOptionalString(annotationInstance, AdministeredObjectDefinitionInjectionSource.DESCRIPTION)); directAdministeredObjectInjectionSource.setInterface(AnnotationElement.asOptionalString(annotationInstance, AdministeredObjectDefinitionInjectionSource.INTERFACE)); directAdministeredObjectInjectionSource.addProperties(AnnotationElement.asOptionalStringArray(annotationInstance, AdministeredObjectDefinitionInjectionSource.PROPERTIES)); return directAdministeredObjectInjectionSource; } }
3,693
49.60274
182
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/RaDeploymentActivator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.deployers.ra; import static org.jboss.as.connector.util.ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME; import org.jboss.as.connector.deployers.ds.processors.DriverProcessor; import org.jboss.as.connector.deployers.ds.processors.DriverManagerAdapterProcessor; import org.jboss.as.connector.deployers.ds.processors.StructureDriverProcessor; import org.jboss.as.connector.deployers.ra.processors.IronJacamarDeploymentParsingProcessor; import org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor; import org.jboss.as.connector.deployers.ra.processors.RaDeploymentParsingProcessor; import org.jboss.as.connector.deployers.ra.processors.RaNativeProcessor; import org.jboss.as.connector.deployers.ra.processors.RaStructureProcessor; import org.jboss.as.connector.deployers.ra.processors.RaXmlDependencyProcessor; import org.jboss.as.connector.deployers.ra.processors.RaXmlDeploymentProcessor; import org.jboss.as.connector.deployers.ra.processors.RarDependencyProcessor; import org.jboss.as.connector.services.mdr.MdrService; import org.jboss.as.connector.services.rarepository.NonJTADataSourceRaRepositoryService; import org.jboss.as.connector.services.rarepository.RaRepositoryService; import org.jboss.as.connector.services.resourceadapters.deployment.registry.ResourceAdapterDeploymentRegistryService; import org.jboss.as.connector.services.resourceadapters.repository.ManagementRepositoryService; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersExtension; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.as.server.deployment.Phase; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceTarget; /** * Service activator which installs the various service required for rar * deployments. * * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public class RaDeploymentActivator { private final boolean appclient; private final boolean legacySecurityAvailable; private final MdrService mdrService = new MdrService(); public RaDeploymentActivator(final boolean appclient, final boolean legacySecurityAvailable) { this.appclient = appclient; this.legacySecurityAvailable = legacySecurityAvailable; } public void activateServices(final ServiceTarget serviceTarget) { // add resources here serviceTarget.addService(ConnectorServices.IRONJACAMAR_MDR, mdrService) .install(); RaRepositoryService raRepositoryService = new RaRepositoryService(); serviceTarget.addService(ConnectorServices.RA_REPOSITORY_SERVICE, raRepositoryService) .addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, raRepositoryService.getMdrInjector()) .addDependency(ConnectorServices.getCachedCapabilityServiceName(TRANSACTION_INTEGRATION_CAPABILITY_NAME), TransactionIntegration.class, raRepositoryService.getTransactionIntegrationInjector()) .install(); // Special resource adapter repository and bootstrap context for non-JTA datasources NonJTADataSourceRaRepositoryService nonJTADataSourceRaRepositoryService = new NonJTADataSourceRaRepositoryService(); serviceTarget.addService(ConnectorServices.NON_JTA_DS_RA_REPOSITORY_SERVICE, nonJTADataSourceRaRepositoryService) .addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, nonJTADataSourceRaRepositoryService.getMdrInjector()) .install(); ManagementRepositoryService managementRepositoryService = new ManagementRepositoryService(); serviceTarget.addService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, managementRepositoryService) .install(); ResourceAdapterDeploymentRegistryService registryService = new ResourceAdapterDeploymentRegistryService(); final ServiceBuilder sb = serviceTarget.addService(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, registryService); sb.requires(ConnectorServices.IRONJACAMAR_MDR); sb.install(); } public void activateProcessors(final DeploymentProcessorTarget updateContext) { updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_RAR, new RaStructureProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_JDBC_DRIVER, new StructureDriverProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_RA_DEPLOYMENT, new RaDeploymentParsingProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_IRON_JACAMAR_DEPLOYMENT, new IronJacamarDeploymentParsingProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_RESOURCE_DEF_ANNOTATION_CONNECTION_FACTORY, new ConnectionFactoryDefinitionAnnotationProcessor(legacySecurityAvailable)); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_RESOURCE_DEF_ANNOTATION_ADMINISTERED_OBJECT, new AdministeredObjectDefinitionAnnotationProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_RAR_CONFIG, new RarDependencyProcessor(appclient)); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.CONFIGURE_MODULE, Phase.CONFIGURE_JDBC_DRIVER_MANAGER_ADAPTER, new DriverManagerAdapterProcessor()); if (!appclient) updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_RAR_SERVICES_DEPS, new RaXmlDependencyProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_RESOURCE_DEF_XML_CONNECTION_FACTORY, new ConnectionFactoryDefinitionDescriptorProcessor(legacySecurityAvailable)); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_RESOURCE_DEF_XML_ADMINISTERED_OBJECT, new AdministeredObjectDefinitionDescriptorProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_RA_NATIVE, new RaNativeProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_RA_DEPLOYMENT, new ParsedRaDeploymentProcessor(appclient)); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_RA_XML_DEPLOYMENT, new RaXmlDeploymentProcessor()); updateContext.addDeploymentProcessor(ResourceAdaptersExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_JDBC_DRIVER, new DriverProcessor()); } }
8,333
66.209677
193
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/RaDeploymentParsingProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.deployers.ra.processors; import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.Locale; import org.jboss.as.connector.deployers.Util; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.jca.common.api.metadata.spec.Connector; import org.jboss.jca.common.metadata.spec.RaParser; import org.jboss.vfs.VFSUtils; import org.jboss.vfs.VirtualFile; /** * DeploymentUnitProcessor responsible for parsing a standard jca xml descriptor * and attaching the corresponding metadata. It take care also to register this * metadata into IronJacamar's MetadataRepository * * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public class RaDeploymentParsingProcessor implements DeploymentUnitProcessor { /** * Construct a new instance. */ public RaDeploymentParsingProcessor() { } /** * Process a deployment for standard ra deployment files. Will parse the xml * file and attach a configuration discovered during processing. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException * */ @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); final boolean resolveProperties = Util.shouldResolveSpec(deploymentUnit); final VirtualFile file = deploymentRoot.getRoot(); if (file == null || !file.exists()) return; final String deploymentRootName = file.getName().toLowerCase(Locale.ENGLISH); if (!deploymentRootName.endsWith(".rar")) { return; } final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CONNECTOR_DEPLOYMENT_DESCRIPTOR); String prefix = ""; if (deploymentUnit.getParent() != null) { prefix = deploymentUnit.getParent().getName() + "#"; } String deploymentName = prefix + file.getName(); ConnectorXmlDescriptor xmlDescriptor = process(resolveProperties, file, alternateDescriptor, deploymentName); phaseContext.getDeploymentUnit().putAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor); } public static ConnectorXmlDescriptor process(boolean resolveProperties, VirtualFile file, VirtualFile alternateDescriptor, String deploymentName) throws DeploymentUnitProcessingException { // Locate the descriptor final VirtualFile serviceXmlFile; if (alternateDescriptor != null) { serviceXmlFile = alternateDescriptor; } else { serviceXmlFile = file.getChild("/META-INF/ra.xml"); } InputStream xmlStream = null; Connector result = null; try { if (serviceXmlFile != null && serviceXmlFile.exists()) { xmlStream = serviceXmlFile.openStream(); RaParser raParser = new RaParser(); raParser.setSystemPropertiesResolved(resolveProperties); result = raParser.parse(xmlStream); if (result == null) throw ConnectorLogger.ROOT_LOGGER.failedToParseServiceXml(serviceXmlFile); } File root = file.getPhysicalFile(); URL url = root.toURI().toURL(); return new ConnectorXmlDescriptor(result, root, url, deploymentName); } catch (Exception e) { throw ConnectorLogger.ROOT_LOGGER.failedToParseServiceXml(e, serviceXmlFile); } finally { VFSUtils.safeClose(xmlStream); } } }
5,304
40.124031
192
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/RaXmlDependencyProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ra.processors; import org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor; import org.jboss.as.connector.subsystems.resourceadapters.ModifiableResourceAdapter; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemService; import org.jboss.as.connector.util.CopyOnWriteArrayListMultiMap; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.msc.service.ServiceName; public class RaXmlDependencyProcessor implements DeploymentUnitProcessor { /** * Add dependencies for modules required for ra deployments * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if (phaseContext.getDeploymentUnit().getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY) == null) { return; // Skip non ra deployments } CopyOnWriteArrayListMultiMap<String,ServiceName> resourceAdaptersMap = phaseContext.getDeploymentUnit().getAttachment(ResourceAdaptersSubsystemService.ATTACHMENT_KEY).getAdapters(); String deploymentUnitPrefix = ""; if (deploymentUnit.getParent() != null) { deploymentUnitPrefix = deploymentUnit.getParent().getName() + "#"; } final String deploymentUnitName = deploymentUnitPrefix + deploymentUnit.getName(); if (resourceAdaptersMap != null && resourceAdaptersMap.get(deploymentUnitName) != null) { for (ServiceName serviceName : resourceAdaptersMap.get(deploymentUnitName)) { phaseContext.addDeploymentDependency(serviceName, AttachmentKey .create(ModifiableResourceAdapter.class)); } } } }
3,200
46.073529
189
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/ParsedRaDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.deployers.ra.processors; import static org.jboss.as.connector.logging.ConnectorLogger.DEPLOYMENT_CONNECTOR_LOGGER; import java.util.Collections; import java.util.Locale; import java.util.Map; import org.jboss.as.connector.annotations.repository.jandex.JandexAnnotationRepositoryImpl; import org.jboss.as.connector.metadata.deployment.ResourceAdapterDeployment; import org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor; import org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor; import org.jboss.as.connector.services.mdr.AS7MetadataRepository; import org.jboss.as.connector.services.resourceadapters.deployment.ResourceAdapterDeploymentService; import org.jboss.as.connector.services.resourceadapters.deployment.registry.ResourceAdapterDeploymentRegistry; import org.jboss.as.connector.subsystems.jca.Constants; import org.jboss.as.connector.subsystems.jca.JcaSubsystemConfiguration; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.controller.descriptions.OverrideDescriptionProvider; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.as.naming.service.NamingService; import org.jboss.as.server.Services; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentModelUtils; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.annotation.AnnotationIndexUtils; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.dmr.ModelNode; import org.jboss.jandex.Index; import org.jboss.jca.common.annotations.Annotations; import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.metadata.spec.Connector; import org.jboss.jca.common.metadata.merge.Merger; import org.jboss.jca.common.spi.annotations.repository.AnnotationRepository; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.modules.Module; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController.Mode; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * DeploymentUnitProcessor responsible for using IronJacamar metadata and create * service for ResourceAdapter. * * @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author <a href="[email protected]">Jesper Pedersen</a> */ public class ParsedRaDeploymentProcessor implements DeploymentUnitProcessor { private final boolean appclient; public ParsedRaDeploymentProcessor(final boolean appclient) { this.appclient = appclient; } /** * Process a deployment for a Connector. Will install a {@Code * JBossService} for this ResourceAdapter. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException * */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ConnectorXmlDescriptor connectorXmlDescriptor = deploymentUnit.getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY); final ManagementResourceRegistration registration; final ManagementResourceRegistration baseRegistration = deploymentUnit.getAttachment(DeploymentModelUtils.MUTABLE_REGISTRATION_ATTACHMENT); final Resource deploymentResource = deploymentUnit.getAttachment(DeploymentModelUtils.DEPLOYMENT_RESOURCE); final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); if (connectorXmlDescriptor == null) { return; } final ServiceTarget serviceTarget = phaseContext.getServiceTarget(); if (deploymentUnit.getParent() != null) { registration = baseRegistration.getSubModel(PathAddress.pathAddress(PathElement.pathElement("subdeployment"))); } else { registration = baseRegistration; } final IronJacamarXmlDescriptor ironJacamarXmlDescriptor = deploymentUnit .getAttachment(IronJacamarXmlDescriptor.ATTACHMENT_KEY); final Module module = deploymentUnit.getAttachment(Attachments.MODULE); DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: Processing=%s", deploymentUnit); final ClassLoader classLoader = module.getClassLoader(); Map<ResourceRoot, Index> annotationIndexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit); ServiceBuilder builder = process(connectorXmlDescriptor, ironJacamarXmlDescriptor, classLoader, serviceTarget, annotationIndexes, deploymentUnit.getServiceName(),registration, deploymentResource, support, appclient); if (builder != null) { String bootstrapCtx = null; if (ironJacamarXmlDescriptor != null && ironJacamarXmlDescriptor.getIronJacamar() != null && ironJacamarXmlDescriptor.getIronJacamar().getBootstrapContext() != null) bootstrapCtx = ironJacamarXmlDescriptor.getIronJacamar().getBootstrapContext(); if (bootstrapCtx == null) bootstrapCtx = "default"; builder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootstrapCtx)); //Register an empty override model regardless of we're enabled or not - the statistics listener will add the relevant childresources if (registration.isAllowsOverride() && registration.getOverrideModel(deploymentUnit.getName()) == null) { registration.registerOverrideModel(deploymentUnit.getName(), new OverrideDescriptionProvider() { @Override public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) { return Collections.emptyMap(); } @Override public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) { return Collections.emptyMap(); } }); } builder.setInitialMode(Mode.ACTIVE).install(); } } public static ServiceBuilder<ResourceAdapterDeployment> process(final ConnectorXmlDescriptor connectorXmlDescriptor, final IronJacamarXmlDescriptor ironJacamarXmlDescriptor, final ClassLoader classLoader, final ServiceTarget serviceTarget, final Map<ResourceRoot, Index> annotationIndexes, final ServiceName duServiceName, final ManagementResourceRegistration registration, Resource deploymentResource, final CapabilityServiceSupport support, final boolean appclient) throws DeploymentUnitProcessingException { Connector cmd = connectorXmlDescriptor != null ? connectorXmlDescriptor.getConnector() : null; final Activation activation = ironJacamarXmlDescriptor != null ? ironJacamarXmlDescriptor.getIronJacamar() : null; try { // Annotation merging Annotations annotator = new Annotations(); if (annotationIndexes != null && annotationIndexes.size() > 0) { DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: Found %d annotationIndexes", annotationIndexes.size()); for (Index index : annotationIndexes.values()) { // Don't apply any empty indexes, as IronJacamar doesn't like that atm. if (index.getKnownClasses() != null && !index.getKnownClasses().isEmpty()) { AnnotationRepository repository = new JandexAnnotationRepositoryImpl(index, classLoader); cmd = annotator.merge(cmd, repository, classLoader); DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: CMD=%s", cmd); } } } if (annotationIndexes == null || annotationIndexes.size() == 0) DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: Found 0 annotationIndexes"); // FIXME: when the connector is null the Iron Jacamar data is ignored if (cmd != null) { // Validate metadata cmd.validate(); // Merge metadata cmd = (new Merger()).mergeConnectorWithCommonIronJacamar(activation, cmd); } TransactionSupportEnum transactionSupport = TransactionSupportEnum.NoTransaction; if (cmd != null && cmd.getResourceadapter() != null && cmd.getResourceadapter().getOutboundResourceadapter() != null) { transactionSupport = cmd.getResourceadapter().getOutboundResourceadapter().getTransactionSupport(); } if (activation != null && activation.getTransactionSupport() != null) { transactionSupport = activation.getTransactionSupport(); } final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName()); final ResourceAdapterDeploymentService raDeploymentService = new ResourceAdapterDeploymentService(connectorXmlDescriptor, cmd, activation, classLoader, deployerServiceName, duServiceName, registration, deploymentResource); // Create the service ServiceBuilder<ResourceAdapterDeployment> builder = Services.addServerExecutorDependency( serviceTarget.addService(deployerServiceName, raDeploymentService), raDeploymentService.getExecutorServiceInjector()) .addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, raDeploymentService.getMdrInjector()) .addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, raDeploymentService.getRaRepositoryInjector()) .addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, raDeploymentService.getManagementRepositoryInjector()) .addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, raDeploymentService.getRegistryInjector()) .addDependency(support.getCapabilityServiceName(ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME), TransactionIntegration.class, raDeploymentService.getTxIntegrationInjector()) .addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, raDeploymentService.getConfigInjector()); if (!appclient) { builder.addDependency(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, ResourceAdaptersSubsystemService.class, raDeploymentService.getResourceAdaptersSubsystem()); } builder.requires(ConnectorServices.IDLE_REMOVER_SERVICE); builder.requires(ConnectorServices.CONNECTION_VALIDATOR_SERVICE); builder.requires(support.getCapabilityServiceName(NamingService.CAPABILITY_NAME)); if (transactionSupport == null || transactionSupport.equals(TransactionSupportEnum.NoTransaction)) { builder.addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector()); } else { builder.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector()); } builder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(Constants.DEFAULT_NAME)); return builder; } catch (Throwable t) { throw new DeploymentUnitProcessingException(t); } } }
13,657
56.628692
234
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/IronJacamarDeploymentParsingProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.deployers.ra.processors; import java.io.InputStream; import java.util.Locale; import org.jboss.as.connector.deployers.Util; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.metadata.ironjacamar.IronJacamarParser; import org.jboss.vfs.VFSUtils; import org.jboss.vfs.VirtualFile; /** * DeploymentUnitProcessor responsible for parsing an iron-jacamar.xml descriptor * and attaching the corresponding IronJacamar metadata. It take care also to * register this metadata into IronJacamar0s MetadataRepository * * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ public class IronJacamarDeploymentParsingProcessor implements DeploymentUnitProcessor { /** * Construct a new instance. */ public IronJacamarDeploymentParsingProcessor() { } /** * Process a deployment for iron-jacamar.xml files. Will parse the xml file * and attach metadata discovered during processing. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException */ @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); final VirtualFile deploymentRoot = resourceRoot.getRoot(); final boolean resolveProperties = Util.shouldResolveJBoss(deploymentUnit); IronJacamarXmlDescriptor xmlDescriptor = process(deploymentRoot, resolveProperties); if (xmlDescriptor != null) { deploymentUnit.putAttachment(IronJacamarXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor); } } public static IronJacamarXmlDescriptor process(VirtualFile deploymentRoot, boolean resolveProperties) throws DeploymentUnitProcessingException { IronJacamarXmlDescriptor xmlDescriptor = null; if (deploymentRoot == null || !deploymentRoot.exists()) return null; final String deploymentRootName = deploymentRoot.getName().toLowerCase(Locale.ENGLISH); VirtualFile serviceXmlFile = null; if (deploymentRootName.endsWith(".rar")) { serviceXmlFile = deploymentRoot.getChild("/META-INF/ironjacamar.xml"); } if (serviceXmlFile == null || !serviceXmlFile.exists()) return null; InputStream xmlStream = null; Activation result = null; try { xmlStream = serviceXmlFile.openStream(); IronJacamarParser ironJacamarParser = new IronJacamarParser(); ironJacamarParser.setSystemPropertiesResolved(resolveProperties); result = ironJacamarParser.parse(xmlStream); if (result != null) { xmlDescriptor = new IronJacamarXmlDescriptor(result); } else throw ConnectorLogger.ROOT_LOGGER.failedToParseServiceXml(serviceXmlFile); } catch (Exception e) { throw ConnectorLogger.ROOT_LOGGER.failedToParseServiceXml(e, serviceXmlFile); } finally { VFSUtils.safeClose(xmlStream); } return xmlDescriptor; } }
4,831
42.142857
148
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/RarDependencyProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ra.processors; import org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersSubsystemService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.module.ModuleDependency; import org.jboss.as.server.deployment.module.ModuleSpecification; import org.jboss.modules.Module; import org.jboss.modules.ModuleLoader; public class RarDependencyProcessor implements DeploymentUnitProcessor { private static String JMS_ID = "jakarta.jms.api"; private static String IRON_JACAMAR_ID = "org.jboss.ironjacamar.api"; private static String IRON_JACAMAR_IMPL_ID = "org.jboss.ironjacamar.impl"; private static String VALIDATION_ID = "jakarta.validation.api"; private static String HIBERNATE_VALIDATOR_ID = "org.hibernate.validator"; private static String RESOURCE_API_ID = "jakarta.resource.api"; private final boolean appclient; public RarDependencyProcessor(final boolean appclient) { this.appclient = appclient; } /** * Add dependencies for modules required for ra deployments * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException * */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ModuleLoader moduleLoader = Module.getBootModuleLoader(); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, RESOURCE_API_ID, false, false, false, false)); if (phaseContext.getDeploymentUnit().getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY) == null) { return; // Skip non ra deployments } //if a module depends on a rar it also needs a dep on all the rar's "local dependencies" moduleSpecification.setLocalDependenciesTransitive(true); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JMS_ID, false, false, false, false)); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, VALIDATION_ID, false, false, false, false)); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, IRON_JACAMAR_ID, false, false, false, false)); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, IRON_JACAMAR_IMPL_ID, false, true, false, false)); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, HIBERNATE_VALIDATOR_ID, false, false, true, false)); if (! appclient) phaseContext.addDeploymentDependency(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, ResourceAdaptersSubsystemService.ATTACHMENT_KEY); } }
4,319
51.048193
152
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/RaXmlDeploymentProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.deployers.ra.processors; import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER; import static org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT; import org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor; import org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService; import org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.connector.util.RaServicesFactory; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentModelUtils; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.modules.Module; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceController.Mode; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * DeploymentUnitProcessor responsible for using IronJacamar metadata and create * service for ResourceAdapter. * * @author <a href="mailto:[email protected]">Stefano * Maestri</a> * @author <a href="[email protected]">Jesper Pedersen</a> */ public class RaXmlDeploymentProcessor implements DeploymentUnitProcessor { public RaXmlDeploymentProcessor() { } /** * Process a deployment for a Connector. Will install a {@Code * JBossService} for this ResourceAdapter. * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ManagementResourceRegistration baseRegistration = deploymentUnit.getAttachment(DeploymentModelUtils.MUTABLE_REGISTRATION_ATTACHMENT); final ManagementResourceRegistration registration; final Resource deploymentResource = deploymentUnit.getAttachment(DeploymentModelUtils.DEPLOYMENT_RESOURCE); final ConnectorXmlDescriptor connectorXmlDescriptor = deploymentUnit.getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY); final CapabilityServiceSupport support = deploymentUnit.getAttachment(CAPABILITY_SERVICE_SUPPORT); if (connectorXmlDescriptor == null) { return; // Skip non ra deployments } if (deploymentUnit.getParent() != null) { registration = baseRegistration.getSubModel(PathAddress.pathAddress(PathElement.pathElement("subdeployment"))); } else { registration = baseRegistration; } ResourceAdaptersService.ModifiableResourceAdaptors raxmls = null; final ServiceController<?> raService = phaseContext.getServiceRegistry().getService( ConnectorServices.RESOURCEADAPTERS_SERVICE); if (raService != null) raxmls = ((ResourceAdaptersService.ModifiableResourceAdaptors) raService.getValue()); ROOT_LOGGER.tracef("processing Raxml"); Module module = deploymentUnit.getAttachment(Attachments.MODULE); try { final ServiceTarget serviceTarget = phaseContext.getServiceTarget(); String deploymentUnitPrefix = ""; if (deploymentUnit.getParent() != null) { deploymentUnitPrefix = deploymentUnit.getParent().getName() + "#"; } final String deploymentUnitName = deploymentUnitPrefix + deploymentUnit.getName(); if (raxmls != null) { for (Activation raxml : raxmls.getActivations()) { String rarName = raxml.getArchive(); if (deploymentUnitName.equals(rarName)) { RaServicesFactory.createDeploymentService(registration, connectorXmlDescriptor, module, serviceTarget, deploymentUnitName, deploymentUnit.getServiceName(), deploymentUnitName, raxml, deploymentResource, phaseContext.getServiceRegistry(), support); } } } //create service pointing to rar for other future activations ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(deploymentUnitName); InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, deploymentUnitName, deploymentUnitName, deploymentUnit.getServiceName(), registration, serviceTarget, deploymentResource); ServiceBuilder builder = serviceTarget .addService(serviceName, service); builder.setInitialMode(Mode.ACTIVE).install(); } catch (Throwable t) { throw new DeploymentUnitProcessingException(t); } } }
6,491
48.181818
271
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/RaNativeProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.deployers.ra.processors; import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER; import java.io.File; import java.util.List; import java.util.Locale; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.vfs.VirtualFile; import org.jboss.vfs.VirtualFileFilter; /** * Load native libraries for .rar deployments * * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ public class RaNativeProcessor implements DeploymentUnitProcessor { /** * Construct a new instance. */ public RaNativeProcessor() { } /** * Process a deployment for standard ra deployment files. Will parse the xml * file and attach a configuration discovered during processing. * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException */ @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final VirtualFile deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot(); process(deploymentRoot); } public static void process(VirtualFile deploymentRoot) throws DeploymentUnitProcessingException { if (deploymentRoot == null || !deploymentRoot.exists()) return; final String deploymentRootName = deploymentRoot.getName().toLowerCase(Locale.ENGLISH); if (!deploymentRootName.endsWith(".rar")) { return; } try { List<VirtualFile> libs = deploymentRoot.getChildrenRecursively(new LibraryFilter()); if (libs != null && !libs.isEmpty()) { for (VirtualFile vf : libs) { String fileName = vf.getName().toLowerCase(Locale.ENGLISH); ROOT_LOGGER.tracef("Processing library: %s", fileName); try { File f = vf.getPhysicalFile(); System.load(f.getAbsolutePath()); ROOT_LOGGER.debugf("Loaded library: %s", f.getAbsolutePath()); } catch (Throwable t) { ROOT_LOGGER.debugf("Unable to load library: %s", fileName); } } } } catch (Exception e) { throw ConnectorLogger.ROOT_LOGGER.failedToLoadNativeLibraries(e); } } private static class LibraryFilter implements VirtualFileFilter { public boolean accepts(VirtualFile vf) { if (vf == null) return false; if (vf.isFile()) { String fileName = vf.getName().toLowerCase(Locale.ENGLISH); if (fileName.endsWith(".a") || fileName.endsWith(".so") || fileName.endsWith(".dll")) { return true; } } return false; } } }
4,221
35.713043
129
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/CachedConnectionManagerSetupProcessor.java
/* * 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.connector.deployers.ra.processors; import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Set; import jakarta.resource.ResourceException; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.ee.component.Attachments; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.SetupAction; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * Setup processor that adds sets operations for the cached connection manager. These operations are run around * incoming requests. * * @author Stuart Douglas */ public class CachedConnectionManagerSetupProcessor implements DeploymentUnitProcessor { private static final ServiceName SERVICE_NAME = ServiceName.of("jca", "cachedConnectionManagerSetupProcessor"); private static final AttachmentKey<SetupAction> ATTACHMENT_KEY = AttachmentKey.create(SetupAction.class); @Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ServiceName serviceName = deploymentUnit.getServiceName().append(SERVICE_NAME); final CachedConnectionManagerSetupAction action = new CachedConnectionManagerSetupAction(serviceName); phaseContext.getServiceTarget().addService(serviceName, action) .addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, action.cachedConnectionManager) .addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, action.noTxCcmValue) .install(); deploymentUnit.addToAttachmentList(Attachments.WEB_SETUP_ACTIONS, action); deploymentUnit.addToAttachmentList(Attachments.OTHER_EE_SETUP_ACTIONS, action); deploymentUnit.putAttachment(ATTACHMENT_KEY, action); } @Override public void undeploy(final DeploymentUnit deploymentUnit) { SetupAction action = deploymentUnit.removeAttachment(ATTACHMENT_KEY); deploymentUnit.getAttachmentList(Attachments.OTHER_EE_SETUP_ACTIONS).remove(action); deploymentUnit.getAttachmentList(Attachments.WEB_SETUP_ACTIONS).remove(action); } private static class CachedConnectionManagerSetupAction implements SetupAction, Service<Void> { private final InjectedValue<CachedConnectionManager> cachedConnectionManager = new InjectedValue<CachedConnectionManager>(); private final InjectedValue<CachedConnectionManager> noTxCcmValue = new InjectedValue<CachedConnectionManager>(); private final ServiceName serviceName; private static final Set<?> unsharable = new HashSet<Object>(); private CachedConnectionManagerSetupAction(final ServiceName serviceName) { this.serviceName = serviceName; } @Override public void setup(final Map<String, Object> properties) { try { final CachedConnectionManager noTxCcm = noTxCcmValue.getOptionalValue(); if (noTxCcm != null) { noTxCcm.pushMetaAwareObject(this, unsharable); } final CachedConnectionManager connectionManager = cachedConnectionManager.getOptionalValue(); if (connectionManager != null) { connectionManager.pushMetaAwareObject(this, unsharable); } } catch (ResourceException e) { throw new RuntimeException(e); } } @Override public void teardown(final Map<String, Object> properties) { try { final CachedConnectionManager connectionManager = cachedConnectionManager.getOptionalValue(); if (connectionManager != null) { connectionManager.popMetaAwareObject(unsharable); } final CachedConnectionManager noTxCcm = noTxCcmValue.getOptionalValue(); if (noTxCcm != null) { noTxCcm.popMetaAwareObject(unsharable); } } catch (ResourceException e) { throw new RuntimeException(e); } } @Override public int priority() { return 0; } @Override public Set<ServiceName> dependencies() { return Collections.singleton(serviceName); } @Override public void start(final StartContext context) throws StartException { } @Override public void stop(final StopContext context) { } @Override public Void getValue() throws IllegalStateException, IllegalArgumentException { return null; } } }
6,372
40.653595
132
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/ra/processors/RaStructureProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.ra.processors; import java.io.Closeable; import java.io.IOException; import java.util.List; import java.util.Locale; import java.util.Map; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.MountedDeploymentOverlay; import org.jboss.as.server.deployment.module.ModuleRootMarker; import org.jboss.as.server.deployment.module.ModuleSpecification; import org.jboss.as.server.deployment.module.MountHandle; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.as.server.deployment.module.TempFileProviderService; import org.jboss.vfs.VFS; import org.jboss.vfs.VFSUtils; import org.jboss.vfs.VirtualFile; import org.jboss.vfs.VisitorAttributes; import org.jboss.vfs.util.SuffixMatchFilter; /** * Deployment processor used to determine the structure of RAR deployments. * * @author John Bailey */ public class RaStructureProcessor implements DeploymentUnitProcessor { private static final String RAR_EXTENSION = ".rar"; private static final String JAR_EXTENSION = ".jar"; private static final SuffixMatchFilter CHILD_ARCHIVE_FILTER = new SuffixMatchFilter(JAR_EXTENSION, VisitorAttributes.RECURSE_LEAVES_ONLY); private static Closeable NO_OP_CLOSEABLE = new Closeable() { public void close() throws IOException { // NO-OP } }; public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); if(resourceRoot == null) { return; } final VirtualFile deploymentRoot = resourceRoot.getRoot(); if (deploymentRoot == null || !deploymentRoot.exists()) { return; } final String deploymentRootName = deploymentRoot.getName().toLowerCase(Locale.ENGLISH); if (!deploymentRootName.endsWith(RAR_EXTENSION)) { return; } final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); moduleSpecification.setPublicModule(true); //this violates the spec, but everyone expects it to work ModuleRootMarker.mark(resourceRoot, true); Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS); try { final List<VirtualFile> childArchives = deploymentRoot.getChildren(CHILD_ARCHIVE_FILTER); for (final VirtualFile child : childArchives) { String relativeName = child.getPathNameRelativeTo(deploymentRoot); MountedDeploymentOverlay overlay = overlays.get(relativeName); Closeable closable = NO_OP_CLOSEABLE; if(overlay != null) { overlay.remountAsZip(false); } else if(child.isFile()) { closable = VFS.mountZip(child, child, TempFileProviderService.provider()); } final MountHandle mountHandle = MountHandle.create(closable); final ResourceRoot childResource = new ResourceRoot(child, mountHandle); ModuleRootMarker.mark(childResource); deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource); resourceRoot.addToAttachmentList(Attachments.INDEX_IGNORE_PATHS, child.getPathNameRelativeTo(deploymentRoot)); } } catch (IOException e) { throw ConnectorLogger.ROOT_LOGGER.failedToProcessRaChild(e, deploymentRoot); } } public void undeploy(DeploymentUnit context) { final List<ResourceRoot> childRoots = context.removeAttachment(Attachments.RESOURCE_ROOTS); if(childRoots != null) { for(ResourceRoot childRoot : childRoots) { VFSUtils.safeClose(childRoot.getMountHandle()); } } } }
5,402
42.926829
142
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/datasource/DefaultDataSourceBindingProcessor.java
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.connector.deployers.datasource; import org.jboss.as.ee.component.EEModuleDescription; import org.jboss.as.ee.component.deployers.AbstractPlatformBindingProcessor; import org.jboss.as.server.deployment.DeploymentUnit; /** * Processor responsible for binding the default datasource to the naming context of EE modules/components. * * @author Eduardo Martins */ public class DefaultDataSourceBindingProcessor extends AbstractPlatformBindingProcessor { public static final String DEFAULT_DATASOURCE_JNDI_NAME = "DefaultDataSource"; public static final String COMP_DEFAULT_DATASOURCE_JNDI_NAME = "java:comp/"+DEFAULT_DATASOURCE_JNDI_NAME; @Override protected void addBindings(DeploymentUnit deploymentUnit, EEModuleDescription moduleDescription) { final String defaultDataSource = moduleDescription.getDefaultResourceJndiNames().getDataSource(); if(defaultDataSource != null) { addBinding(defaultDataSource, DEFAULT_DATASOURCE_JNDI_NAME, deploymentUnit, moduleDescription); } } }
2,076
44.152174
109
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/datasource/DataSourceDefinitionAnnotationProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.connector.deployers.datasource; import org.jboss.as.ee.resource.definition.ResourceDefinitionAnnotationProcessor; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.DotName; import org.jboss.metadata.property.PropertyReplacer; import jakarta.annotation.sql.DataSourceDefinition; import jakarta.annotation.sql.DataSourceDefinitions; /** * @author John Bailey * @author Jason T. Greene * @author Eduardo Martins */ public class DataSourceDefinitionAnnotationProcessor extends ResourceDefinitionAnnotationProcessor { private static final DotName DATASOURCE_DEFINITION = DotName.createSimple(DataSourceDefinition.class.getName()); private static final DotName DATASOURCE_DEFINITIONS = DotName.createSimple(DataSourceDefinitions.class.getName()); @Override protected DotName getAnnotationDotName() { return DATASOURCE_DEFINITION; } @Override protected DotName getAnnotationCollectionDotName() { return DATASOURCE_DEFINITIONS; } @Override protected ResourceDefinitionInjectionSource processAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException { final DataSourceDefinitionInjectionSource directDataSourceInjectionSource = new DataSourceDefinitionInjectionSource(AnnotationElement.asRequiredString(annotationInstance, AnnotationElement.NAME)); directDataSourceInjectionSource.setClassName(AnnotationElement.asRequiredString(annotationInstance, "className")); directDataSourceInjectionSource.setDatabaseName(AnnotationElement.asOptionalString(annotationInstance, DataSourceDefinitionInjectionSource.DATABASE_NAME_PROP)); directDataSourceInjectionSource.setDescription(AnnotationElement.asOptionalString(annotationInstance, DataSourceDefinitionInjectionSource.DESCRIPTION_PROP)); directDataSourceInjectionSource.setInitialPoolSize(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.INITIAL_POOL_SIZE_PROP)); directDataSourceInjectionSource.setIsolationLevel(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.ISOLATION_LEVEL_PROP)); directDataSourceInjectionSource.setLoginTimeout(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.LOGIN_TIMEOUT_PROP)); directDataSourceInjectionSource.setMaxIdleTime(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.MAX_IDLE_TIME_PROP)); directDataSourceInjectionSource.setMaxStatements(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.MAX_STATEMENTS_PROP)); directDataSourceInjectionSource.setMaxPoolSize(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.MAX_POOL_SIZE_PROP)); directDataSourceInjectionSource.setMinPoolSize(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.MIN_POOL_SIZE_PROP)); directDataSourceInjectionSource.setInitialPoolSize(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.INITIAL_POOL_SIZE_PROP)); directDataSourceInjectionSource.setPassword(AnnotationElement.asOptionalString(annotationInstance, DataSourceDefinitionInjectionSource.PASSWORD_PROP)); directDataSourceInjectionSource.setPortNumber(AnnotationElement.asOptionalInt(annotationInstance, DataSourceDefinitionInjectionSource.PORT_NUMBER_PROP)); directDataSourceInjectionSource.addProperties(AnnotationElement.asOptionalStringArray(annotationInstance, AnnotationElement.PROPERTIES)); directDataSourceInjectionSource.setServerName(AnnotationElement.asOptionalString(annotationInstance, DataSourceDefinitionInjectionSource.SERVER_NAME_PROP)); directDataSourceInjectionSource.setTransactional(AnnotationElement.asOptionalBoolean(annotationInstance, DataSourceDefinitionInjectionSource.TRANSACTIONAL_PROP)); directDataSourceInjectionSource.setUrl(AnnotationElement.asOptionalString(annotationInstance, DataSourceDefinitionInjectionSource.URL_PROP)); directDataSourceInjectionSource.setUser(AnnotationElement.asOptionalString(annotationInstance, DataSourceDefinitionInjectionSource.USER_PROP)); return directDataSourceInjectionSource; } }
5,563
68.55
204
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/datasource/DefaultDataSourceResourceReferenceProcessor.java
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt 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.connector.deployers.datasource; import org.jboss.as.ee.component.Attachments; import org.jboss.as.ee.component.EEModuleDescription; import org.jboss.as.ee.component.InjectionSource; import org.jboss.as.ee.component.LookupInjectionSource; import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessor; import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessorRegistry; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import javax.sql.DataSource; /** * Processor responsible for adding an EEResourceReferenceProcessor, which defaults @resource datasource injection to java:comp/DefaultDataSource. * * @author Eduardo Martins */ public class DefaultDataSourceResourceReferenceProcessor implements DeploymentUnitProcessor { private static final DatasourceResourceReferenceProcessor RESOURCE_REFERENCE_PROCESSOR = new DatasourceResourceReferenceProcessor(); @Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if(deploymentUnit.getParent() == null) { final EEResourceReferenceProcessorRegistry eeResourceReferenceProcessorRegistry = deploymentUnit.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY); if(eeResourceReferenceProcessorRegistry != null) { final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); if (eeModuleDescription != null && eeModuleDescription.getDefaultResourceJndiNames().getDataSource() != null) { eeResourceReferenceProcessorRegistry.registerResourceReferenceProcessor(RESOURCE_REFERENCE_PROCESSOR); } } } } private static class DatasourceResourceReferenceProcessor implements EEResourceReferenceProcessor { private static final String TYPE = DataSource.class.getName(); private static final InjectionSource INJECTION_SOURCE = new LookupInjectionSource(DefaultDataSourceBindingProcessor.COMP_DEFAULT_DATASOURCE_JNDI_NAME); @Override public String getResourceReferenceType() { return TYPE; } @Override public InjectionSource getResourceReferenceBindingSource() throws DeploymentUnitProcessingException { return INJECTION_SOURCE; } } }
3,670
46.675325
174
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/datasource/DataSourceDefinitionInjectionSource.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.datasource; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER; import static org.jboss.as.connector.subsystems.jca.Constants.DEFAULT_NAME; import java.lang.reflect.Method; import java.sql.Connection; import java.util.Iterator; import java.util.Map; import javax.sql.XADataSource; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.ds.DsSecurityImpl; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService; import org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService; import org.jboss.as.connector.subsystems.datasources.LocalDataSourceService; import org.jboss.as.connector.subsystems.datasources.ModifiableDataSource; import org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource; import org.jboss.as.connector.subsystems.datasources.XaDataSourceService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.ee.component.Attachments; import org.jboss.as.ee.component.EEModuleDescription; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.naming.ManagedReferenceFactory; import org.jboss.as.naming.ServiceBasedNamingStore; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.service.BinderService; import org.jboss.as.naming.service.NamingService; import org.jboss.as.server.Services; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.reflect.ClassReflectionIndexUtil; import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex; import org.jboss.invocation.proxy.MethodIdentifier; import org.jboss.jca.common.api.metadata.Defaults; import org.jboss.jca.common.api.metadata.ds.TransactionIsolation; import org.jboss.jca.common.metadata.ds.DsPoolImpl; import org.jboss.jca.common.metadata.ds.DsXaPoolImpl; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.modules.Module; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * A binding description for DataSourceDefinition annotations. * <p/> * The referenced datasource must be directly visible to the * component declaring the annotation. * * @author Jason T. Greene */ public class DataSourceDefinitionInjectionSource extends ResourceDefinitionInjectionSource { public static final String USER_PROP = "user"; public static final String URL_PROP = "url"; public static final String UPPERCASE_URL_PROP = "URL"; public static final String TRANSACTIONAL_PROP = "transactional"; public static final String SERVER_NAME_PROP = "serverName"; public static final String PORT_NUMBER_PROP = "portNumber"; public static final String PASSWORD_PROP = "password"; public static final String MIN_POOL_SIZE_PROP = "minPoolSize"; public static final String MAX_STATEMENTS_PROP = "maxStatements"; public static final String MAX_IDLE_TIME_PROP = "maxIdleTime"; public static final String LOGIN_TIMEOUT_PROP = "loginTimeout"; public static final String ISOLATION_LEVEL_PROP = "isolationLevel"; public static final String INITIAL_POOL_SIZE_PROP = "initialPoolSize"; public static final String DESCRIPTION_PROP = "description"; public static final String DATABASE_NAME_PROP = "databaseName"; public static final String MAX_POOL_SIZE_PROP = "maxPoolSize"; private String className; private String description; private String url; private String databaseName; private String serverName; private int portNumber = -1; private int loginTimeout = -1; private int isolationLevel = -1; private boolean transactional = true; private int initialPoolSize = -1; private int maxIdleTime = -1; private int maxPoolSize = -1; private int maxStatements = -1; private int minPoolSize = -1; private String user; private String password; public DataSourceDefinitionInjectionSource(final String jndiName) { super(jndiName); } public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final String poolName = uniqueName(context, jndiName); final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName); final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); final CapabilityServiceSupport support = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT); try { final Class<?> clazz = module.getClassLoader().loadClass(className); clearUnknownProperties(reflectionIndex, clazz, properties); populateProperties(reflectionIndex, clazz, properties); DsSecurityImpl dsSecurity = new DsSecurityImpl(user, password, null, null, null); if (XADataSource.class.isAssignableFrom(clazz) && transactional) { final DsXaPoolImpl xaPool = new DsXaPoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize), initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize), maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize), Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, Defaults.IS_SAME_RM_OVERRIDE, Defaults.INTERLEAVING, Defaults.PAD_XID, Defaults.WRAP_XA_RESOURCE, Defaults.NO_TX_SEPARATE_POOL, Boolean.FALSE, null, Defaults.FAIR, null); final ModifiableXaDataSource dataSource = new ModifiableXaDataSource(transactionIsolation(), null, dsSecurity, null, null, null, null, null, null, poolName, true, jndiName, false, false, Defaults.CONNECTABLE, Defaults.TRACKING, Defaults.MCP, Defaults.ENLISTMENT_TRACE, properties, className, null, null, xaPool, null); final XaDataSourceService xds = new XaDataSourceService(bindInfo.getBinderServiceName().getCanonicalName(), bindInfo, module.getClassLoader()); xds.getDataSourceConfigInjector().inject(dataSource); startDataSource(xds, bindInfo, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector, support); } else { final DsPoolImpl commonPool = new DsPoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize), initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize), maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize), Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, Boolean.FALSE, null, Defaults.FAIR, null); final ModifiableDataSource dataSource = new ModifiableDataSource(url, null, className, null, transactionIsolation(), properties, null, dsSecurity, null, null, null, null, null, false, poolName, true, jndiName, Defaults.SPY, Defaults.USE_CCM, transactional, Defaults.CONNECTABLE, Defaults.TRACKING, Defaults.MCP, Defaults.ENLISTMENT_TRACE, commonPool); final LocalDataSourceService ds = new LocalDataSourceService(bindInfo.getBinderServiceName().getCanonicalName(), bindInfo, module.getClassLoader()); ds.getDataSourceConfigInjector().inject(dataSource); startDataSource(ds, bindInfo, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector, support); } } catch (Exception e) { throw new DeploymentUnitProcessingException(e); } } private void clearUnknownProperties(final DeploymentReflectionIndex reflectionIndex, final Class<?> dataSourceClass, final Map<String, String> props) { final Iterator<Map.Entry<String, String>> it = props.entrySet().iterator(); while (it.hasNext()) { final Map.Entry<String, String> entry = it.next(); String value = entry.getKey(); if (value == null || "".equals(value)) { it.remove(); } else { StringBuilder builder = new StringBuilder("set").append(entry.getKey()); builder.setCharAt(3, Character.toUpperCase(entry.getKey().charAt(0))); final String methodName = builder.toString(); final Class<?> paramType = value.getClass(); final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, paramType); final Method setterMethod = ClassReflectionIndexUtil.findMethod(reflectionIndex, dataSourceClass, methodIdentifier); if (setterMethod == null) { it.remove(); ConnectorLogger.DS_DEPLOYER_LOGGER.methodNotFoundOnDataSource(methodName, dataSourceClass); } } } } private String uniqueName(ResolutionContext context, final String jndiName) { StringBuilder name = new StringBuilder(); name.append(context.getApplicationName() + "_"); name.append(context.getModuleName() + "_"); if (context.getComponentName() != null) { name.append(context.getComponentName() + "_"); } name.append(jndiName); return name.toString(); } private void startDataSource(final AbstractDataSourceService dataSourceService, final ContextNames.BindInfo bindInfo, final EEModuleDescription moduleDescription, final ResolutionContext context, final ServiceTarget serviceTarget, final ServiceBuilder valueSourceServiceBuilder, final Injector<ManagedReferenceFactory> injector, final CapabilityServiceSupport support) { final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo); final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency( serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector()) .addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector()) .addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()) .addDependency(support.getCapabilityServiceName(ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME), TransactionIntegration.class, dataSourceService.getTransactionIntegrationInjector()) .addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, dataSourceService.getManagementRepositoryInjector()) .addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector()) .addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, dataSourceService.getDriverRegistryInjector()); dataSourceServiceBuilder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME)); dataSourceServiceBuilder.requires(support.getCapabilityServiceName(NamingService.CAPABILITY_NAME)); // We don't need to inject legacy security subsystem services. They are only used with a configured legacy // security domain, and the annotation does not support configuring that // if(securityEnabled) { // dataSourceServiceBuilder.addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class, // dataSourceService.getServerSecurityManager()); // dataSourceServiceBuilder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, // dataSourceService.getSubjectFactoryInjector()); // } final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService(); final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE .append(bindInfo.getBinderServiceName()); final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, javax.sql.DataSource.class, referenceFactoryService.getDataSourceInjector()); final BinderService binderService = new BinderService(bindInfo.getBindName(), this); final ServiceBuilder<?> binderBuilder = serviceTarget .addService(bindInfo.getBinderServiceName(), binderService) .addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()) .addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new LifecycleListener() { private volatile boolean bound; public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) { switch (event) { case UP: { if (isTransactional()) { SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName); } else { SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName); } bound = true; break; } case DOWN: { if (bound) { if (isTransactional()) { SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName); } else { SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName); } } break; } case REMOVED: { SUBSYSTEM_DATASOURCES_LOGGER.debugf("Removed JDBC Data-source [%s]", jndiName); break; } } } }); dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install(); referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install(); binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install(); valueSourceServiceBuilder.addDependency(bindInfo.getBinderServiceName(), ManagedReferenceFactory.class, injector); } private TransactionIsolation transactionIsolation() { switch (isolationLevel) { case Connection.TRANSACTION_NONE: return TransactionIsolation.TRANSACTION_NONE; case Connection.TRANSACTION_READ_COMMITTED: return TransactionIsolation.TRANSACTION_READ_COMMITTED; case Connection.TRANSACTION_READ_UNCOMMITTED: return TransactionIsolation.TRANSACTION_READ_UNCOMMITTED; case Connection.TRANSACTION_REPEATABLE_READ: return TransactionIsolation.TRANSACTION_REPEATABLE_READ; case Connection.TRANSACTION_SERIALIZABLE: return TransactionIsolation.TRANSACTION_SERIALIZABLE; default: return TransactionIsolation.TRANSACTION_READ_COMMITTED; } } private void populateProperties(final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> dataSourceClass, final Map<String, String> properties) { setProperty(deploymentReflectionIndex, dataSourceClass, properties, DESCRIPTION_PROP, description); setProperty(deploymentReflectionIndex, dataSourceClass, properties, URL_PROP, url); setProperty(deploymentReflectionIndex, dataSourceClass, properties, UPPERCASE_URL_PROP, url); setProperty(deploymentReflectionIndex, dataSourceClass, properties, DATABASE_NAME_PROP, databaseName); setProperty(deploymentReflectionIndex, dataSourceClass, properties, SERVER_NAME_PROP, serverName); setProperty(deploymentReflectionIndex, dataSourceClass, properties, PORT_NUMBER_PROP, Integer.valueOf(portNumber)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, LOGIN_TIMEOUT_PROP, Integer.valueOf(loginTimeout)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, ISOLATION_LEVEL_PROP, Integer.valueOf(isolationLevel)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, TRANSACTIONAL_PROP, Boolean.valueOf(transactional)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, INITIAL_POOL_SIZE_PROP, Integer.valueOf(initialPoolSize)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, MAX_IDLE_TIME_PROP, Integer.valueOf(maxIdleTime)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, MAX_POOL_SIZE_PROP, Integer.valueOf(maxPoolSize)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, MAX_STATEMENTS_PROP, Integer.valueOf(maxStatements)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, MIN_POOL_SIZE_PROP, Integer.valueOf(minPoolSize)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, INITIAL_POOL_SIZE_PROP, Integer.valueOf(minPoolSize)); setProperty(deploymentReflectionIndex, dataSourceClass, properties, USER_PROP, user); setProperty(deploymentReflectionIndex, dataSourceClass, properties, PASSWORD_PROP, password); } private void setProperty(final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> dataSourceClass, final Map<String, String> properties, final String name, final Object value) { // Ignore defaulted values if (value == null || "".equals(value)) return; if (value instanceof Integer && ((Integer) value).intValue() == -1) return; StringBuilder builder = new StringBuilder("set").append(name); builder.setCharAt(3, Character.toUpperCase(name.charAt(0))); final String methodName = builder.toString(); final Class<?> paramType = value.getClass(); MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, paramType); Method setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier); if (setterMethod != null) { properties.put(name, value.toString()); } else if (paramType == Integer.class) { //if this is an Integer also look for int setters (WFLY-1364) methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, int.class); setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier); if (setterMethod != null) { properties.put(name, value.toString()); } } else if (paramType == Boolean.class) { methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, boolean.class); setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier); if (setterMethod != null) { properties.put(name, value.toString()); } } } public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getDatabaseName() { return databaseName; } public void setDatabaseName(String databaseName) { this.databaseName = databaseName; } public String getServerName() { return serverName; } public void setServerName(String serverName) { this.serverName = serverName; } public int getPortNumber() { return portNumber; } public void setPortNumber(int portNumber) { this.portNumber = portNumber; } public int getLoginTimeout() { return loginTimeout; } public void setLoginTimeout(int loginTimeout) { this.loginTimeout = loginTimeout; } public int getIsolationLevel() { return isolationLevel; } public void setIsolationLevel(int isolationLevel) { this.isolationLevel = isolationLevel; } public boolean isTransactional() { return transactional; } public void setTransactional(boolean transactional) { this.transactional = transactional; } public int getInitialPoolSize() { return initialPoolSize; } public void setInitialPoolSize(int initialPoolSize) { this.initialPoolSize = initialPoolSize; } public int getMaxIdleTime() { return maxIdleTime; } public void setMaxIdleTime(int maxIdleTime) { this.maxIdleTime = maxIdleTime; } public int getMaxPoolSize() { return maxPoolSize; } public void setMaxPoolSize(int maxPoolSize) { this.maxPoolSize = maxPoolSize; } public int getMaxStatements() { return maxStatements; } public void setMaxStatements(int maxStatements) { this.maxStatements = maxStatements; } public int getMinPoolSize() { return minPoolSize; } public void setMinPoolSize(int minPoolSize) { this.minPoolSize = minPoolSize; } public String getUser() { return user; } public void setUser(String user) { this.user = user; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; DataSourceDefinitionInjectionSource that = (DataSourceDefinitionInjectionSource) o; if (initialPoolSize != that.initialPoolSize) return false; if (isolationLevel != that.isolationLevel) return false; if (loginTimeout != that.loginTimeout) return false; if (maxIdleTime != that.maxIdleTime) return false; if (maxPoolSize != that.maxPoolSize) return false; if (maxStatements != that.maxStatements) return false; if (minPoolSize != that.minPoolSize) return false; if (portNumber != that.portNumber) return false; if (transactional != that.transactional) return false; if (className != null ? !className.equals(that.className) : that.className != null) return false; if (databaseName != null ? !databaseName.equals(that.databaseName) : that.databaseName != null) return false; if (description != null ? !description.equals(that.description) : that.description != null) return false; if (password != null ? !password.equals(that.password) : that.password != null) return false; if (serverName != null ? !serverName.equals(that.serverName) : that.serverName != null) return false; if (url != null ? !url.equals(that.url) : that.url != null) return false; if (user != null ? !user.equals(that.user) : that.user != null) return false; return true; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (className != null ? className.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (url != null ? url.hashCode() : 0); result = 31 * result + (databaseName != null ? databaseName.hashCode() : 0); result = 31 * result + (serverName != null ? serverName.hashCode() : 0); result = 31 * result + portNumber; result = 31 * result + loginTimeout; result = 31 * result + isolationLevel; result = 31 * result + (transactional ? 1 : 0); result = 31 * result + initialPoolSize; result = 31 * result + maxIdleTime; result = 31 * result + maxPoolSize; result = 31 * result + maxStatements; result = 31 * result + minPoolSize; result = 31 * result + (user != null ? user.hashCode() : 0); result = 31 * result + (password != null ? password.hashCode() : 0); return result; } }
28,287
48.28223
241
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/deployers/datasource/DataSourceDefinitionDescriptorProcessor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.deployers.datasource; import org.jboss.as.ee.resource.definition.ResourceDefinitionDescriptorProcessor; import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.metadata.javaee.spec.DataSourceMetaData; import org.jboss.metadata.javaee.spec.DataSourcesMetaData; import org.jboss.metadata.javaee.spec.RemoteEnvironment; import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER; /** * Deployment processor responsible for processing data-source deployment descriptor elements * * @author Stuart Douglas * @author Eduardo Martins */ public class DataSourceDefinitionDescriptorProcessor extends ResourceDefinitionDescriptorProcessor { @Override protected void processEnvironment(RemoteEnvironment environment, ResourceDefinitionInjectionSources injectionSources) throws DeploymentUnitProcessingException { final DataSourcesMetaData metaDatas = environment.getDataSources(); if (metaDatas != null) { for(DataSourceMetaData metaData : metaDatas) { injectionSources.addResourceDefinitionInjectionSource(getResourceDefinitionInjectionSource(metaData)); } } } private ResourceDefinitionInjectionSource getResourceDefinitionInjectionSource(final DataSourceMetaData metaData) { final String name = metaData.getName(); if (name == null || name.isEmpty()) { throw ROOT_LOGGER.elementAttributeMissing("<data-source>", "name"); } final DataSourceDefinitionInjectionSource resourceDefinitionInjectionSource = new DataSourceDefinitionInjectionSource(name); final String className = metaData.getClassName(); if (className == null || className.equals(Object.class.getName())) { throw ROOT_LOGGER.elementAttributeMissing("<data-source>", "className"); } resourceDefinitionInjectionSource.setClassName(className); resourceDefinitionInjectionSource.setDatabaseName(metaData.getDatabaseName()); if (metaData.getDescriptions() != null) { resourceDefinitionInjectionSource.setDescription(metaData.getDescriptions().toString()); } resourceDefinitionInjectionSource.setInitialPoolSize(metaData.getInitialPoolSize()); if (metaData.getIsolationLevel() != null) { resourceDefinitionInjectionSource.setIsolationLevel(metaData.getIsolationLevel().ordinal()); } resourceDefinitionInjectionSource.setLoginTimeout(metaData.getLoginTimeout()); resourceDefinitionInjectionSource.setMaxIdleTime(metaData.getMaxIdleTime()); resourceDefinitionInjectionSource.setMaxStatements(metaData.getMaxStatements()); resourceDefinitionInjectionSource.setMaxPoolSize(metaData.getMaxPoolSize()); resourceDefinitionInjectionSource.setMinPoolSize(metaData.getMinPoolSize()); resourceDefinitionInjectionSource.setInitialPoolSize(metaData.getInitialPoolSize()); resourceDefinitionInjectionSource.setPassword(metaData.getPassword()); resourceDefinitionInjectionSource.setPortNumber(metaData.getPortNumber()); resourceDefinitionInjectionSource.addProperties(metaData.getProperties()); resourceDefinitionInjectionSource.setServerName(metaData.getServerName()); resourceDefinitionInjectionSource.setTransactional(metaData.getTransactional()); resourceDefinitionInjectionSource.setUrl(metaData.getUrl()); resourceDefinitionInjectionSource.setUser(metaData.getUser()); return resourceDefinitionInjectionSource; } }
4,686
52.261364
164
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/common/pool/Constants.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.common.pool; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.util.Objects; import java.util.stream.Stream; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.AttributeMarshaller; import org.jboss.as.controller.PropertiesAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.operations.validation.EnumValidator; import org.jboss.as.controller.operations.validation.IntRangeValidator; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.jca.common.api.metadata.Defaults; import org.jboss.jca.common.api.metadata.common.FlushStrategy; import org.jboss.jca.common.api.metadata.common.Pool; import org.jboss.jca.common.api.metadata.ds.TimeOut; import org.jboss.jca.common.api.metadata.ds.Validation; /** * @author @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ public class Constants { private static final String MIN_POOL_SIZE_NAME = "min-pool-size"; private static final String INITIAL_POOL_SIZE_NAME = "initial-pool-size"; private static final String MAX_POOL_SIZE_NAME = "max-pool-size"; private static final String POOL_PREFILL_NAME = "pool-prefill"; private static final String POOL_FAIR_NAME = "pool-fair"; private static final String POOL_USE_STRICT_MIN_NAME = "pool-use-strict-min"; private static final String BACKGROUNDVALIDATIONMILLIS_NAME = "background-validation-millis"; private static final String BACKGROUNDVALIDATION_NAME = "background-validation"; private static final String USE_FAST_FAIL_NAME = "use-fast-fail"; private static final String VALIDATEONMATCH_NAME = "validate-on-match"; private static final String BLOCKING_TIMEOUT_WAIT_MILLIS_NAME = "blocking-timeout-wait-millis"; private static final String IDLETIMEOUTMINUTES_NAME = "idle-timeout-minutes"; private static final String FLUSH_STRATEGY_NAME = "flush-strategy"; private static final String CAPACITY_INCREMENTER_CLASS_NAME = "capacity-incrementer-class"; private static final String CAPACITY_INCREMENTER_PROPERTIES_NAME = "capacity-incrementer-properties"; private static final String CAPACITY_DECREMENTER_CLASS_NAME = "capacity-decrementer-class"; private static final String CAPACITY_DECREMENTER_PROPERTIES_NAME = "capacity-decrementer-properties"; public static final SimpleAttributeDefinition BLOCKING_TIMEOUT_WAIT_MILLIS = new SimpleAttributeDefinitionBuilder(BLOCKING_TIMEOUT_WAIT_MILLIS_NAME, ModelType.LONG, true) .setXmlName(TimeOut.Tag.BLOCKING_TIMEOUT_MILLIS.getLocalName()) .setMeasurementUnit(MeasurementUnit.MILLISECONDS) .setAllowExpression(true) .build(); public static final SimpleAttributeDefinition IDLETIMEOUTMINUTES = new SimpleAttributeDefinitionBuilder(IDLETIMEOUTMINUTES_NAME, ModelType.LONG, true) .setXmlName(TimeOut.Tag.IDLE_TIMEOUT_MINUTES.getLocalName()) .setMeasurementUnit(MeasurementUnit.MINUTES) .setAllowExpression(true) .setValidator(new IntRangeValidator(0, Integer.MAX_VALUE, true, true)) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition BACKGROUNDVALIDATIONMILLIS = new SimpleAttributeDefinitionBuilder(BACKGROUNDVALIDATIONMILLIS_NAME, ModelType.LONG, true) .setXmlName(Validation.Tag.BACKGROUND_VALIDATION_MILLIS.getLocalName()) .setMeasurementUnit(MeasurementUnit.MILLISECONDS) .setValidator(new IntRangeValidator(1, true, true)) .setAllowExpression(true) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition BACKGROUNDVALIDATION = new SimpleAttributeDefinitionBuilder(BACKGROUNDVALIDATION_NAME, ModelType.BOOLEAN, true) .setXmlName(Validation.Tag.BACKGROUND_VALIDATION.getLocalName()) .setAllowExpression(true) //.setDefaultValue(new ModelNode(Defaults.BACKGROUND_VALIDATION)) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition USE_FAST_FAIL = new SimpleAttributeDefinitionBuilder(USE_FAST_FAIL_NAME, ModelType.BOOLEAN, true) .setXmlName(Validation.Tag.USE_FAST_FAIL.getLocalName()) .setDefaultValue(new ModelNode(Defaults.USE_FAST_FAIL)) .setAllowExpression(true) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition VALIDATE_ON_MATCH = new SimpleAttributeDefinitionBuilder(VALIDATEONMATCH_NAME, ModelType.BOOLEAN, true) .setXmlName(Validation.Tag.VALIDATE_ON_MATCH.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition MAX_POOL_SIZE = new SimpleAttributeDefinitionBuilder(MAX_POOL_SIZE_NAME, ModelType.INT, true) .setXmlName(Pool.Tag.MAX_POOL_SIZE.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(Defaults.MAX_POOL_SIZE)) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition MIN_POOL_SIZE = new SimpleAttributeDefinitionBuilder(MIN_POOL_SIZE_NAME, ModelType.INT, true) .setXmlName(Pool.Tag.MIN_POOL_SIZE.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(Defaults.MIN_POOL_SIZE)) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition INITIAL_POOL_SIZE = new SimpleAttributeDefinitionBuilder(INITIAL_POOL_SIZE_NAME, ModelType.INT) .setXmlName(Pool.Tag.INITIAL_POOL_SIZE.getLocalName()) .setAllowExpression(true) .setRequired(false) .build(); public static final SimpleAttributeDefinition CAPACITY_INCREMENTER_CLASS = new SimpleAttributeDefinitionBuilder(CAPACITY_INCREMENTER_CLASS_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); public static final PropertiesAttributeDefinition CAPACITY_INCREMENTER_PROPERTIES = new PropertiesAttributeDefinition.Builder(CAPACITY_INCREMENTER_PROPERTIES_NAME, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setRequired(false) .setAllowExpression(true) .setAttributeMarshaller(new AttributeMarshaller() { @Override public void marshallAsElement(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException { for (ModelNode property : resourceModel.get(attribute.getName()).asList()) { writer.writeStartElement(attribute.getXmlName()); writer.writeAttribute(org.jboss.as.controller.parsing.Attribute.NAME.getLocalName(), property.asProperty().getName()); writer.writeCharacters(property.asProperty().getValue().asString()); writer.writeEndElement(); } } }) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition CAPACITY_DECREMENTER_CLASS = new SimpleAttributeDefinitionBuilder(CAPACITY_DECREMENTER_CLASS_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); public static final PropertiesAttributeDefinition CAPACITY_DECREMENTER_PROPERTIES = new PropertiesAttributeDefinition.Builder(CAPACITY_DECREMENTER_PROPERTIES_NAME, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setRequired(false) .setAllowExpression(true) .setAttributeMarshaller(new AttributeMarshaller() { @Override public void marshallAsElement(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException { for (ModelNode property : resourceModel.get(attribute.getName()).asList()) { writer.writeStartElement(attribute.getXmlName()); writer.writeAttribute(org.jboss.as.controller.parsing.Attribute.NAME.getLocalName(), property.asProperty().getName()); writer.writeCharacters(property.asProperty().getValue().asString()); writer.writeEndElement(); } } }) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition POOL_PREFILL = new SimpleAttributeDefinitionBuilder(POOL_PREFILL_NAME, ModelType.BOOLEAN, true) .setDefaultValue(new ModelNode(Defaults.PREFILL)) .setAllowExpression(true) .setXmlName(Pool.Tag.PREFILL.getLocalName()) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition POOL_FAIR = new SimpleAttributeDefinitionBuilder(POOL_FAIR_NAME, ModelType.BOOLEAN, true) .setDefaultValue(ModelNode.TRUE) .setAllowExpression(true) .setXmlName(Pool.Tag.FAIR.getLocalName()) .build(); public static final SimpleAttributeDefinition POOL_USE_STRICT_MIN = new SimpleAttributeDefinitionBuilder(POOL_USE_STRICT_MIN_NAME, ModelType.BOOLEAN, true) .setDefaultValue(new ModelNode(Defaults.USE_STRICT_MIN)) .setAllowExpression(true) .setXmlName(Pool.Tag.USE_STRICT_MIN.getLocalName()) .build(); public static final SimpleAttributeDefinition POOL_FLUSH_STRATEGY = new SimpleAttributeDefinitionBuilder(FLUSH_STRATEGY_NAME, ModelType.STRING) .setDefaultValue(new ModelNode(Defaults.FLUSH_STRATEGY.getName())) .setXmlName(Pool.Tag.FLUSH_STRATEGY.getLocalName()) .setRequired(false) .setAllowExpression(true) .setAllowedValues(Stream.of(FlushStrategy.values()).map(FlushStrategy::toString).filter(Objects::nonNull).toArray(String[]::new)) .setValidator(EnumValidator.create(FlushStrategy.class)) .setRestartAllServices() .build(); public static final AttributeDefinition[] POOL_ATTRIBUTES = {BLOCKING_TIMEOUT_WAIT_MILLIS, IDLETIMEOUTMINUTES, BACKGROUNDVALIDATIONMILLIS, BACKGROUNDVALIDATION, USE_FAST_FAIL, VALIDATE_ON_MATCH, MAX_POOL_SIZE, MIN_POOL_SIZE, INITIAL_POOL_SIZE, POOL_PREFILL, POOL_FAIR, POOL_USE_STRICT_MIN, POOL_FLUSH_STRATEGY, CAPACITY_INCREMENTER_CLASS, CAPACITY_DECREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES, CAPACITY_DECREMENTER_PROPERTIES}; public static final SimpleAttributeDefinition POOL_STATISTICS_ENABLED = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.STATISTICS_ENABLED, ModelType.BOOLEAN) .setStorageRuntime() .build(); }
12,745
51.887967
202
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/common/pool/PoolConfigurationRWHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.common.pool; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration; import org.jboss.jca.core.api.management.ConnectionFactory; import org.jboss.jca.core.api.management.Connector; import org.jboss.jca.core.api.management.DataSource; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.msc.service.ServiceController; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_ATTRIBUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.common.pool.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; /** * @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author <a href="mailto:[email protected]">Jeff Zhang</a> */ public class PoolConfigurationRWHandler { public static final List<String> ATTRIBUTES = Arrays.asList(MAX_POOL_SIZE.getName(), MIN_POOL_SIZE.getName(), INITIAL_POOL_SIZE.getName(),BLOCKING_TIMEOUT_WAIT_MILLIS.getName(), IDLETIMEOUTMINUTES.getName(), BACKGROUNDVALIDATION.getName(), BACKGROUNDVALIDATIONMILLIS.getName(), POOL_PREFILL.getName(), POOL_FAIR.getName(), POOL_USE_STRICT_MIN.getName(), POOL_FLUSH_STRATEGY.getName()); // TODO this seems to just do what the default handler does, so registering it is probably unnecessary public static class PoolConfigurationReadHandler implements OperationStepHandler { public static final PoolConfigurationReadHandler INSTANCE = new PoolConfigurationReadHandler(); public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final String parameterName = operation.require(NAME).asString(); final ModelNode submodel = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel(); final ModelNode currentValue = submodel.hasDefined(parameterName) ? submodel.get(parameterName).clone() : new ModelNode(); context.getResult().set(currentValue); } } public abstract static class PoolConfigurationWriteHandler extends AbstractWriteAttributeHandler<List<PoolConfiguration>> { protected PoolConfigurationWriteHandler() { super(POOL_ATTRIBUTES); } @Override protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<PoolConfiguration>> handbackHolder) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String poolName = address.getLastElement().getValue(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); List<PoolConfiguration> poolConfigs = null; if (managementRepoService != null) { try { final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue(); poolConfigs = getMatchingPoolConfigs(poolName, repository); updatePoolConfigs(poolConfigs, parameterName, newValue); handbackHolder.setHandback(poolConfigs); } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage())); } } return (IDLETIMEOUTMINUTES.getName().equals(parameterName) || BACKGROUNDVALIDATION.getName().equals(parameterName) || BACKGROUNDVALIDATIONMILLIS.getName().equals(parameterName) || POOL_PREFILL.getName().equals(parameterName) || POOL_FLUSH_STRATEGY.getName().equals(parameterName) || MAX_POOL_SIZE.getName().equals(parameterName) || MIN_POOL_SIZE.getName().equals(parameterName)); } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String parameterName, ModelNode valueToRestore, ModelNode valueToRevert, List<PoolConfiguration> handback) throws OperationFailedException { if (handback != null) { updatePoolConfigs(handback, parameterName, valueToRestore.resolve()); } } private void updatePoolConfigs(List<PoolConfiguration> poolConfigs, String parameterName, ModelNode newValue) { for (PoolConfiguration pc : poolConfigs) { if (MAX_POOL_SIZE.getName().equals(parameterName)) { pc.setMaxSize(newValue.asInt()); } if (MIN_POOL_SIZE.getName().equals(parameterName)) { pc.setMinSize(newValue.asInt()); } if (INITIAL_POOL_SIZE.getName().equals(parameterName)) { pc.setInitialSize(newValue.isDefined()? newValue.asInt(): 0); } if (BLOCKING_TIMEOUT_WAIT_MILLIS.getName().equals(parameterName)) { pc.setBlockingTimeout(newValue.isDefined()? newValue.asLong(): 0); } if (POOL_USE_STRICT_MIN.getName().equals(parameterName)) { pc.setStrictMin(newValue.asBoolean()); } if (USE_FAST_FAIL.getName().equals(parameterName)) { pc.setUseFastFail(newValue.asBoolean()); } if (VALIDATE_ON_MATCH.getName().equals(parameterName)) { pc.setValidateOnMatch(newValue.asBoolean()); } if (POOL_FAIR.getName().equals(parameterName)) { pc.setFair(newValue.asBoolean()); } } } protected abstract List<PoolConfiguration> getMatchingPoolConfigs(String jndiName, ManagementRepository repository); } public static class LocalAndXaDataSourcePoolConfigurationWriteHandler extends PoolConfigurationWriteHandler { public static final LocalAndXaDataSourcePoolConfigurationWriteHandler INSTANCE = new LocalAndXaDataSourcePoolConfigurationWriteHandler(); protected LocalAndXaDataSourcePoolConfigurationWriteHandler() { super(); } protected List<PoolConfiguration> getMatchingPoolConfigs(String poolName, ManagementRepository repository) { ArrayList<PoolConfiguration> result = new ArrayList<PoolConfiguration>(repository.getDataSources().size()); if (repository.getDataSources() != null) { for (DataSource ds : repository.getDataSources()) { if (poolName.equalsIgnoreCase(ds.getPool().getName())) { result.add(ds.getPoolConfiguration()); } } } result.trimToSize(); return result; } } public static class RaPoolConfigurationWriteHandler extends PoolConfigurationWriteHandler { public static final RaPoolConfigurationWriteHandler INSTANCE = new RaPoolConfigurationWriteHandler(); protected RaPoolConfigurationWriteHandler() { super(); } protected List<PoolConfiguration> getMatchingPoolConfigs(String poolName, ManagementRepository repository) { ArrayList<PoolConfiguration> result = new ArrayList<PoolConfiguration>(repository.getConnectors().size()); if (repository.getConnectors() != null) { for (Connector conn : repository.getConnectors()) { if (conn.getConnectionFactories() == null || conn.getConnectionFactories().get(0) == null || conn.getConnectionFactories().get(0).getPool() == null) continue; ConnectionFactory connectionFactory = conn.getConnectionFactories().get(0); if (poolName.equals(connectionFactory.getPool().getName())) { PoolConfiguration pc = conn.getConnectionFactories().get(0).getPoolConfiguration(); result.add(pc); } } } result.trimToSize(); return result; } } }
11,230
51.481308
181
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/common/pool/PoolStatisticsRuntimeAttributeReadHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.common.pool; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.spi.statistics.StatisticsPlugin; public class PoolStatisticsRuntimeAttributeReadHandler implements OperationStepHandler { private final StatisticsPlugin stats; public PoolStatisticsRuntimeAttributeReadHandler(StatisticsPlugin stats) { this.stats = stats; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(NAME).asString(); try { final ModelNode result = context.getResult(); switch (attributeName) { case ModelDescriptionConstants.STATISTICS_ENABLED: { result.set(stats.isEnabled()); break; } } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } }, OperationContext.Stage.RUNTIME); } } }
2,877
40.710145
132
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/common/pool/PoolStatisticsRuntimeAttributeWriteHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.common.pool; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.operations.validation.ParametersValidator; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.spi.statistics.StatisticsPlugin; public class PoolStatisticsRuntimeAttributeWriteHandler implements OperationStepHandler { private final StatisticsPlugin stats; private final ParametersValidator nameValidator = new ParametersValidator(); public PoolStatisticsRuntimeAttributeWriteHandler(final StatisticsPlugin stats) { this.stats = stats; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { nameValidator.validate(operation); final String attributeName = operation.require(NAME).asString(); // Don't require VALUE. Let the validator decide if it's bothered by an undefined value ModelNode newValue = operation.hasDefined(VALUE) ? operation.get(VALUE) : new ModelNode(); final ModelNode resolvedValue = newValue.resolve(); switch (attributeName) { case ModelDescriptionConstants.STATISTICS_ENABLED: { stats.setEnabled(resolvedValue.asBoolean()); break; } } } }
2,694
37.5
104
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/common/pool/PoolOperations.java
/* * 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.connector.subsystems.common.pool; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCES; import static org.jboss.as.connector.subsystems.datasources.Constants.ENABLED; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import java.util.ArrayList; import java.util.List; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.subsystems.common.jndi.Util; import static org.jboss.as.connector.subsystems.datasources.Constants.USERNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.PASSWORD; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.connector.util.ModelNodeUtil; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.jboss.jca.adapters.jdbc.WrappedConnectionRequestInfo; import org.jboss.jca.core.api.connectionmanager.pool.FlushMode; import org.jboss.jca.core.api.connectionmanager.pool.Pool; import org.jboss.jca.core.api.management.ConnectionFactory; import org.jboss.jca.core.api.management.Connector; import org.jboss.jca.core.api.management.DataSource; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.msc.service.ServiceController; import jakarta.resource.ResourceException; public abstract class PoolOperations implements OperationStepHandler { private final PoolMatcher matcher; private final boolean disallowMonitor; protected PoolOperations(PoolMatcher matcher, boolean disallowMonitor) { super(); this.matcher = matcher; this.disallowMonitor = disallowMonitor; } public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String jndiName; ModelNode model; if (!address.getElement(0).getKey().equals(ModelDescriptionConstants.DEPLOYMENT) && (model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel()).isDefined()) { jndiName = Util.getJndiName(context, model); if (isDisabledDatasource(context, address, model)) { throw ConnectorLogger.ROOT_LOGGER.datasourceIsDisabled(jndiName); } } else { jndiName = address.getLastElement().getValue(); } final Object[] parameters = getParameters(context, operation); if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ServiceController<?> managementRepoService = context.getServiceRegistry(disallowMonitor).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); if (managementRepoService != null) { ModelNode operationResult = null; try { final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue(); final List<Pool> pools = matcher.match(jndiName, repository); if (pools.isEmpty()) { throw ConnectorLogger.ROOT_LOGGER.failedToMatchPool(jndiName); } for (Pool pool : pools) { operationResult = invokeCommandOn(pool, parameters); } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToInvokeOperation(concatenateExceptionCauses(e))); } if (operationResult != null) { context.getResult().set(operationResult); } } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } }, OperationContext.Stage.RUNTIME); } } private String concatenateExceptionCauses(Exception e) { StringBuilder sb = new StringBuilder(); sb.append(e.toString()); Throwable t = e.getCause(); while (t != null) { sb.append(" Caused by: ").append(t.toString()); t = t.getCause(); } return sb.toString(); } protected abstract ModelNode invokeCommandOn(Pool pool, Object... parameters) throws Exception; protected abstract Object[] getParameters(OperationContext context, ModelNode operation); public static class FlushIdleConnectionInPool extends PoolOperations { public static final FlushIdleConnectionInPool DS_INSTANCE = new FlushIdleConnectionInPool(new DsPoolMatcher()); public static final FlushIdleConnectionInPool RA_INSTANCE = new FlushIdleConnectionInPool(new RaPoolMatcher()); protected FlushIdleConnectionInPool(PoolMatcher matcher) { super(matcher, true); } @Override protected ModelNode invokeCommandOn(Pool pool, Object... parameters) { pool.flush(FlushMode.IDLE); return null; } @Override protected Object[] getParameters(OperationContext context, ModelNode operation) { return null; } } public static class DumpQueuedThreadInPool extends PoolOperations { public static final DumpQueuedThreadInPool DS_INSTANCE = new DumpQueuedThreadInPool(new DsPoolMatcher()); public static final DumpQueuedThreadInPool RA_INSTANCE = new DumpQueuedThreadInPool(new RaPoolMatcher()); protected DumpQueuedThreadInPool(PoolMatcher matcher) { super(matcher, false); } @Override protected ModelNode invokeCommandOn(Pool pool, Object... parameters) { ModelNode result = new ModelNode(); for (String line : pool.dumpQueuedThreads()) { result.add(line); } return result; } @Override protected Object[] getParameters(OperationContext context, ModelNode operation) { return null; } } public static class FlushAllConnectionInPool extends PoolOperations { public static final FlushAllConnectionInPool DS_INSTANCE = new FlushAllConnectionInPool(new DsPoolMatcher()); public static final FlushAllConnectionInPool RA_INSTANCE = new FlushAllConnectionInPool(new RaPoolMatcher()); protected FlushAllConnectionInPool(PoolMatcher matcher) { super(matcher, true); } @Override protected ModelNode invokeCommandOn(Pool pool, Object... parameters) { pool.flush(FlushMode.ALL); return null; } @Override protected Object[] getParameters(OperationContext context, ModelNode operation) { return null; } } public static class FlushInvalidConnectionInPool extends PoolOperations { public static final FlushInvalidConnectionInPool DS_INSTANCE = new FlushInvalidConnectionInPool(new DsPoolMatcher()); public static final FlushInvalidConnectionInPool RA_INSTANCE = new FlushInvalidConnectionInPool(new RaPoolMatcher()); protected FlushInvalidConnectionInPool(PoolMatcher matcher) { super(matcher, true); } @Override protected ModelNode invokeCommandOn(Pool pool, Object... parameters) { pool.flush(FlushMode.INVALID); return null; } @Override protected Object[] getParameters(OperationContext context, ModelNode operation) { return null; } } public static class FlushGracefullyConnectionInPool extends PoolOperations { public static final FlushGracefullyConnectionInPool DS_INSTANCE = new FlushGracefullyConnectionInPool(new DsPoolMatcher()); public static final FlushGracefullyConnectionInPool RA_INSTANCE = new FlushGracefullyConnectionInPool(new RaPoolMatcher()); protected FlushGracefullyConnectionInPool(PoolMatcher matcher) { super(matcher, true); } @Override protected ModelNode invokeCommandOn(Pool pool, Object... parameters) { pool.flush(FlushMode.GRACEFULLY); return null; } @Override protected Object[] getParameters(OperationContext context, ModelNode operation) { return null; } } public static class TestConnectionInPool extends PoolOperations { public static final TestConnectionInPool DS_INSTANCE = new TestConnectionInPool(new DsPoolMatcher()); public static final TestConnectionInPool RA_INSTANCE = new TestConnectionInPool(new RaPoolMatcher()); protected TestConnectionInPool(PoolMatcher matcher) { super(matcher, true); } @Override protected ModelNode invokeCommandOn(Pool pool, Object... parameters) throws Exception { ModelNode result = new ModelNode(); try { if (parameters != null) { WrappedConnectionRequestInfo cri = new WrappedConnectionRequestInfo((String) parameters[0], (String) parameters[1]); pool.testConnection(cri, null); } else { pool.testConnection(); } result.add(true); return result; } catch (ResourceException e) { throw ConnectorLogger.ROOT_LOGGER.invalidConnection(e); } } @Override protected Object[] getParameters(OperationContext context, ModelNode operation) { Object[] parameters = null; try { if (operation.hasDefined(USERNAME.getName()) || operation.hasDefined(PASSWORD.getName())) { parameters = new Object[2]; parameters[0] = USERNAME.resolveModelAttribute(context, operation).asString(); parameters[1] = PASSWORD.resolveModelAttribute(context, operation).asString(); } } catch (OperationFailedException ofe) { //just return null } return parameters; } } private interface PoolMatcher { List<Pool> match(String jndiName, ManagementRepository repository); } private static class DsPoolMatcher implements PoolMatcher { public List<Pool> match(String jndiName, ManagementRepository repository) { ArrayList<Pool> result = new ArrayList<Pool>(repository .getDataSources().size()); if (repository.getDataSources() != null) { for (DataSource ds : repository.getDataSources()) { if (jndiName.equalsIgnoreCase(ds.getJndiName()) && ds.getPool() != null) { result.add(ds.getPool()); } } } result.trimToSize(); return result; } } private static class RaPoolMatcher implements PoolMatcher { public List<Pool> match(String jndiName, ManagementRepository repository) { ArrayList<Pool> result = new ArrayList<Pool>(repository.getConnectors().size()); if (repository.getConnectors() != null) { for (Connector c : repository.getConnectors()) { if (c.getConnectionFactories() == null || c.getConnectionFactories().isEmpty()) continue; for (ConnectionFactory cf : c.getConnectionFactories()) { if (cf != null && cf.getPool() != null && jndiName.equalsIgnoreCase(cf.getJndiName())) { result.add(cf.getPool()); } } } } return result; } } private boolean isDisabledDatasource(OperationContext context, PathAddress address, ModelNode datasourceNode) throws OperationFailedException { return address.getElement(0).getValue().equals(DATASOURCES) && !ModelNodeUtil.getBooleanIfSetOrGetDefault(context, datasourceNode, ENABLED); } }
13,759
40.95122
147
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/common/pool/PoolMetrics.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.common.pool; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import java.util.List; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.jca.core.spi.statistics.StatisticsPlugin; import org.jboss.msc.service.ServiceController; /** * @author <a href="mailto:[email protected]">Jeff Zhang</a> */ public abstract class PoolMetrics implements OperationStepHandler { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String jndiName = address.getLastElement().getValue(); final String attributeName = operation.require(NAME).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); if (managementRepoService != null) { try { final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue(); final ModelNode result = context.getResult(); List<StatisticsPlugin> stats = getMatchingStats(jndiName, repository); for (StatisticsPlugin stat : stats) { result.set("" + stat.getValue(attributeName)); } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } } }, OperationContext.Stage.RUNTIME); } } protected abstract List<StatisticsPlugin> getMatchingStats(String jndiName, ManagementRepository repository); public static class ParametrizedPoolMetricsHandler implements OperationStepHandler { private final StatisticsPlugin stats; public ParametrizedPoolMetricsHandler(StatisticsPlugin stats) { this.stats = stats; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(NAME).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); if (managementRepoService != null) { try { setModelValue(context.getResult(), attributeName); } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } } }, OperationContext.Stage.RUNTIME); } } private void setModelValue(ModelNode result, String attributeName) { if (stats.getType(attributeName) == int.class) { result.set((Integer) stats.getValue(attributeName)); } else if (stats.getType(attributeName) == long.class) { result.set((Long) stats.getValue(attributeName)); } else { result.set("" + stats.getValue(attributeName)); } } } }
5,587
46.760684
139
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/common/jndi/Constants.java
/* * JBoss, Home of Professional Open Source * Copyright 2022, Red Hat Middleware LLC, 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. */ package org.jboss.as.connector.subsystems.common.jndi; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.jca.common.api.metadata.Defaults; import org.jboss.jca.common.api.metadata.ds.DataSource; public class Constants { private static final String JNDINAME_NAME = "jndi-name"; private static final String USE_JAVA_CONTEXT_NAME = "use-java-context"; public static SimpleAttributeDefinition JNDI_NAME = new SimpleAttributeDefinitionBuilder(JNDINAME_NAME, ModelType.STRING, false) .setXmlName(DataSource.Attribute.JNDI_NAME.getLocalName()) .setAllowExpression(true) .setValidator((__, value) -> { if (value.getType() != ModelType.EXPRESSION) { String str = value.asString(); if (str.endsWith("/") || str.indexOf("//") != -1) { throw ConnectorLogger.ROOT_LOGGER.jndiNameShouldValidate(); } } }) .setRestartAllServices() .build(); public static SimpleAttributeDefinition USE_JAVA_CONTEXT = new SimpleAttributeDefinitionBuilder(USE_JAVA_CONTEXT_NAME, ModelType.BOOLEAN, true) .setXmlName(DataSource.Attribute.USE_JAVA_CONTEXT.getLocalName()) .setDefaultValue(new ModelNode(Defaults.USE_JAVA_CONTEXT)) .setAllowExpression(true) .setRestartAllServices() .build(); }
2,422
43.87037
147
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/common/jndi/Util.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.common.jndi; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * Common use utility methods. * * @author Brian Stansberry (c) 2011 Red Hat Inc. */ public class Util { /** * Extracts the raw JNDI_NAME value from the given model node, and depending on the value and * the value of any USE_JAVA_CONTEXT child node, converts the raw name into a compliant jndi name. * * @param modelNode the model node; either an operation or the model behind a datasource resource * * @return the compliant jndi name */ public static String getJndiName(final OperationContext context, final ModelNode modelNode) throws OperationFailedException { final String rawJndiName = JNDI_NAME.resolveModelAttribute(context, modelNode).asString(); return cleanJndiName(rawJndiName, USE_JAVA_CONTEXT.resolveModelAttribute(context, modelNode).asBoolean()); } public static String cleanJndiName(String rawJndiName, Boolean useJavaContext) { final String jndiName; if (!rawJndiName.startsWith("java:") && useJavaContext) { if(rawJndiName.startsWith("jboss/")) { // Bind to java:jboss/ namespace jndiName = "java:" + rawJndiName; } else { // Bind to java:/ namespace jndiName= "java:/" + rawJndiName; } } else { jndiName = rawJndiName; } return jndiName; } private Util() { // prevent instantiation } }
2,843
38.5
129
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/Constants.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import org.jboss.as.controller.ModelVersion; /** * @author @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ public class Constants { static final ModelVersion ELYTRON_BY_DEFAULT_VERSION = ModelVersion.create(6, 0, 0); static final String JCA = "jca"; static final String ARCHIVE_VALIDATION = "archive-validation"; static final String BEAN_VALIDATION = "bean-validation"; static final String TRACER = "tracer"; static final String CACHED_CONNECTION_MANAGER = "cached-connection-manager"; public static final String DEFAULT_NAME = "default"; static final String WORKMANAGER_SHORT_RUNNING = "short-running-threads"; static final String WORKMANAGER_LONG_RUNNING = "long-running-threads"; static final String WORKMANAGER = "workmanager"; static final String DISTRIBUTED_WORKMANAGER = "distributed-workmanager"; static final String BOOTSTRAP_CONTEXT = "bootstrap-context"; static final String TX = "TX"; static final String NON_TX = "NonTX"; static final Boolean ELYTRON_MANAGED_SECURITY = Boolean.TRUE; static final String ELYTRON_ENABLED_NAME = "elytron-enabled"; }
2,323
35.888889
88
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/ParamsUtils.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import org.jboss.dmr.ModelNode; public class ParamsUtils { public static boolean has(ModelNode operation, String name) { return operation.has(name) && operation.get(name).isDefined(); } public static boolean parseBooleanParameter(ModelNode operation, String name) { return parseBooleanParameter(operation, name, false); } public static boolean parseBooleanParameter(ModelNode operation, String name, boolean defaultValue) { return has(operation, name) ? operation.get(name).asBoolean() : defaultValue; } public static String parseStringParameter(ModelNode operation, String name) { return has(operation, name) ? operation.get(name).toString() : null; } }
1,796
38.933333
105
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/IdleRemoverService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import org.jboss.jca.core.connectionmanager.pool.idle.IdleRemover; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * Idle remover service * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ final class IdleRemoverService implements Service<IdleRemover> { /** * Constructor */ public IdleRemoverService() { } @Override public IdleRemover getValue() throws IllegalStateException { return IdleRemover.getInstance(); } @Override public void start(StartContext context) throws StartException { try { IdleRemover.getInstance().start(); } catch (Throwable t) { throw new StartException(t); } } @Override public void stop(StopContext context) { try { IdleRemover.getInstance().stop(); } catch (Throwable t) { // Ignore } } }
2,107
30.939394
73
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaDistributedWorkManagerWriteHandler.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.services.workmanager.NamedDistributedWorkManager; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.connector.util.Injection; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.dmr.Property; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import org.jboss.jca.core.workmanager.policy.Always; import org.jboss.jca.core.workmanager.policy.Never; import org.jboss.jca.core.workmanager.policy.WaterMark; import org.jboss.jca.core.workmanager.selector.FirstAvailable; import org.jboss.jca.core.workmanager.selector.MaxFreeThreads; import org.jboss.jca.core.workmanager.selector.PingTime; public class JcaDistributedWorkManagerWriteHandler extends AbstractWriteAttributeHandler<JcaSubsystemConfiguration> { static JcaDistributedWorkManagerWriteHandler INSTANCE = new JcaDistributedWorkManagerWriteHandler(); private JcaDistributedWorkManagerWriteHandler() { super(JcaDistributedWorkManagerDefinition.DWmParameters.getAttributeDefinitions()); } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<JcaSubsystemConfiguration> jcaSubsystemConfigurationHandbackHolder) throws OperationFailedException { final ModelNode address = operation.require(OP_ADDR); final String name = PathAddress.pathAddress(address).getLastElement().getValue(); Object wm = context.getServiceRegistry(true).getService(ConnectorServices.WORKMANAGER_SERVICE.append(name)).getValue(); if (wm == null || ! (wm instanceof NamedDistributedWorkManager)) { throw ConnectorLogger.ROOT_LOGGER.failedToFindDistributedWorkManager(name); } NamedDistributedWorkManager namedDistributedWorkManager = (NamedDistributedWorkManager) wm; Injection injector = new Injection(); if (attributeName.equals(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().getName())) { switch (JcaDistributedWorkManagerDefinition.PolicyValue.valueOf(resolvedValue.asString())) { case NEVER: { namedDistributedWorkManager.setPolicy(new Never()); break; } case ALWAYS: { namedDistributedWorkManager.setPolicy(new Always()); break; } case WATERMARK: { namedDistributedWorkManager.setPolicy(new WaterMark()); break; } default: { throw ROOT_LOGGER.unsupportedPolicy(resolvedValue.asString()); } } } else if (attributeName.equals(JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR.getAttribute().getName())) { switch (JcaDistributedWorkManagerDefinition.SelectorValue.valueOf(resolvedValue.asString())) { case FIRST_AVAILABLE: { namedDistributedWorkManager.setSelector(new FirstAvailable()); break; } case MAX_FREE_THREADS: { namedDistributedWorkManager.setSelector(new MaxFreeThreads()); break; } case PING_TIME: { namedDistributedWorkManager.setSelector(new PingTime()); break; } default: { throw ROOT_LOGGER.unsupportedSelector(resolvedValue.asString()); } } } else if (attributeName.equals(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute().getName()) && namedDistributedWorkManager.getPolicy() != null) { for (Property property : resolvedValue.asPropertyList()) { try { injector.inject(namedDistributedWorkManager.getPolicy(), property.getName(), property.getValue().asString()); } catch (Exception e) { ROOT_LOGGER.unsupportedPolicyOption(property.getName()); } } } else if (attributeName.equals(JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute().getName())) { for (Property property : resolvedValue.asPropertyList()) { try { injector.inject(namedDistributedWorkManager.getSelector(), property.getName(), property.getValue().asString()); } catch (Exception e) { ROOT_LOGGER.unsupportedSelectorOption(property.getName()); } } } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, JcaSubsystemConfiguration handback) throws OperationFailedException { CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(true).getService(ConnectorServices.CCM_SERVICE).getValue(); if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG.getAttribute().getName())) { ccm.setDebug(valueToRestore.asBoolean()); } else if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.ERROR.getAttribute().getName())) { ccm.setError(valueToRestore.asBoolean()); } else if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute().getName())) { ccm.setIgnoreUnknownConnections(valueToRestore.asBoolean()); } } }
7,235
47.891892
277
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/BeanValidationAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractBoottimeAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * @author <a href="[email protected]">Jesper Pedersen</a> * @author <a href="[email protected]">Stefano Maestri</a> */ public class BeanValidationAdd extends AbstractBoottimeAddStepHandler { public static final BeanValidationAdd INSTANCE = new BeanValidationAdd(); @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { for (JcaBeanValidationDefinition.BeanValidationParameters parameter : JcaBeanValidationDefinition.BeanValidationParameters.values() ) { parameter.getAttribute().validateAndSet(operation,model); } } @Override protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final boolean enabled = JcaBeanValidationDefinition.BeanValidationParameters.BEAN_VALIDATION_ENABLED.getAttribute().resolveModelAttribute(context, model).asBoolean(); ServiceName serviceName = ConnectorServices.BEAN_VALIDATION_CONFIG_SERVICE; ServiceName jcaConfigServiceName = ConnectorServices.CONNECTOR_CONFIG_SERVICE; final ServiceTarget serviceTarget = context.getServiceTarget(); final BeanValidationService.BeanValidation config = new BeanValidationService.BeanValidation(enabled); final BeanValidationService service = new BeanValidationService(config); ServiceController<?> controller = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(jcaConfigServiceName, JcaSubsystemConfiguration.class, service.getJcaConfigInjector() ) .install(); } }
3,199
48.230769
174
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaCachedConnectionManagerWriteHandler.java
/* * 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; /** * {@link org.jboss.as.controller.OperationStepHandler} for the {@code write-attribute} operation for the * {@link JcaCachedConnectionManagerDefinition cached connection manager resource}. * * @author Brian Stansberry (c) 2012 Red Hat Inc. */ public class JcaCachedConnectionManagerWriteHandler extends AbstractWriteAttributeHandler<JcaSubsystemConfiguration> { static JcaCachedConnectionManagerWriteHandler INSTANCE = new JcaCachedConnectionManagerWriteHandler(); private JcaCachedConnectionManagerWriteHandler() { super( JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG.getAttribute(), JcaCachedConnectionManagerDefinition.CcmParameters.ERROR.getAttribute(), JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute() ); } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<JcaSubsystemConfiguration> jcaSubsystemConfigurationHandbackHolder) throws OperationFailedException { CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(true).getService(ConnectorServices.CCM_SERVICE).getValue(); if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG.getAttribute().getName())) { ccm.setDebug(resolvedValue.asBoolean()); } else if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.ERROR.getAttribute().getName())) { ccm.setError(resolvedValue.asBoolean()); } else if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute().getName())) { ccm.setIgnoreUnknownConnections(resolvedValue.asBoolean()); } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, JcaSubsystemConfiguration handback) throws OperationFailedException { CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(true).getService(ConnectorServices.CCM_SERVICE).getValue(); if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG.getAttribute().getName())) { ccm.setDebug(valueToRestore.asBoolean()); } else if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.ERROR.getAttribute().getName())) { ccm.setError(valueToRestore.asBoolean()); } else if (attributeName.equals(JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute().getName())) { ccm.setIgnoreUnknownConnections(valueToRestore.asBoolean()); } } }
4,305
50.879518
277
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/CachedConnectionManagerAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import org.jboss.as.connector.deployers.ra.processors.CachedConnectionManagerSetupProcessor; import org.jboss.as.connector.services.jca.CachedConnectionManagerService; import org.jboss.as.connector.services.jca.NonTxCachedConnectionManagerService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractBoottimeAddStepHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.as.controller.registry.Resource; import org.jboss.as.server.AbstractDeploymentChainStep; import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.as.server.deployment.Phase; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.msc.service.ServiceTarget; import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER; import static org.jboss.as.connector.subsystems.jca.JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG; import static org.jboss.as.connector.subsystems.jca.JcaCachedConnectionManagerDefinition.CcmParameters.ERROR; import static org.jboss.as.connector.subsystems.jca.JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS; import static org.jboss.as.connector.subsystems.jca.JcaCachedConnectionManagerDefinition.CcmParameters.INSTALL; import java.util.Set; /** * @author <a href="[email protected]">Jesper Pedersen</a> * @author <a href="[email protected]">Stefano Maestri</a> */ public class CachedConnectionManagerAdd extends AbstractBoottimeAddStepHandler { public static final CachedConnectionManagerAdd INSTANCE = new CachedConnectionManagerAdd(); @Override protected Resource createResource(OperationContext context, ModelNode operation) { // WFLY-2640/WFLY-8141 This resource is an odd case because the *parser* will insert a // resource add op even if the config says nothing, but we also have to support // cases where subsystem isn't added and this resource is added via a management op. // To cover all the cases we need to allow add to succeed when the resource already // exists, so long as it is configured with the values the parser generates (i.e. no defined attributes) try { Resource existing = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); // will fail in normal case ModelNode model = existing.getModel(); boolean allDefault = true; for (JcaCachedConnectionManagerDefinition.CcmParameters param : JcaCachedConnectionManagerDefinition.CcmParameters.values()) { if (param == INSTALL || param == DEBUG || param == ERROR || param == IGNORE_UNKNOWN_CONNECTIONS) { AttributeDefinition ad = param.getAttribute(); assert !ad.isRequired() : ad.getName(); // else someone changed something and we need to account for that if (model.hasDefined(ad.getName())) { allDefault = false; break; } } else { // Someone added a new param since WFLY-2640/WFLY-8141 and did not account for it above throw new IllegalStateException(); } } if (allDefault) { // We can use the existing resource as if we just created it return existing; } // else fall through and call super method which will fail due to resource already being present } catch (Resource.NoSuchResourceException normal) { // normal case; resource doesn't exist yet so fall through } return super.createResource(context, operation); } @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { for (JcaCachedConnectionManagerDefinition.CcmParameters parameter : JcaCachedConnectionManagerDefinition.CcmParameters.values()) { parameter.getAttribute().validateAndSet(operation, model); } } @Override protected void recordCapabilitiesAndRequirements(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { // At the time of WFLY-2640/WFLY-8141 there were no capabilities associated with this resource, // but if anyone adds one, part of the task is to deal with possible reregistration. // So here's an assert to ensure that is considered Set<RuntimeCapability> capabilitySet = context.getResourceRegistration().getCapabilities(); assert capabilitySet.isEmpty(); } @Override protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final boolean debug = JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG.getAttribute().resolveModelAttribute(context, model).asBoolean(); final boolean error = JcaCachedConnectionManagerDefinition.CcmParameters.ERROR.getAttribute().resolveModelAttribute(context, model).asBoolean(); final boolean ignoreUnknownConnections = JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute().resolveModelAttribute(context, model).asBoolean(); final boolean install = JcaCachedConnectionManagerDefinition.CcmParameters.INSTALL.getAttribute().resolveModelAttribute(context, model).asBoolean(); final ServiceTarget serviceTarget = context.getServiceTarget(); if (install) { ROOT_LOGGER.debug("Enabling the Cache Connection Manager valve and interceptor..."); context.addStep(new AbstractDeploymentChainStep() { protected void execute(DeploymentProcessorTarget processorTarget) { processorTarget.addDeploymentProcessor(JcaExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_CACHED_CONNECTION_MANAGER, new CachedConnectionManagerSetupProcessor()); } }, OperationContext.Stage.RUNTIME); } else { ROOT_LOGGER.debug("Disabling the Cache Connection Manager valve and interceptor..."); } CachedConnectionManagerService ccmService = new CachedConnectionManagerService(debug, error, ignoreUnknownConnections); serviceTarget .addService(ConnectorServices.CCM_SERVICE, ccmService) .addDependency(context.getCapabilityServiceSupport().getCapabilityServiceName(ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME), TransactionIntegration.class, ccmService.getTransactionIntegrationInjector()) .install(); NonTxCachedConnectionManagerService noTxCcm = new NonTxCachedConnectionManagerService(debug, error, ignoreUnknownConnections); serviceTarget .addService(ConnectorServices.NON_TX_CCM_SERVICE, noTxCcm) .install(); } }
8,265
55.616438
197
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/Element.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import java.util.HashMap; import java.util.Map; /** * An Element. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public enum Element { /** always the first **/ UNKNOWN(null), /** archive-validation element **/ ARCHIVE_VALIDATION("archive-validation"), /** bean-validation element **/ BEAN_VALIDATION("bean-validation"), /** default-workmanager element **/ DEFAULT_WORKMANAGER("default-workmanager"), /** cached-connection-manager element **/ CACHED_CONNECTION_MANAGER("cached-connection-manager"), /** short-running-threads element **/ SHORT_RUNNING_THREADS("short-running-threads"), /** long-running-threads element **/ LONG_RUNNING_THREADS("long-running-threads"), /** workmanager element **/ WORKMANAGER("workmanager"), /** distributed workmanager element **/ DISTRIBUTED_WORKMANAGER("distributed-workmanager"), WORKMANAGERS("workmanagers"), /** bootstrap-contexts element **/ BOOTSTRAP_CONTEXTS("bootstrap-contexts"), BOOTSTRAP_CONTEXT("bootstrap-context"), POLICY("policy"), SELECTOR("selector"), OPTION("option"), TRACER("tracer"), /** elytron-enabled element **/ ELYTRON_ENABLED("elytron-enabled"); private final String name; Element(final String name) { this.name = name; } /** * Get the local name of this element. * @return the local name */ public String getLocalName() { return name; } private static final Map<String, Element> MAP; static { final Map<String, Element> map = new HashMap<String, Element>(); for (Element element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } public static Element forName(String localName) { final Element element = MAP.get(localName); return element == null ? UNKNOWN : element; } }
3,105
26.245614
74
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaBootstrapContextDefinition.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.BOOTSTRAP_CONTEXT; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReadResourceNameOperationStepHandler; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelType; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. */ public class JcaBootstrapContextDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_BOOTSTRAP_CONTEXT = PathElement.pathElement(BOOTSTRAP_CONTEXT); JcaBootstrapContextDefinition() { super(PATH_BOOTSTRAP_CONTEXT, JcaExtension.getResourceDescriptionResolver(PATH_BOOTSTRAP_CONTEXT.getKey()), BootstrapContextAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { super.registerAttributes(resourceRegistration); for (final BootstrapCtxParameters parameter : BootstrapCtxParameters.values()) { AttributeDefinition ad = parameter.getAttribute(); if (parameter == BootstrapCtxParameters.NAME) { resourceRegistration.registerReadOnlyAttribute(ad, ReadResourceNameOperationStepHandler.INSTANCE); } else { resourceRegistration.registerReadWriteAttribute(ad, null, new ReloadRequiredWriteAttributeHandler(ad)); } } } public enum BootstrapCtxParameters { NAME(SimpleAttributeDefinitionBuilder.create("name", ModelType.STRING) .setAllowExpression(false) .setRequired(true) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("name") .build()), WORKMANAGER(SimpleAttributeDefinitionBuilder.create("workmanager", ModelType.STRING) .setAllowExpression(true) .setRequired(true) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("workmanager") .build()); BootstrapCtxParameters(SimpleAttributeDefinition attribute) { this.attribute = attribute; } public SimpleAttributeDefinition getAttribute() { return attribute; } private SimpleAttributeDefinition attribute; } }
4,005
40.729167
115
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaConfigService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.jca.Version; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * A ConnectorConfigService. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ final class JcaConfigService implements Service<JcaSubsystemConfiguration> { private final JcaSubsystemConfiguration value; /** create an instance **/ public JcaConfigService(JcaSubsystemConfiguration value) { super(); this.value = value; } @Override public JcaSubsystemConfiguration getValue() throws IllegalStateException { return ConnectorServices.notNull(value); } @Override public void start(StartContext context) throws StartException { ROOT_LOGGER.startingSubsystem("Jakarta Connectors", Version.FULL_VERSION); ROOT_LOGGER.tracef("config=%s", value); } @Override public void stop(StopContext context) { } }
2,225
33.246154
82
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaSubsystemRootDefinition.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector._private.Capabilities.JCA_NAMING_CAPABILITY; import static org.jboss.as.connector.util.ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME; import static org.jboss.as.connector.util.ConnectorServices.LOCAL_TRANSACTION_PROVIDER_CAPABILITY; import static org.jboss.as.connector.util.ConnectorServices.TRANSACTION_SYNCHRONIZATION_REGISTRY_CAPABILITY; import static org.jboss.as.connector.util.ConnectorServices.TRANSACTION_XA_RESOURCE_RECOVERY_REGISTRY_CAPABILITY; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.jca.core.spi.transaction.TransactionIntegration; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. */ public class JcaSubsystemRootDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_SUBSYSTEM = PathElement.pathElement(SUBSYSTEM, JcaExtension.SUBSYSTEM_NAME); static final RuntimeCapability<Void> TRANSACTION_INTEGRATION_CAPABILITY = RuntimeCapability.Builder.of(TRANSACTION_INTEGRATION_CAPABILITY_NAME, TransactionIntegration.class) .addRequirements(LOCAL_TRANSACTION_PROVIDER_CAPABILITY, TRANSACTION_XA_RESOURCE_RECOVERY_REGISTRY_CAPABILITY, TRANSACTION_SYNCHRONIZATION_REGISTRY_CAPABILITY) .build(); private final boolean registerRuntimeOnly; private JcaSubsystemRootDefinition(final boolean registerRuntimeOnly) { super(new Parameters(PATH_SUBSYSTEM, JcaExtension.getResourceDescriptionResolver()) .setAddHandler(JcaSubsystemAdd.INSTANCE) .setRemoveHandler(JcaSubSystemRemove.INSTANCE) .setCapabilities(JCA_NAMING_CAPABILITY, TRANSACTION_INTEGRATION_CAPABILITY) ); this.registerRuntimeOnly = registerRuntimeOnly; } public static JcaSubsystemRootDefinition createInstance(final boolean registerRuntimeOnly) { return new JcaSubsystemRootDefinition(registerRuntimeOnly); } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); resourceRegistration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE); } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerSubModel(new JcaArchiveValidationDefinition()); resourceRegistration.registerSubModel(new JcaBeanValidationDefinition()); resourceRegistration.registerSubModel(new TracerDefinition()); resourceRegistration.registerSubModel(new JcaCachedConnectionManagerDefinition()); resourceRegistration.registerSubModel(JcaWorkManagerDefinition.createInstance(registerRuntimeOnly)); resourceRegistration.registerSubModel(JcaDistributedWorkManagerDefinition.createInstance(registerRuntimeOnly)); resourceRegistration.registerSubModel(new JcaBootstrapContextDefinition()); } }
4,490
52.464286
177
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/TracerAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * @author <a href="[email protected]">Jesper Pedersen</a> * @author <a href="[email protected]">Stefano Maestri</a> */ public class TracerAdd extends AbstractAddStepHandler { public static final TracerAdd INSTANCE = new TracerAdd(); @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { for (TracerDefinition.TracerParameters parameter : TracerDefinition.TracerParameters.values()) { parameter.getAttribute().validateAndSet(operation, model); } } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final boolean enabled = TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute().resolveModelAttribute(context, model).asBoolean(); ServiceName serviceName = ConnectorServices.TRACER_CONFIG_SERVICE; ServiceName jcaConfigServiceName = ConnectorServices.CONNECTOR_CONFIG_SERVICE; final ServiceTarget serviceTarget = context.getServiceTarget(); final TracerService.Tracer config = new TracerService.Tracer(enabled); final TracerService service = new TracerService(config); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(jcaConfigServiceName, JcaSubsystemConfiguration.class, service.getJcaConfigInjector()) .install(); } }
2,989
44.30303
149
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/BeanValidationService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class BeanValidationService implements Service<BeanValidationService.BeanValidation> { private final BeanValidation value; private final InjectedValue<JcaSubsystemConfiguration> jcaConfig = new InjectedValue<JcaSubsystemConfiguration>(); /** create an instance **/ public BeanValidationService(BeanValidation value) { this.value = value; } @Override public BeanValidation getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { jcaConfig.getValue().setBeanValidation(value.isEnabled()); } @Override public void stop(StopContext context) { } public Injector<JcaSubsystemConfiguration> getJcaConfigInjector() { return jcaConfig; } public static class BeanValidation { private final boolean enabled; public BeanValidation(boolean enabled) { this.enabled = enabled; } public boolean isEnabled() { return enabled; } } }
2,608
30.817073
122
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaExtension.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER; import static org.jboss.as.connector.subsystems.jca.Constants.ARCHIVE_VALIDATION; import static org.jboss.as.connector.subsystems.jca.Constants.BEAN_VALIDATION; import static org.jboss.as.connector.subsystems.jca.Constants.BOOTSTRAP_CONTEXT; import static org.jboss.as.connector.subsystems.jca.Constants.CACHED_CONNECTION_MANAGER; import static org.jboss.as.connector.subsystems.jca.Constants.DEFAULT_NAME; import static org.jboss.as.connector.subsystems.jca.Constants.DISTRIBUTED_WORKMANAGER; import static org.jboss.as.connector.subsystems.jca.Constants.JCA; import static org.jboss.as.connector.subsystems.jca.Constants.TRACER; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_LONG_RUNNING; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_SHORT_RUNNING; 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.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.parsing.ParseUtils.missingRequiredElement; import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent; import static org.jboss.as.controller.parsing.ParseUtils.requireSingleAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement; import java.util.ArrayList; import java.util.EnumSet; import java.util.List; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.jboss.as.connector.subsystems.jca.JcaArchiveValidationDefinition.ArchiveValidationParameters; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.Extension; import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.PropertiesAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SubsystemRegistration; import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; import org.jboss.as.controller.parsing.ExtensionParsingContext; import org.jboss.as.controller.parsing.ParseUtils; import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.as.threads.ThreadsParser; import org.jboss.dmr.ModelNode; import org.jboss.dmr.Property; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLElementWriter; import org.jboss.staxmapper.XMLExtendedStreamReader; import org.jboss.staxmapper.XMLExtendedStreamWriter; /** * @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author <a href="mailto:[email protected]">Darran Lofthouse</a> * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ public class JcaExtension implements Extension { public static final String SUBSYSTEM_NAME = "jca"; private static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(6, 0, 0); private static final String RESOURCE_NAME = JcaExtension.class.getPackage().getName() + ".LocalDescriptions"; static StandardResourceDescriptionResolver getResourceDescriptionResolver(final String... keyPrefix) { StringBuilder prefix = new StringBuilder(SUBSYSTEM_NAME); for (String kp : keyPrefix) { prefix.append('.').append(kp); } return new StandardResourceDescriptionResolver(prefix.toString(), RESOURCE_NAME, JcaExtension.class.getClassLoader(), true, false); } @Override public void initialize(final ExtensionContext context) { ROOT_LOGGER.debugf("Initializing Connector Extension"); final boolean registerRuntimeOnly = context.isRuntimeOnlyRegistrationValid(); final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION); subsystem.registerSubsystemModel(JcaSubsystemRootDefinition.createInstance(registerRuntimeOnly)); subsystem.registerXMLElementWriter(ConnectorSubsystemParser.INSTANCE); } @Override public void initializeParsers(final ExtensionParsingContext context) { context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_1_1.getUriString(), () -> ConnectorSubsystemParser.INSTANCE); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_2_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_3_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_4_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_5_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.JCA_6_0.getUriString(), () -> ConnectorSubsystemParser.INSTANCE); } static final class ConnectorSubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> { static final ConnectorSubsystemParser INSTANCE = new ConnectorSubsystemParser(); /** * {@inheritDoc} */ @Override public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { context.startSubsystemElement(Namespace.CURRENT.getUriString(), false); ModelNode node = context.getModelNode(); writeArchiveValidation(writer, node); writeBeanValidation(writer, node); writeTracer(writer, node); writeWorkManagers(writer, node); writeDistributedWorkManagers(writer, node); writeBootstrapContexts(writer, node); writeCachedConnectionManager(writer, node); writer.writeEndElement(); } private void writeArchiveValidation(XMLExtendedStreamWriter writer, ModelNode parentNode) throws XMLStreamException { if (parentNode.hasDefined(ARCHIVE_VALIDATION)) { ModelNode node = parentNode.get(ARCHIVE_VALIDATION).get(ARCHIVE_VALIDATION); if (ArchiveValidationParameters.ARCHIVE_VALIDATION_ENABLED.getAttribute().isMarshallable(node) || ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_ERROR.getAttribute().isMarshallable(node) || ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_WARN.getAttribute().isMarshallable(node)) { writer.writeEmptyElement(Element.ARCHIVE_VALIDATION.getLocalName()); ArchiveValidationParameters.ARCHIVE_VALIDATION_ENABLED.getAttribute().marshallAsAttribute(node, writer); ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_ERROR.getAttribute().marshallAsAttribute(node, writer); ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_WARN.getAttribute().marshallAsAttribute(node, writer); } } } private void writeBeanValidation(XMLExtendedStreamWriter writer, ModelNode parentNode) throws XMLStreamException { if (parentNode.hasDefined(BEAN_VALIDATION)) { ModelNode node = parentNode.get(BEAN_VALIDATION).get(BEAN_VALIDATION); if (JcaBeanValidationDefinition.BeanValidationParameters.BEAN_VALIDATION_ENABLED.getAttribute().isMarshallable(node)) { writer.writeEmptyElement(Element.BEAN_VALIDATION.getLocalName()); JcaBeanValidationDefinition.BeanValidationParameters.BEAN_VALIDATION_ENABLED.getAttribute().marshallAsAttribute(node, writer); } } } private void writeTracer(XMLExtendedStreamWriter writer, ModelNode parentNode) throws XMLStreamException { if (parentNode.hasDefined(TRACER)) { ModelNode node = parentNode.get(TRACER).get(TRACER); if (TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute().isMarshallable(node)) { writer.writeEmptyElement(Element.TRACER.getLocalName()); TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute().marshallAsAttribute(node, writer); } } } private void writeCachedConnectionManager(XMLExtendedStreamWriter writer, ModelNode parentNode) throws XMLStreamException { if (parentNode.hasDefined(CACHED_CONNECTION_MANAGER)) { ModelNode node = parentNode.get(CACHED_CONNECTION_MANAGER).get(CACHED_CONNECTION_MANAGER); final String name = JcaCachedConnectionManagerDefinition.CcmParameters.INSTALL.getAttribute().getName(); if (node.hasDefined(name) && node.get(name).asBoolean()) { writer.writeEmptyElement(Element.CACHED_CONNECTION_MANAGER.getLocalName()); JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG.getAttribute().marshallAsAttribute(node, writer); JcaCachedConnectionManagerDefinition.CcmParameters.ERROR.getAttribute().marshallAsAttribute(node, writer); JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute().marshallAsAttribute(node, writer); } } } private void writeDistributedWorkManagers(XMLExtendedStreamWriter writer, ModelNode parentNode) throws XMLStreamException { if (parentNode.hasDefined(DISTRIBUTED_WORKMANAGER) && !parentNode.get(DISTRIBUTED_WORKMANAGER).asList().isEmpty()) { ModelNode workManagers = parentNode.get(DISTRIBUTED_WORKMANAGER); for (String name : workManagers.keys()) { ModelNode workManager = workManagers.get(name); writer.writeStartElement(Element.DISTRIBUTED_WORKMANAGER.getLocalName()); ((SimpleAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute()).marshallAsAttribute(workManager, writer); JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute().marshallAsElement(workManager, writer); for (Property prop : workManager.asPropertyList()) { if (WORKMANAGER_LONG_RUNNING.equals(prop.getName()) && prop.getValue().isDefined() && !prop.getValue().asPropertyList().isEmpty()) { ThreadsParser.getInstance().writeBoundedQueueThreadPool(writer, prop.getValue().asProperty(), Element.LONG_RUNNING_THREADS.getLocalName(), false, true); } if (WORKMANAGER_SHORT_RUNNING.equals(prop.getName()) && prop.getValue().isDefined() && !prop.getValue().asPropertyList().isEmpty()) { ThreadsParser.getInstance().writeBoundedQueueThreadPool(writer, prop.getValue().asProperty(), Element.SHORT_RUNNING_THREADS.getLocalName(), false, true); } if ((JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().getName().equals(prop.getName()) && prop.getValue().isDefined()) || (JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().getName().equals(prop.getName()) && workManager.hasDefined(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute().getName()))) { writer.writeStartElement(Element.POLICY.getLocalName()); if (prop.getValue().isDefined() ) writer.writeAttribute(JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute().getXmlName(), prop.getValue().asString()); else writer.writeAttribute(JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute().getXmlName(), JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().getDefaultValue().asString()); if (workManager.hasDefined(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute().getName())) { for (Property option : workManager.get(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute().getName()).asPropertyList()) { writeProperty(writer, option.getName(), option .getValue().asString(), Element.OPTION.getLocalName()); } } writer.writeEndElement(); } if (JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR.getAttribute().getName().equals(prop.getName()) && prop.getValue().isDefined()) { writer.writeStartElement(Element.SELECTOR.getLocalName()); writer.writeAttribute(JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute().getXmlName(), prop.getValue().asString()); if (workManager.hasDefined(JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute().getName())) { for (Property option : workManager.get(JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute().getName()).asPropertyList()) { writeProperty(writer, option.getName(), option .getValue().asString(), Element.OPTION.getLocalName()); } } writer.writeEndElement(); } } writer.writeEndElement(); } } } private void writeWorkManagers(XMLExtendedStreamWriter writer, ModelNode parentNode) throws XMLStreamException { List<Property> workManagers; if (parentNode.hasDefined(WORKMANAGER) && !(workManagers = parentNode.get(WORKMANAGER).asPropertyList()).isEmpty()) { List<ModelNode> defaultFirst = new ArrayList<>(); for (Property prop : workManagers) { ModelNode workManager = prop.getValue(); if ("default".equals(workManager.get(NAME).asString())) { defaultFirst.add(0, workManager); } else { defaultFirst.add(workManager); } } for (int i = 0; i < defaultFirst.size(); i++) { ModelNode workManager = defaultFirst.get(i); if (i == 0 && "default".equals(workManager.get(NAME).asString())) { writer.writeStartElement(Element.DEFAULT_WORKMANAGER.getLocalName()); } else { writer.writeStartElement(Element.WORKMANAGER.getLocalName()); JcaWorkManagerDefinition.WmParameters.NAME.getAttribute().marshallAsAttribute(workManager, writer); } JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().marshallAsElement(workManager, writer); if (workManager.hasDefined(WORKMANAGER_SHORT_RUNNING)) { ThreadsParser.getInstance().writeBoundedQueueThreadPool(writer, workManager.get(WORKMANAGER_SHORT_RUNNING).asProperty(), Element.SHORT_RUNNING_THREADS.getLocalName(), false, true); } if (workManager.hasDefined(WORKMANAGER_LONG_RUNNING)) { ThreadsParser.getInstance().writeBoundedQueueThreadPool(writer, workManager.get(WORKMANAGER_LONG_RUNNING).asProperty(), Element.LONG_RUNNING_THREADS.getLocalName(), false, true); } writer.writeEndElement(); } } } private void writeBootstrapContexts(XMLExtendedStreamWriter writer, ModelNode parentNode) throws XMLStreamException { if (parentNode.hasDefined(BOOTSTRAP_CONTEXT) && !parentNode.get(BOOTSTRAP_CONTEXT).asList().isEmpty()) { boolean started = false; ModelNode contexts = parentNode.get(BOOTSTRAP_CONTEXT); for (String name : contexts.keys()) { ModelNode context = contexts.get(name); if (!context.get(JcaBootstrapContextDefinition.BootstrapCtxParameters.NAME.getAttribute().getName()).asString().equals(DEFAULT_NAME) && (JcaBootstrapContextDefinition.BootstrapCtxParameters.NAME.getAttribute().isMarshallable(context) || JcaBootstrapContextDefinition.BootstrapCtxParameters.WORKMANAGER.getAttribute().isMarshallable(context))) { if (!started) { writer.writeStartElement(Element.BOOTSTRAP_CONTEXTS.getLocalName()); started = true; } writer.writeStartElement(Element.BOOTSTRAP_CONTEXT.getLocalName()); JcaBootstrapContextDefinition.BootstrapCtxParameters.NAME.getAttribute().marshallAsAttribute(context, writer); JcaBootstrapContextDefinition.BootstrapCtxParameters.WORKMANAGER.getAttribute().marshallAsAttribute(context, writer); writer.writeEndElement(); } } if (started) { writer.writeEndElement(); } } } @Override public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException { final ModelNode address = new ModelNode(); address.add(org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM, JCA); address.protect(); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).set(address); list.add(subsystem); // Handle elements final EnumSet<Element> visited = EnumSet.noneOf(Element.class); final EnumSet<Element> requiredElement = EnumSet.of(Element.DEFAULT_WORKMANAGER); boolean ccmAdded = false; while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { Namespace readerNs = Namespace.forUri(reader.getNamespaceURI()); switch (readerNs) { case JCA_6_0: case JCA_5_0: case JCA_4_0: case JCA_3_0: case JCA_2_0: case JCA_1_1: { final Element element = Element.forName(reader.getLocalName()); if (!visited.add(element)) { throw unexpectedElement(reader); } switch (element) { case ARCHIVE_VALIDATION: { list.add(parseArchiveValidation(reader, address)); break; } case BEAN_VALIDATION: { list.add(parseBeanValidation(reader, address)); break; } case DEFAULT_WORKMANAGER: { parseWorkManager(reader, address, list, true, readerNs); final ModelNode bootstrapContextOperation = new ModelNode(); bootstrapContextOperation.get(OP).set(ADD); final ModelNode bootStrapCOntextAddress = address.clone(); bootStrapCOntextAddress.add(BOOTSTRAP_CONTEXT, DEFAULT_NAME); bootStrapCOntextAddress.protect(); bootstrapContextOperation.get(OP_ADDR).set(bootStrapCOntextAddress); bootstrapContextOperation.get(WORKMANAGER).set(DEFAULT_NAME); bootstrapContextOperation.get(NAME).set(DEFAULT_NAME); list.add(bootstrapContextOperation); requiredElement.remove(Element.DEFAULT_WORKMANAGER); break; } case CACHED_CONNECTION_MANAGER: { list.add(parseCcm(reader, address)); ccmAdded = true; break; } case WORKMANAGER: { parseWorkManager(reader, address, list, false, readerNs); // AS7-4434 Multiple work managers are allowed visited.remove(Element.WORKMANAGER); break; } case DISTRIBUTED_WORKMANAGER: { parseDistributedWorkManager(reader, address, list, readerNs); // AS7-4434 Multiple work managers are allowed visited.remove(Element.DISTRIBUTED_WORKMANAGER); break; } case BOOTSTRAP_CONTEXTS: { parseBootstrapContexts(reader, address, list); break; } case TRACER: { if (Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_3_0) || Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_4_0) || Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_5_0) || Namespace.forUri(reader.getNamespaceURI()).equals(Namespace.JCA_6_0)) { list.add(parseTracer(reader, address)); } else { throw unexpectedElement(reader); } break; } default: throw unexpectedElement(reader); } break; } default: throw unexpectedElement(reader); } } if (!requiredElement.isEmpty()) { throw missingRequiredElement(reader, requiredElement); } if (!ccmAdded) { final ModelNode ccmOperation = new ModelNode(); ccmOperation.get(OP).set(ADD); final ModelNode ccmAddress = address.clone(); ccmAddress.add(CACHED_CONNECTION_MANAGER, CACHED_CONNECTION_MANAGER); ccmAddress.protect(); ccmOperation.get(OP_ADDR).set(ccmAddress); assert ccmOperation.keys().size() == 2; // prevent people adding params without considering special // WFLY-2640/WFLY-8141 logic. This assert can be changed once // you've made the necessary adjustments list.add(ccmOperation); } } private ModelNode parseArchiveValidation(final XMLExtendedStreamReader reader, final ModelNode parentOperation) throws XMLStreamException { final ModelNode archiveValidationOperation = new ModelNode(); archiveValidationOperation.get(OP).set(ADD); final ModelNode archiveValidationAddress = parentOperation.clone(); archiveValidationAddress.add(ARCHIVE_VALIDATION, ARCHIVE_VALIDATION); archiveValidationAddress.protect(); archiveValidationOperation.get(OP_ADDR).set(archiveValidationAddress); final int cnt = reader.getAttributeCount(); for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { String value = rawAttributeText(reader, ArchiveValidationParameters.ARCHIVE_VALIDATION_ENABLED.getAttribute().getXmlName()); ArchiveValidationParameters.ARCHIVE_VALIDATION_ENABLED.getAttribute().parseAndSetParameter(value, archiveValidationOperation, reader); break; } case FAIL_ON_ERROR: { String value = rawAttributeText(reader, ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_ERROR.getAttribute().getXmlName()); ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_ERROR.getAttribute().parseAndSetParameter(value, archiveValidationOperation, reader); break; } case FAIL_ON_WARN: { String value = rawAttributeText(reader, ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_WARN.getAttribute().getXmlName()); ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_WARN.getAttribute().parseAndSetParameter(value, archiveValidationOperation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } // Handle elements requireNoContent(reader); return archiveValidationOperation; } private void parseWorkManager(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> list, boolean defaultWm, Namespace elementNs) throws XMLStreamException { final ModelNode workManagerOperation = new ModelNode(); workManagerOperation.get(OP).set(ADD); final int cnt = reader.getAttributeCount(); String name = null; for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { name = rawAttributeText(reader, JcaWorkManagerDefinition.WmParameters.NAME.getAttribute().getXmlName()); JcaWorkManagerDefinition.WmParameters.NAME.getAttribute().parseAndSetParameter(name, workManagerOperation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } if (name == null) { if (defaultWm) { name = DEFAULT_NAME; workManagerOperation.get(NAME).set(name); } else { throw new XMLStreamException("name attribute is mandatory for workmanager element"); } } final ModelNode workManagerAddress = parentAddress.clone(); workManagerAddress.add(WORKMANAGER, name); workManagerAddress.protect(); workManagerOperation.get(OP_ADDR).set(workManagerAddress); list.add(workManagerOperation); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); Namespace readerNS = Namespace.forUri(reader.getNamespaceURI()); switch (element) { case LONG_RUNNING_THREADS: { checkName(reader); org.jboss.as.threads.Namespace ns = org.jboss.as.threads.Namespace.THREADS_1_1; ThreadsParser.getInstance().parseBlockingBoundedQueueThreadPool(reader, readerNS.getUriString(), ns, workManagerAddress, list, WORKMANAGER_LONG_RUNNING, name); break; } case SHORT_RUNNING_THREADS: { checkName(reader); org.jboss.as.threads.Namespace ns = org.jboss.as.threads.Namespace.THREADS_1_1; ThreadsParser.getInstance().parseBlockingBoundedQueueThreadPool(reader, readerNS.getUriString(), ns, workManagerAddress, list, WORKMANAGER_SHORT_RUNNING, name); break; } case ELYTRON_ENABLED: { switch (readerNS) { case JCA_5_0: case JCA_6_0: { String value = rawElementText(reader); JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().parseAndSetParameter(value, workManagerOperation, reader); break; } default: { throw unexpectedElement(reader); } } break; } default: throw unexpectedElement(reader); } } // For older versions set 'elytron-enabled' to 'false' if not explicitly set, as that was the default in those xsds handleLegacyWorkManagerSecurity(workManagerOperation, JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute(), elementNs); } // WFLY-14587 private void checkName(final XMLExtendedStreamReader reader) throws XMLStreamException { int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { org.jboss.as.threads.Attribute attribute = org.jboss.as.threads.Attribute.forName(reader.getAttributeLocalName(i)); if (attribute.equals(org.jboss.as.threads.Attribute.NAME)) { throw unexpectedAttribute(reader, i); } } } private void parseDistributedWorkManager(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> list, Namespace elementNS) throws XMLStreamException { final ModelNode distributedWorkManagerOperation = new ModelNode(); distributedWorkManagerOperation.get(OP).set(ADD); final int cnt = reader.getAttributeCount(); String name = null; final AttributeDefinition attributeDefinition = JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute(); final String attributeName = attributeDefinition.getXmlName(); for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { name = rawAttributeText(reader, attributeName); ((SimpleAttributeDefinition) attributeDefinition).parseAndSetParameter(name, distributedWorkManagerOperation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } if (name == null) { throw ParseUtils.missingRequired(reader, attributeName); } final ModelNode distributedWorkManagerAddress = parentAddress.clone(); distributedWorkManagerAddress.add(DISTRIBUTED_WORKMANAGER, name); distributedWorkManagerAddress.protect(); distributedWorkManagerOperation.get(OP_ADDR).set(distributedWorkManagerAddress); list.add(distributedWorkManagerOperation); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); Namespace readerNS = Namespace.forUri(reader.getNamespaceURI()); switch (element) { case LONG_RUNNING_THREADS: { org.jboss.as.threads.Namespace ns = org.jboss.as.threads.Namespace.THREADS_1_1; ThreadsParser.getInstance().parseBlockingBoundedQueueThreadPool(reader, readerNS.getUriString(), ns, distributedWorkManagerAddress, list, WORKMANAGER_LONG_RUNNING, name); break; } case SHORT_RUNNING_THREADS: { org.jboss.as.threads.Namespace ns = org.jboss.as.threads.Namespace.THREADS_1_1; ThreadsParser.getInstance().parseBlockingBoundedQueueThreadPool(reader, readerNS.getUriString(), ns, distributedWorkManagerAddress, list, WORKMANAGER_SHORT_RUNNING, name); break; } case POLICY: { switch (readerNS) { case JCA_2_0: case JCA_3_0: case JCA_4_0: case JCA_5_0: case JCA_6_0:{ parsePolicy(reader, distributedWorkManagerOperation); break; } default: { throw unexpectedElement(reader); } } break; } case SELECTOR: { switch (readerNS) { case JCA_2_0: case JCA_3_0: case JCA_4_0: case JCA_5_0: case JCA_6_0:{ parseSelector(reader, distributedWorkManagerOperation); break; } default: { throw unexpectedElement(reader); } } break; } case ELYTRON_ENABLED: { switch (readerNS) { case JCA_5_0: case JCA_6_0: { String value = rawElementText(reader); ((SimpleAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute()).parseAndSetParameter(value, distributedWorkManagerOperation, reader); break; } default: { throw unexpectedElement(reader); } } break; } default: throw unexpectedElement(reader); } } // For older versions set 'elytron-enabled' to 'false' if not explicitly set, as that was the default in those xsds handleLegacyWorkManagerSecurity(distributedWorkManagerOperation, JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute(), elementNS); } private void parsePolicy(final XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException { final int cnt = reader.getAttributeCount(); for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { String policy = rawAttributeText(reader, attribute.getLocalName()); ((SimpleAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute()).parseAndSetParameter(policy, operation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); switch (element) { case OPTION: { requireSingleAttribute(reader, "name"); final String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final String trimmed = value == null ? null : value.trim(); ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute()).parseAndAddParameterElement(name, trimmed, operation, reader); break; } } // Handle elements } } private void parseSelector(final XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException { final int cnt = reader.getAttributeCount(); for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { String selector = rawAttributeText(reader, attribute.getLocalName()); ((SimpleAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR.getAttribute()).parseAndSetParameter(selector, operation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } // Handle elements while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); switch (element) { case OPTION: { requireSingleAttribute(reader, "name"); final String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final String trimmed = value == null ? null : value.trim(); ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute()).parseAndAddParameterElement(name, trimmed, operation, reader); break; } } // Handle elements } } private ModelNode parseBeanValidation(final XMLExtendedStreamReader reader, final ModelNode parentOperation) throws XMLStreamException { final ModelNode beanValidationOperation = new ModelNode(); beanValidationOperation.get(OP).set(ADD); final ModelNode beanValidationAddress = parentOperation.clone(); beanValidationAddress.add(BEAN_VALIDATION, BEAN_VALIDATION); beanValidationAddress.protect(); beanValidationOperation.get(OP_ADDR).set(beanValidationAddress); final int cnt = reader.getAttributeCount(); for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { String value = rawAttributeText(reader, JcaBeanValidationDefinition.BeanValidationParameters.BEAN_VALIDATION_ENABLED.getAttribute().getXmlName()); JcaBeanValidationDefinition.BeanValidationParameters.BEAN_VALIDATION_ENABLED.getAttribute().parseAndSetParameter(value, beanValidationOperation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } // Handle elements requireNoContent(reader); return beanValidationOperation; } private ModelNode parseTracer(final XMLExtendedStreamReader reader, final ModelNode parentOperation) throws XMLStreamException { final ModelNode tracerOperation = new ModelNode(); tracerOperation.get(OP).set(ADD); final ModelNode tracerAddress = parentOperation.clone(); tracerAddress.add(TRACER, TRACER); tracerAddress.protect(); tracerOperation.get(OP_ADDR).set(tracerAddress); final int cnt = reader.getAttributeCount(); for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { String value = rawAttributeText(reader, TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute().getXmlName()); TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute().parseAndSetParameter(value, tracerOperation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } // Handle elements requireNoContent(reader); return tracerOperation; } private ModelNode parseCcm(final XMLExtendedStreamReader reader, final ModelNode parentOperation) throws XMLStreamException { final ModelNode ccmOperation = new ModelNode(); ccmOperation.get(OP).set(ADD); final ModelNode ccmAddress = parentOperation.clone(); ccmAddress.add(CACHED_CONNECTION_MANAGER, CACHED_CONNECTION_MANAGER); ccmAddress.protect(); ccmOperation.get(OP_ADDR).set(ccmAddress); final int cnt = reader.getAttributeCount(); for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case DEBUG: { String value = rawAttributeText(reader, JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG.getAttribute().getXmlName()); JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG.getAttribute().parseAndSetParameter(value, ccmOperation, reader); break; } case ERROR: { String value = rawAttributeText(reader, JcaCachedConnectionManagerDefinition.CcmParameters.ERROR.getAttribute().getXmlName()); JcaCachedConnectionManagerDefinition.CcmParameters.ERROR.getAttribute().parseAndSetParameter(value, ccmOperation, reader); break; } case IGNORE_UNKNOWN_CONNECHIONS: { String value = rawAttributeText(reader, JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute().getXmlName()); JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute().parseAndSetParameter(value, ccmOperation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } ccmOperation.get(JcaCachedConnectionManagerDefinition.CcmParameters.INSTALL.getAttribute().getName()).set(true); // Handle elements requireNoContent(reader); return ccmOperation; } private void parseBootstrapContexts(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> list) throws XMLStreamException { while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); switch (element) { case BOOTSTRAP_CONTEXT: { ModelNode bootstrapContextOperation = new ModelNode(); bootstrapContextOperation.get(OP).set(ADD); final int cnt = reader.getAttributeCount(); String name = null; String wmName = null; for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { name = rawAttributeText(reader, JcaBootstrapContextDefinition.BootstrapCtxParameters.NAME.getAttribute().getXmlName()); JcaBootstrapContextDefinition.BootstrapCtxParameters.NAME.getAttribute().parseAndSetParameter(name, bootstrapContextOperation, reader); break; } case WORKMANAGER: { wmName = rawAttributeText(reader, JcaBootstrapContextDefinition.BootstrapCtxParameters.WORKMANAGER.getAttribute().getXmlName()); JcaBootstrapContextDefinition.BootstrapCtxParameters.WORKMANAGER.getAttribute().parseAndSetParameter(wmName, bootstrapContextOperation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } if (name == null) { if (DEFAULT_NAME.equals(wmName)) { name = DEFAULT_NAME; } else { throw new XMLStreamException("name attribute is mandatory for workmanager element"); } } final ModelNode bootstrapContextAddress = parentAddress.clone(); bootstrapContextAddress.add(BOOTSTRAP_CONTEXT, name); bootstrapContextAddress.protect(); bootstrapContextOperation.get(OP_ADDR).set(bootstrapContextAddress); // Handle elements requireNoContent(reader); list.add(bootstrapContextOperation); break; } default: { throw unexpectedElement(reader); } } } } public String rawAttributeText(XMLStreamReader reader, String attributeName) { String attributeString = reader.getAttributeValue("", attributeName) == null ? null : reader.getAttributeValue( "", attributeName) .trim(); return attributeString; } public String rawElementText(XMLStreamReader reader) throws XMLStreamException { String elementText = reader.getElementText(); elementText = elementText == null || elementText.trim().length() == 0 ? null : elementText.trim(); return elementText; } private void writeProperty(XMLExtendedStreamWriter writer, String name, String value, String localName) throws XMLStreamException { writer.writeStartElement(localName); writer.writeAttribute("name", name); writer.writeCharacters(value); writer.writeEndElement(); } private static void handleLegacyWorkManagerSecurity(ModelNode addOp, AttributeDefinition ad, Namespace ns) { if (!addOp.hasDefined(ad.getName())) { switch (ns) { case JCA_1_1: case JCA_2_0: case JCA_3_0: case JCA_4_0: case JCA_5_0: // set the old default value from these xsd versions addOp.get(ad.getName()).set(false); break; default: // unconfigured value in later namespaces matches current AttributeDefinition default break; } } } } }
51,126
51.871768
258
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/ConnectionValidatorService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import org.jboss.jca.core.connectionmanager.pool.validator.ConnectionValidator; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * Connection validator service * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ final class ConnectionValidatorService implements Service<ConnectionValidator> { /** * Constructor */ public ConnectionValidatorService() { } @Override public ConnectionValidator getValue() throws IllegalStateException { return ConnectionValidator.getInstance(); } @Override public void start(StartContext context) throws StartException { try { ConnectionValidator.getInstance().start(); } catch (Throwable t) { throw new StartException(t); } } @Override public void stop(StopContext context) { try { ConnectionValidator.getInstance().stop(); } catch (Throwable t) { // Ignore } } }
2,184
32.106061
80
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/DistributedWorkManagerAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_LONG_RUNNING; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_SHORT_RUNNING; import java.util.Map; import java.util.concurrent.Executor; import org.jboss.as.connector.services.workmanager.DistributedWorkManagerService; import org.jboss.as.connector.services.workmanager.NamedDistributedWorkManager; import org.jboss.as.connector.services.workmanager.statistics.DistributedWorkManagerStatisticsService; import org.jboss.as.connector.services.workmanager.statistics.WorkManagerStatisticsService; import org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.connector.util.Injection; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PropertiesAttributeDefinition; import org.jboss.as.controller.registry.Resource; import org.jboss.as.threads.ThreadsServices; import org.jboss.as.txn.integration.JBossContextXATerminator; import org.jboss.as.txn.service.TxnServices; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.workmanager.DistributedWorkManager; import org.jboss.jca.core.api.workmanager.WorkManager; import org.jboss.jca.core.workmanager.policy.Always; import org.jboss.jca.core.workmanager.policy.Never; import org.jboss.jca.core.workmanager.policy.WaterMark; import org.jboss.jca.core.workmanager.selector.FirstAvailable; import org.jboss.jca.core.workmanager.selector.MaxFreeThreads; import org.jboss.jca.core.workmanager.selector.PingTime; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.server.service.ClusteringDefaultRequirement; /** * @author <a href="[email protected]">Jesper Pedersen</a> * @author <a href="[email protected]">Stefano Maestri</a> */ public class DistributedWorkManagerAdd extends AbstractAddStepHandler { public static final DistributedWorkManagerAdd INSTANCE = new DistributedWorkManagerAdd(); private DistributedWorkManagerAdd() { super(JcaDistributedWorkManagerDefinition.DWmParameters.getAttributes()); } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException { ModelNode model = resource.getModel(); String name = JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute().resolveModelAttribute(context, model).asString(); boolean elytronEnabled = JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().resolveModelAttribute(context, resource.getModel()).asBoolean(); String policy = JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().resolveModelAttribute(context, model).asString(); String selector = JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR.getAttribute().resolveModelAttribute(context, model).asString(); ServiceTarget serviceTarget = context.getServiceTarget(); NamedDistributedWorkManager namedDistributedWorkManager = new NamedDistributedWorkManager(name, elytronEnabled); if (policy != null && !policy.trim().isEmpty()) { switch (JcaDistributedWorkManagerDefinition.PolicyValue.valueOf(policy)) { case NEVER: { namedDistributedWorkManager.setPolicy(new Never()); break; } case ALWAYS: { namedDistributedWorkManager.setPolicy(new Always()); break; } case WATERMARK: { namedDistributedWorkManager.setPolicy(new WaterMark()); break; } default: throw ROOT_LOGGER.unsupportedPolicy(policy); } Injection injector = new Injection(); for (Map.Entry<String, String> entry : ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute()).unwrap(context, model).entrySet()) { try { injector.inject(namedDistributedWorkManager.getPolicy(), entry.getKey(), entry.getValue()); } catch (Exception e) { ROOT_LOGGER.unsupportedPolicyOption(entry.getKey()); } } } else { namedDistributedWorkManager.setPolicy(new WaterMark()); } if (selector != null && !selector.trim().isEmpty()) { switch (JcaDistributedWorkManagerDefinition.SelectorValue.valueOf(selector)) { case FIRST_AVAILABLE: { namedDistributedWorkManager.setSelector(new FirstAvailable()); break; } case MAX_FREE_THREADS: { namedDistributedWorkManager.setSelector(new MaxFreeThreads()); break; } case PING_TIME: { namedDistributedWorkManager.setSelector(new PingTime()); break; } default: throw ROOT_LOGGER.unsupportedSelector(selector); } Injection injector = new Injection(); for (Map.Entry<String, String> entry : ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute()).unwrap(context, model).entrySet()) { try { injector.inject(namedDistributedWorkManager.getSelector(), entry.getKey(), entry.getValue()); } catch (Exception e) { ROOT_LOGGER.unsupportedSelectorOption(entry.getKey()); } } } else { namedDistributedWorkManager.setSelector(new PingTime()); } DistributedWorkManagerService wmService = new DistributedWorkManagerService(namedDistributedWorkManager); ServiceBuilder<NamedDistributedWorkManager> builder = serviceTarget .addService(ConnectorServices.WORKMANAGER_SERVICE.append(name), wmService); builder.addDependency(ClusteringDefaultRequirement.COMMAND_DISPATCHER_FACTORY.getServiceName(context), CommandDispatcherFactory.class, wmService.getCommandDispatcherFactoryInjector()); if (resource.hasChild(PathElement.pathElement(Element.LONG_RUNNING_THREADS.getLocalName()))) { builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING).append(name), Executor.class, wmService.getExecutorLongInjector()); } builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING).append(name), Executor.class, wmService.getExecutorShortInjector()); builder.addDependency(TxnServices.JBOSS_TXN_CONTEXT_XA_TERMINATOR, JBossContextXATerminator.class, wmService.getXaTerminatorInjector()) .setInitialMode(ServiceController.Mode.ON_DEMAND) .install(); WorkManagerStatisticsService wmStatsService = new WorkManagerStatisticsService(context.getResourceRegistrationForUpdate(), name, true); serviceTarget .addService(ConnectorServices.WORKMANAGER_STATS_SERVICE.append(name), wmStatsService) .addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(name), WorkManager.class, wmStatsService.getWorkManagerInjector()) .setInitialMode(ServiceController.Mode.PASSIVE).install(); DistributedWorkManagerStatisticsService dwmStatsService = new DistributedWorkManagerStatisticsService(context.getResourceRegistrationForUpdate(), name, true); serviceTarget .addService(ConnectorServices.DISTRIBUTED_WORKMANAGER_STATS_SERVICE.append(name), dwmStatsService) .addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(name), DistributedWorkManager.class, dwmStatsService.getDistributedWorkManagerInjector()) .setInitialMode(ServiceController.Mode.PASSIVE).install(); PathElement peDistributedWm = PathElement.pathElement(org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_NAME, "distributed"); PathElement peLocaldWm = PathElement.pathElement(org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_NAME, "local"); final Resource wmResource = new IronJacamarResource.IronJacamarRuntimeResource(); if (!resource.hasChild(peLocaldWm)) resource.registerChild(peLocaldWm, wmResource); final Resource dwmResource = new IronJacamarResource.IronJacamarRuntimeResource(); if (!resource.hasChild(peDistributedWm)) resource.registerChild(peDistributedWm, dwmResource); } }
10,230
54.907104
203
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaCachedConnectionManagerDefinition.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.CACHED_CONNECTION_MANAGER; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleOperationDefinition; import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.transform.description.DiscardAttributeChecker; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. */ public class JcaCachedConnectionManagerDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_CACHED_CONNECTION_MANAGER = PathElement.pathElement(CACHED_CONNECTION_MANAGER, CACHED_CONNECTION_MANAGER); JcaCachedConnectionManagerDefinition() { super(PATH_CACHED_CONNECTION_MANAGER, JcaExtension.getResourceDescriptionResolver(PATH_CACHED_CONNECTION_MANAGER.getKey()), CachedConnectionManagerAdd.INSTANCE, CachedConnectionManagerRemove.INSTANCE); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { super.registerAttributes(resourceRegistration); for (final CcmParameters parameter : CcmParameters.values()) { if (parameter != CcmParameters.INSTALL) { resourceRegistration.registerReadWriteAttribute(parameter.getAttribute(), null, JcaCachedConnectionManagerWriteHandler.INSTANCE); } else { AttributeDefinition ad = parameter.getAttribute(); resourceRegistration.registerReadWriteAttribute(ad, null, new ReloadRequiredWriteAttributeHandler(ad)); } } } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); resourceRegistration.registerOperationHandler(CcmOperations.GET_NUMBER_OF_CONNECTIONS.getOperation(), GetNumberOfConnectionsHandler.INSTANCE); resourceRegistration.registerOperationHandler(CcmOperations.LIST_CONNECTIONS.getOperation(), ListOfConnectionsHandler.INSTANCE); } static void registerTransformers110(ResourceTransformationDescriptionBuilder parentBuilder) { ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_CACHED_CONNECTION_MANAGER); builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.ALWAYS, CcmParameters.IGNORE_UNKNOWN_CONNECTIONS.getAttribute()); } public enum CcmParameters { DEBUG(SimpleAttributeDefinitionBuilder.create("debug", ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("debug") .build()), ERROR(SimpleAttributeDefinitionBuilder.create("error", ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("error") .build()), IGNORE_UNKNOWN_CONNECTIONS(SimpleAttributeDefinitionBuilder.create("ignore-unknown-connections", ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("ignore-unknown-connections") .build()), INSTALL(SimpleAttributeDefinitionBuilder.create("install", ModelType.BOOLEAN) .setAllowExpression(false) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .build()); CcmParameters(SimpleAttributeDefinition attribute) { this.attribute = attribute; } public SimpleAttributeDefinition getAttribute() { return attribute; } private SimpleAttributeDefinition attribute; } public enum CcmOperations { GET_NUMBER_OF_CONNECTIONS(new SimpleOperationDefinitionBuilder("get-number-of-connections", JcaExtension.getResourceDescriptionResolver(PATH_CACHED_CONNECTION_MANAGER.getKey())) .setRuntimeOnly() .setReadOnly() .build()), LIST_CONNECTIONS(new SimpleOperationDefinitionBuilder("list-connections", JcaExtension.getResourceDescriptionResolver(PATH_CACHED_CONNECTION_MANAGER.getKey())) .setRuntimeOnly() .setReadOnly() .build()); CcmOperations(SimpleOperationDefinition operation) { this.operation = operation; } public SimpleOperationDefinition getOperation() { return operation; } private SimpleOperationDefinition operation; } }
6,833
42.807692
185
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/CachedConnectionManagerRemove.java
package org.jboss.as.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.JcaCachedConnectionManagerDefinition.CcmParameters.DEBUG; import static org.jboss.as.connector.subsystems.jca.JcaCachedConnectionManagerDefinition.CcmParameters.ERROR; import static org.jboss.as.connector.subsystems.jca.JcaCachedConnectionManagerDefinition.CcmParameters.IGNORE_UNKNOWN_CONNECTIONS; import static org.jboss.as.connector.subsystems.jca.JcaCachedConnectionManagerDefinition.CcmParameters.INSTALL; import java.util.Set; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.dmr.ModelNode; class CachedConnectionManagerRemove implements OperationStepHandler { static final CachedConnectionManagerRemove INSTANCE = new CachedConnectionManagerRemove(); private CachedConnectionManagerRemove() {} @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // This is an odd case where we do not actually do a remove; we just reset state to // what it would be following parsing if the xml element does not exist. // See discussion on PR with fix for WFLY-2640 . ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); for (JcaCachedConnectionManagerDefinition.CcmParameters param : JcaCachedConnectionManagerDefinition.CcmParameters.values()) { AttributeDefinition ad = param.getAttribute(); if (param == INSTALL || param == DEBUG || param == ERROR || param == IGNORE_UNKNOWN_CONNECTIONS) { model.get(ad.getName()).clear(); } else { // Someone added a new param since wFLY-2640/WFLY-8141 and did not account for it above throw new IllegalStateException(); } } // At the time of WFLY-2640 there were no capabilities associated with this resource, // but if anyone adds one, part of the task is to deal with deregistration. // So here's an assert to ensure that is considered Set<RuntimeCapability> capabilitySet = context.getResourceRegistration().getCapabilities(); assert capabilitySet.isEmpty(); if (context.isDefaultRequiresRuntime()) { context.addStep(new OperationStepHandler() { @Override public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException { context.reloadRequired(); context.completeStep(new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext operationContext, ModelNode modelNode) { context.revertReloadRequired(); } }); } }, OperationContext.Stage.RUNTIME); } } }
3,203
49.0625
134
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/ArchiveValidationService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class ArchiveValidationService implements Service<ArchiveValidationService.ArchiveValidation> { private final ArchiveValidation value; private final InjectedValue<JcaSubsystemConfiguration> jcaConfig = new InjectedValue<JcaSubsystemConfiguration>(); /** create an instance **/ public ArchiveValidationService(ArchiveValidation value) { this.value = value; } @Override public ArchiveValidation getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { jcaConfig.getValue().setArchiveValidation(value.isEnabled()); jcaConfig.getValue().setArchiveValidationFailOnError(value.isFailOnError()); jcaConfig.getValue().setArchiveValidationFailOnWarn(value.isFailOnWarn()); } @Override public void stop(StopContext context) { } public Injector<JcaSubsystemConfiguration> getJcaConfigInjector() { return jcaConfig; } public static class ArchiveValidation { private final boolean enabled; private final boolean failOnError; private final boolean failOnWarn; public ArchiveValidation(boolean enabled, boolean failOnError, boolean failOnWarn) { this.enabled = enabled; this.failOnError = failOnError; this.failOnWarn = failOnWarn; } public boolean isEnabled() { return enabled; } public boolean isFailOnError() { return failOnError; } public boolean isFailOnWarn() { return failOnWarn; } } }
3,192
32.260417
122
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/TracerWriteHandler.java
/* * 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * {@link org.jboss.as.controller.OperationStepHandler} for the {@code write-attribute} operation for the * {@link TracerDefinition tracer resource}. * * @author Brian Stansberry (c) 2012 Red Hat Inc. */ public class TracerWriteHandler extends AbstractWriteAttributeHandler<JcaSubsystemConfiguration> { static TracerWriteHandler INSTANCE = new TracerWriteHandler(); private TracerWriteHandler() { super(TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute()); } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<JcaSubsystemConfiguration> jcaSubsystemConfigurationHandbackHolder) throws OperationFailedException { JcaSubsystemConfiguration config = (JcaSubsystemConfiguration) context.getServiceRegistry(true).getService(ConnectorServices.CONNECTOR_CONFIG_SERVICE).getValue(); if (attributeName.equals(TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute().getName())) { config.setTracer(resolvedValue.asBoolean()); } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, JcaSubsystemConfiguration handback) throws OperationFailedException { JcaSubsystemConfiguration config = (JcaSubsystemConfiguration) context.getServiceRegistry(true).getService(ConnectorServices.CONNECTOR_CONFIG_SERVICE).getValue(); if (attributeName.equals(TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute().getName())) { config.setTracer(valueToRestore.asBoolean()); } } }
3,106
46.075758
277
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/ArchiveValidationAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractBoottimeAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * @author <a href="[email protected]">Jesper Pedersen</a> * @author <a href="[email protected]">Stefano Maestri</a> */ public class ArchiveValidationAdd extends AbstractBoottimeAddStepHandler { public static final ArchiveValidationAdd INSTANCE = new ArchiveValidationAdd(); @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { for (JcaArchiveValidationDefinition.ArchiveValidationParameters parameter : JcaArchiveValidationDefinition.ArchiveValidationParameters.values() ) { parameter.getAttribute().validateAndSet(operation,model); } } @Override protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final boolean enabled = JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_ENABLED.getAttribute().resolveModelAttribute(context, model).asBoolean(); final boolean failOnError = JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_ERROR.getAttribute().resolveModelAttribute(context, model).asBoolean(); final boolean failOnWarn = JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_WARN.getAttribute().resolveModelAttribute(context, model).asBoolean(); ServiceName serviceName = ConnectorServices.ARCHIVE_VALIDATION_CONFIG_SERVICE; ServiceName jcaConfigServiceName = ConnectorServices.CONNECTOR_CONFIG_SERVICE; final ServiceTarget serviceTarget = context.getServiceTarget(); final ArchiveValidationService.ArchiveValidation config = new ArchiveValidationService.ArchiveValidation(enabled, failOnError, failOnWarn); final ArchiveValidationService service = new ArchiveValidationService(config); ServiceController<?> controller = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(jcaConfigServiceName, JcaSubsystemConfiguration.class, service.getJcaConfigInjector() ) .install(); } }
3,661
53.656716
193
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/TracerDefinition.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.TRACER; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. * @author Stefano Maestri */ public class TracerDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_TRACER = PathElement.pathElement(TRACER, TRACER); TracerDefinition() { super(PATH_TRACER, JcaExtension.getResourceDescriptionResolver(PATH_TRACER.getKey()), TracerAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { super.registerAttributes(resourceRegistration); for (final TracerParameters parameter : TracerParameters.values()) { resourceRegistration.registerReadWriteAttribute(parameter.getAttribute(), null, TracerWriteHandler.INSTANCE); } } public enum TracerParameters { TRACER_ENABLED(SimpleAttributeDefinitionBuilder.create("enabled", ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .build()); TracerParameters(SimpleAttributeDefinition attribute) { this.attribute = attribute; } public SimpleAttributeDefinition getAttribute() { return attribute; } private SimpleAttributeDefinition attribute; } }
3,189
37.902439
121
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/BootstrapContextAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.DEFAULT_NAME; import org.jboss.as.connector.services.bootstrap.BootStrapContextService; import org.jboss.as.connector.services.bootstrap.NamedBootstrapContext; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.txn.integration.JBossContextXATerminator; import org.jboss.as.txn.service.TxnServices; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext; import org.jboss.jca.core.api.workmanager.WorkManager; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceTarget; /** * @author <a href="[email protected]">Jesper Pedersen</a> * @author <a href="[email protected]">Stefano Maestri</a> */ public class BootstrapContextAdd extends AbstractAddStepHandler { public static final BootstrapContextAdd INSTANCE = new BootstrapContextAdd(); @Override protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { for (JcaBootstrapContextDefinition.BootstrapCtxParameters parameter : JcaBootstrapContextDefinition.BootstrapCtxParameters.values()) { parameter.getAttribute().validateAndSet(operation, model); } } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { String name = JcaBootstrapContextDefinition.BootstrapCtxParameters.NAME.getAttribute().resolveModelAttribute(context, model).asString(); String workmanager = JcaBootstrapContextDefinition.BootstrapCtxParameters.WORKMANAGER.getAttribute().resolveModelAttribute(context, model).asString(); boolean usingDefaultWm = false; CloneableBootstrapContext ctx; if (DEFAULT_NAME.equals(workmanager)) { usingDefaultWm = true; ctx = new NamedBootstrapContext(name); } else { ctx = new NamedBootstrapContext(name, workmanager); } ServiceTarget serviceTarget = context.getServiceTarget(); final BootStrapContextService bootCtxService = new BootStrapContextService(ctx, name, usingDefaultWm); serviceTarget .addService(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(name), bootCtxService) .addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(workmanager), WorkManager.class, bootCtxService.getWorkManagerValueInjector()) .addDependency(TxnServices.JBOSS_TXN_CONTEXT_XA_TERMINATOR, JBossContextXATerminator.class, bootCtxService.getXaTerminatorInjector()) .addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER, com.arjuna.ats.jbossatx.jta.TransactionManagerService.class, bootCtxService.getTxManagerInjector()) .addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, bootCtxService.getJcaConfigInjector()) .setInitialMode(ServiceController.Mode.ACTIVE) .install(); } }
4,399
52.012048
188
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/TracerService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * A ResourceAdaptersService. * * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class TracerService implements Service<TracerService.Tracer> { private final Tracer value; private final InjectedValue<JcaSubsystemConfiguration> jcaConfig = new InjectedValue<JcaSubsystemConfiguration>(); /** * create an instance * */ public TracerService(Tracer value) { this.value = value; } @Override public Tracer getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { jcaConfig.getValue().setTracer(value.isEnabled()); } @Override public void stop(StopContext context) { } public Injector<JcaSubsystemConfiguration> getJcaConfigInjector() { return jcaConfig; } public static class Tracer { private final boolean enabled; public Tracer(boolean enabled) { this.enabled = enabled; } public boolean isEnabled() { return enabled; } } }
2,468
28.047059
118
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaBeanValidationDefinition.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.BEAN_VALIDATION; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. * @author Stefano Maestri */ public class JcaBeanValidationDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_BEAN_VALIDATION = PathElement.pathElement(BEAN_VALIDATION, BEAN_VALIDATION); JcaBeanValidationDefinition() { super(PATH_BEAN_VALIDATION, JcaExtension.getResourceDescriptionResolver(PATH_BEAN_VALIDATION.getKey()), BeanValidationAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { super.registerAttributes(resourceRegistration); for (final BeanValidationParameters parameter : BeanValidationParameters.values()) { resourceRegistration.registerReadWriteAttribute(parameter.getAttribute(), null, JcaBeanValidationWriteHandler.INSTANCE); } } public enum BeanValidationParameters { BEAN_VALIDATION_ENABLED(SimpleAttributeDefinitionBuilder.create("enabled", ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.TRUE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("enabled") .build()); BeanValidationParameters(SimpleAttributeDefinition attribute) { this.attribute = attribute; } public SimpleAttributeDefinition getAttribute() { return attribute; } private SimpleAttributeDefinition attribute; } }
3,363
39.53012
132
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaArchiveValidationWriteHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * Write Handler for Jakarta Connectors config attribute * * @author Stefano Maestri */ class JcaArchiveValidationWriteHandler extends AbstractWriteAttributeHandler<JcaSubsystemConfiguration> { static JcaArchiveValidationWriteHandler INSTANCE = new JcaArchiveValidationWriteHandler(); private JcaArchiveValidationWriteHandler() { super( JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_ENABLED.getAttribute(), JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_ERROR.getAttribute(), JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_WARN.getAttribute() ); } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<JcaSubsystemConfiguration> jcaSubsystemConfigurationHandbackHolder) throws OperationFailedException { JcaSubsystemConfiguration config = (JcaSubsystemConfiguration) context.getServiceRegistry(true).getService(ConnectorServices.CONNECTOR_CONFIG_SERVICE).getValue(); if (attributeName.equals(JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_ENABLED.getAttribute().getName())) { config.setArchiveValidation(resolvedValue.asBoolean()); } else if (attributeName.equals(JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_ERROR.getAttribute().getName())) { config.setArchiveValidationFailOnError(resolvedValue.asBoolean()); } else if (attributeName.equals(JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_WARN.getAttribute().getName())) { config.setArchiveValidationFailOnWarn(resolvedValue.asBoolean()); } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, JcaSubsystemConfiguration handback) throws OperationFailedException { JcaSubsystemConfiguration config = (JcaSubsystemConfiguration) context.getServiceRegistry(true).getService(ConnectorServices.CONNECTOR_CONFIG_SERVICE).getValue(); if (attributeName.equals(JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_ENABLED.getAttribute().getName())) { config.setArchiveValidation(valueToRestore.asBoolean()); }else if (attributeName.equals(JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_ERROR.getAttribute().getName())) { config.setArchiveValidationFailOnError(valueToRestore.asBoolean()); } else if (attributeName.equals(JcaArchiveValidationDefinition.ArchiveValidationParameters.ARCHIVE_VALIDATION_FAIL_ON_WARN.getAttribute().getName())) { config.setArchiveValidationFailOnWarn(valueToRestore.asBoolean()); } } }
4,390
55.294872
277
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaSubSystemRemove.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractRemoveStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationStepHandler; import org.jboss.dmr.ModelNode; /** * @author @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ public class JcaSubSystemRemove extends AbstractRemoveStepHandler { static final OperationStepHandler INSTANCE = new JcaSubSystemRemove(); protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) { context.removeService(ConnectorServices.CONNECTOR_CONFIG_SERVICE); } protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) { // TODO: RE-ADD SERVICES } }
1,891
39.255319
100
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaWorkManagerDefinition.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.ELYTRON_ENABLED_NAME; import static org.jboss.as.connector.subsystems.jca.Constants.ELYTRON_MANAGED_SECURITY; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_LONG_RUNNING; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_SHORT_RUNNING; import static org.jboss.as.controller.OperationContext.Stage.MODEL; import java.util.Arrays; import java.util.Set; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.api.common.Security; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReadResourceNameOperationStepHandler; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.as.threads.BoundedQueueThreadPoolAdd; import org.jboss.as.threads.BoundedQueueThreadPoolRemove; import org.jboss.as.threads.BoundedQueueThreadPoolResourceDefinition; import org.jboss.as.threads.CommonAttributes; import org.jboss.as.threads.ThreadsServices; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.msc.service.ServiceName; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. */ public class JcaWorkManagerDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_WORK_MANAGER = PathElement.pathElement(WORKMANAGER); private final boolean registerRuntimeOnly; private JcaWorkManagerDefinition(final boolean registerRuntimeOnly) { super(PATH_WORK_MANAGER, JcaExtension.getResourceDescriptionResolver(PATH_WORK_MANAGER.getKey()), WorkManagerAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE); this.registerRuntimeOnly = registerRuntimeOnly; } public static JcaWorkManagerDefinition createInstance(final boolean registerRuntimeOnly) { return new JcaWorkManagerDefinition(registerRuntimeOnly); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { super.registerAttributes(resourceRegistration); resourceRegistration.registerReadOnlyAttribute(WmParameters.NAME.getAttribute(), ReadResourceNameOperationStepHandler.INSTANCE); resourceRegistration.registerReadOnlyAttribute(WmParameters.ELYTRON_ENABLED.getAttribute(), null); } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { registerSubModels(resourceRegistration, registerRuntimeOnly); } static void registerSubModels(ManagementResourceRegistration resourceRegistration, boolean runtimeOnly) { final BoundedQueueThreadPoolAdd shortRunningThreadPoolAdd = new BoundedQueueThreadPoolAdd(true, ThreadsServices.STANDARD_THREAD_FACTORY_RESOLVER, ThreadsServices.STANDARD_HANDOFF_EXECUTOR_RESOLVER, ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING)) { @Override protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException { super.populateModel(context, operation, resource); context.addStep(new OperationStepHandler(){ public void execute(OperationContext oc, ModelNode op) throws OperationFailedException { checkThreadPool(oc, op, WORKMANAGER_SHORT_RUNNING); } }, MODEL); } }; resourceRegistration.registerSubModel( new JCAThreadPoolResourceDefinition(true, runtimeOnly, WORKMANAGER_SHORT_RUNNING, ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING), CommonAttributes.BLOCKING_BOUNDED_QUEUE_THREAD_POOL, shortRunningThreadPoolAdd, ReloadRequiredRemoveStepHandler.INSTANCE)); final BoundedQueueThreadPoolAdd longRunningThreadPoolAdd = new BoundedQueueThreadPoolAdd(true, ThreadsServices.STANDARD_THREAD_FACTORY_RESOLVER, ThreadsServices.STANDARD_HANDOFF_EXECUTOR_RESOLVER, ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING)) { @Override protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException { super.populateModel(context, operation, resource); context.addStep(new OperationStepHandler(){ public void execute(OperationContext oc, ModelNode op) throws OperationFailedException { checkThreadPool(oc, op, WORKMANAGER_LONG_RUNNING); } }, MODEL); } }; resourceRegistration.registerSubModel( new JCAThreadPoolResourceDefinition(true, runtimeOnly, WORKMANAGER_LONG_RUNNING, ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING), CommonAttributes.BLOCKING_BOUNDED_QUEUE_THREAD_POOL, longRunningThreadPoolAdd, new BoundedQueueThreadPoolRemove(longRunningThreadPoolAdd))); } private static class JCAThreadPoolResourceDefinition extends BoundedQueueThreadPoolResourceDefinition { @SuppressWarnings("deprecation") protected JCAThreadPoolResourceDefinition(boolean blocking, boolean registerRuntimeOnly, String type, ServiceName serviceNameBase, String resolverPrefix, OperationStepHandler addHandler, OperationStepHandler removeHandler) { super(blocking, registerRuntimeOnly, type, serviceNameBase, resolverPrefix, addHandler, removeHandler); } } private static void checkThreadPool(final OperationContext context, final ModelNode operation, final String type) throws OperationFailedException { PathAddress threadPoolPath = context.getCurrentAddress(); PathAddress workManagerPath = threadPoolPath.getParent(); Set<String> entrySet = context.readResourceFromRoot(workManagerPath, false).getChildrenNames(type); if (!entrySet.isEmpty() && !entrySet.iterator().next().equals(threadPoolPath.getLastElement().getValue())) { throw ConnectorLogger.ROOT_LOGGER.oneThreadPoolWorkManager(threadPoolPath.getLastElement().getValue(), type, workManagerPath.getLastElement().getValue()); } if(!context.getCurrentAddressValue().equals(workManagerPath.getLastElement().getValue())) { throw ConnectorLogger.ROOT_LOGGER.threadPoolNameMustMatchWorkManagerName(threadPoolPath.getLastElement().getValue(), type, workManagerPath.getLastElement().getValue()); } } public enum WmParameters { NAME(SimpleAttributeDefinitionBuilder.create("name", ModelType.STRING) .setAllowExpression(false) .setRequired(true) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("name") .build()), ELYTRON_ENABLED(new SimpleAttributeDefinitionBuilder(ELYTRON_ENABLED_NAME, ModelType.BOOLEAN, true) .setXmlName(Security.Tag.ELYTRON_ENABLED.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(ELYTRON_MANAGED_SECURITY)) .build()); WmParameters(SimpleAttributeDefinition attribute) { this.attribute = attribute; } public SimpleAttributeDefinition getAttribute() { return attribute; } private SimpleAttributeDefinition attribute; static AttributeDefinition[] getAttributes() { return Arrays.stream(WmParameters.values()).map(WmParameters::getAttribute).toArray(AttributeDefinition[]::new); } } }
9,640
50.833333
180
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaSubsystemAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.JcaSubsystemRootDefinition.TRANSACTION_INTEGRATION_CAPABILITY; import static org.jboss.as.connector.util.ConnectorServices.LOCAL_TRANSACTION_PROVIDER_CAPABILITY; import static org.jboss.as.connector.util.ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME; import static org.jboss.as.connector.util.ConnectorServices.TRANSACTION_SYNCHRONIZATION_REGISTRY_CAPABILITY; import static org.jboss.as.connector.util.ConnectorServices.TRANSACTION_XA_RESOURCE_RECOVERY_REGISTRY_CAPABILITY; import java.util.function.Consumer; import java.util.function.Supplier; import jakarta.transaction.TransactionSynchronizationRegistry; import org.jboss.as.connector.deployers.ra.RaDeploymentActivator; import org.jboss.as.connector.services.driver.registry.DriverRegistryService; import org.jboss.as.connector.services.transactionintegration.TransactionIntegrationService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractBoottimeAddStepHandler; import org.jboss.as.controller.CapabilityServiceBuilder; import org.jboss.as.controller.CapabilityServiceTarget; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.ProcessType; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.naming.service.NamingService; import org.jboss.as.server.AbstractDeploymentChainStep; import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.as.txn.integration.JBossContextXATerminator; import org.jboss.as.txn.service.TxnServices; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.tm.XAResourceRecoveryRegistry; import org.jboss.tm.usertx.UserTransactionRegistry; /** * Jakarta Connectors subsystem * * @author @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author @author <a href="mailto:[email protected]">Jesper Pedersen</a> * @author <a href="mailto:[email protected]">Richard Opalka</a> */ class JcaSubsystemAdd extends AbstractBoottimeAddStepHandler { static final JcaSubsystemAdd INSTANCE = new JcaSubsystemAdd(); protected void populateModel(ModelNode operation, ModelNode model) { } protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) { final boolean appclient = context.getProcessType() == ProcessType.APPLICATION_CLIENT; final boolean legacySecurityAvailable = context.hasOptionalCapability("org.wildfly.legacy-security", null, null); final RaDeploymentActivator raDeploymentActivator = new RaDeploymentActivator(appclient, legacySecurityAvailable); context.addStep(new AbstractDeploymentChainStep() { protected void execute(DeploymentProcessorTarget processorTarget) { raDeploymentActivator.activateProcessors(processorTarget); } }, OperationContext.Stage.RUNTIME); final CapabilityServiceTarget serviceTarget = context.getCapabilityServiceTarget(); final CapabilityServiceBuilder<?> sb = serviceTarget.addCapability(TRANSACTION_INTEGRATION_CAPABILITY); final Consumer<TransactionIntegration> tiConsumer = sb.provides(TRANSACTION_INTEGRATION_CAPABILITY, ConnectorServices.TRANSACTION_INTEGRATION_SERVICE); sb.requiresCapability(LOCAL_TRANSACTION_PROVIDER_CAPABILITY, Void.class); final Supplier<TransactionSynchronizationRegistry> tsrSupplier = sb.requiresCapability(TRANSACTION_SYNCHRONIZATION_REGISTRY_CAPABILITY, TransactionSynchronizationRegistry.class); final Supplier<UserTransactionRegistry> utrSupplier = sb.requires(TxnServices.JBOSS_TXN_USER_TRANSACTION_REGISTRY); final Supplier<JBossContextXATerminator> terminatorSupplier = sb.requires(TxnServices.JBOSS_TXN_CONTEXT_XA_TERMINATOR); final Supplier<XAResourceRecoveryRegistry> rrSupplier = sb.requiresCapability(TRANSACTION_XA_RESOURCE_RECOVERY_REGISTRY_CAPABILITY, XAResourceRecoveryRegistry.class); final TransactionIntegrationService tiService = new TransactionIntegrationService(tiConsumer, tsrSupplier, utrSupplier, terminatorSupplier, rrSupplier); sb.setInstance(tiService); sb.install(); // Cache the some capability service names for use by our runtime services final CapabilityServiceSupport support = context.getCapabilityServiceSupport(); ConnectorServices.registerCapabilityServiceName(LOCAL_TRANSACTION_PROVIDER_CAPABILITY, support.getCapabilityServiceName(LOCAL_TRANSACTION_PROVIDER_CAPABILITY)); ConnectorServices.registerCapabilityServiceName(NamingService.CAPABILITY_NAME, support.getCapabilityServiceName(NamingService.CAPABILITY_NAME)); ConnectorServices.registerCapabilityServiceName(TRANSACTION_INTEGRATION_CAPABILITY_NAME, support.getCapabilityServiceName(TRANSACTION_INTEGRATION_CAPABILITY_NAME)); final JcaSubsystemConfiguration config = new JcaSubsystemConfiguration(); final JcaConfigService connectorConfigService = new JcaConfigService(config); serviceTarget.addService(ConnectorServices.CONNECTOR_CONFIG_SERVICE).setInstance(connectorConfigService).install(); final IdleRemoverService idleRemoverService = new IdleRemoverService(); serviceTarget.addService(ConnectorServices.IDLE_REMOVER_SERVICE).setInstance(idleRemoverService).install(); final ConnectionValidatorService connectionValidatorService = new ConnectionValidatorService(); serviceTarget.addService(ConnectorServices.CONNECTION_VALIDATOR_SERVICE).setInstance(connectionValidatorService).install(); // TODO: Does the install of this and the DriverProcessor belong in DataSourcesSubsystemAdd? final DriverRegistryService driverRegistryService = new DriverRegistryService(); serviceTarget.addService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).setInstance(driverRegistryService).install(); raDeploymentActivator.activateServices(serviceTarget); } }
7,110
58.258333
187
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaSubsystemConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.connector.subsystems.jca; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import org.jboss.jca.core.api.bootstrap.CloneableBootstrapContext; import org.jboss.jca.core.tracer.Tracer; import org.jboss.jca.deployers.common.Configuration; /** * Configuration * * @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ public class JcaSubsystemConfiguration implements Configuration { /** Preform Jakarta Bean Validation */ private final AtomicBoolean beanValidation = new AtomicBoolean(true); /** Preform archive validation */ private final AtomicBoolean archiveValidation = new AtomicBoolean(true); /** Archive validation: Fail on Warn */ private final AtomicBoolean archiveValidationFailOnWarn = new AtomicBoolean(false); /** Archive validation: Fail on Error */ private final AtomicBoolean archiveValidationFailOnError = new AtomicBoolean(true); /** Default bootstrap context */ private CloneableBootstrapContext defaultBootstrapContext; /** Bootstrap contexts */ private Map<String, CloneableBootstrapContext> bootstrapContexts = new HashMap<String, CloneableBootstrapContext>(0); /** * Create a new ConnectorSubsystemConfiguration. */ public JcaSubsystemConfiguration() { } /** * Set if Jakarta Bean Validation should be performed * @param value The value */ public void setBeanValidation(boolean value) { beanValidation.set(value); } /** * Should Jakarta Bean Validation be performed * @return True if validation; otherwise false */ public boolean getBeanValidation() { return beanValidation.get(); } /** * Set if tracer should be performed * * @param value The value */ public void setTracer(boolean value) { Tracer.setEnabled(value); } /** * Should Jakarta Bean Validation be performed * * @return True if validation; otherwise false */ public boolean getTracer() { return Tracer.isEnabled(); } /** * Set if archive validation should be performed * @param value The value */ public void setArchiveValidation(boolean value) { archiveValidation.set(value); } /** * Should archive validation be performed * @return True if validation; otherwise false */ public boolean getArchiveValidation() { return archiveValidation.get(); } /** * Set if a failed warning archive validation report should fail the * deployment * @param value The value */ public void setArchiveValidationFailOnWarn(boolean value) { archiveValidationFailOnWarn.set(value); } /** * Does a failed archive validation warning report fail the deployment * @return True if failing; otherwise false */ public boolean getArchiveValidationFailOnWarn() { return archiveValidationFailOnWarn.get(); } /** * Set if a failed error archive validation report should fail the * deployment * @param value The value */ public void setArchiveValidationFailOnError(boolean value) { archiveValidationFailOnError.set(value); } /** * Does a failed archive validation error report fail the deployment * @return True if failing; otherwise false */ public boolean getArchiveValidationFailOnError() { return archiveValidationFailOnError.get(); } @Override public void setDefaultBootstrapContext(CloneableBootstrapContext value) { this.defaultBootstrapContext = value; } @Override public CloneableBootstrapContext getDefaultBootstrapContext() { return this.defaultBootstrapContext; } @Override public void setBootstrapContexts(Map<String, CloneableBootstrapContext> value) { this.bootstrapContexts = value; } @Override public Map<String, CloneableBootstrapContext> getBootstrapContexts() { return bootstrapContexts; } }
5,207
29.635294
121
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/Attribute.java
/* * 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.connector.subsystems.jca; import java.util.HashMap; import java.util.Map; /** * An Attribute. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public enum Attribute { /** always the first **/ UNKNOWN(null), ENABLED("enabled"), /** * fail-on-error attribute */ FAIL_ON_ERROR("fail-on-error"), /** * fail-on-warn attribute */ FAIL_ON_WARN("fail-on-warn"), SHORT_RUNNING_THREAD_POOL("short-running-thread-pool"), LONG_RUNNING_THREAD_POOL("long-running-thread-pool"), DEBUG("debug"), ERROR("error"), IGNORE_UNKNOWN_CONNECHIONS("ignore-unknown-connections"), NAME("name"), WORKMANAGER("workmanager"), JGROUPS_STACK("jgroups-stack"), JGROUPS_CLUSTER("jgroups-cluster"), REQUEST_TIMEOUT("request-timeout"); private final String name; Attribute(final String name) { this.name = name; } /** * Get the local name of this element. * @return the local name */ public String getLocalName() { return name; } private static final Map<String, Attribute> MAP; static { final Map<String, Attribute> map = new HashMap<String, Attribute>(); for (Attribute element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } public static Attribute forName(String localName) { final Attribute element = MAP.get(localName); return element == null ? UNKNOWN : element; } @Override public String toString() { return getLocalName(); } }
2,735
25.563107
76
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/GetNumberOfConnectionsHandler.java
/* * 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; /** * * @author Stefano Maestri (c) 2011 Red Hat Inc. */ public class GetNumberOfConnectionsHandler implements OperationStepHandler { public static final GetNumberOfConnectionsHandler INSTANCE = new GetNumberOfConnectionsHandler(); private GetNumberOfConnectionsHandler() { } @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ModelNode result = new ModelNode(); CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.CCM_SERVICE).getValue(); ModelNode txResult = new ModelNode().set(ccm.getNumberOfConnections()); ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.NON_TX_CCM_SERVICE).getValue(); ModelNode nonTxResult = new ModelNode().set(ccm.getNumberOfConnections()); result.get(Constants.TX).set(txResult); result.get(Constants.NON_TX).set(nonTxResult); context.getResult().set(result); } }, OperationContext.Stage.RUNTIME); } } }
2,908
39.402778
163
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaBeanValidationWriteHandler.java
/* * 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * {@link org.jboss.as.controller.OperationStepHandler} for the {@code write-attribute} operation for the * {@link JcaArchiveValidationDefinition Jakarta Bean Validation resource}. * * @author Brian Stansberry (c) 2012 Red Hat Inc. */ public class JcaBeanValidationWriteHandler extends AbstractWriteAttributeHandler<JcaSubsystemConfiguration> { static JcaBeanValidationWriteHandler INSTANCE = new JcaBeanValidationWriteHandler(); private JcaBeanValidationWriteHandler() { super(JcaBeanValidationDefinition.BeanValidationParameters.BEAN_VALIDATION_ENABLED.getAttribute()); } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<JcaSubsystemConfiguration> jcaSubsystemConfigurationHandbackHolder) throws OperationFailedException { JcaSubsystemConfiguration config = (JcaSubsystemConfiguration) context.getServiceRegistry(true).getService(ConnectorServices.CONNECTOR_CONFIG_SERVICE).getValue(); if (attributeName.equals(JcaBeanValidationDefinition.BeanValidationParameters.BEAN_VALIDATION_ENABLED.getAttribute().getName())) { config.setBeanValidation(resolvedValue.asBoolean()); } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, JcaSubsystemConfiguration handback) throws OperationFailedException { JcaSubsystemConfiguration config = (JcaSubsystemConfiguration) context.getServiceRegistry(true).getService(ConnectorServices.CONNECTOR_CONFIG_SERVICE).getValue(); if (attributeName.equals(JcaBeanValidationDefinition.BeanValidationParameters.BEAN_VALIDATION_ENABLED.getAttribute().getName())) { config.setBeanValidation(valueToRestore.asBoolean()); } } }
3,281
48.727273
277
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaTransformers.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.JcaDistributedWorkManagerDefinition.PATH_DISTRIBUTED_WORK_MANAGER; import static org.jboss.as.connector.subsystems.jca.JcaExtension.SUBSYSTEM_NAME; import static org.jboss.as.connector.subsystems.jca.JcaWorkManagerDefinition.PATH_WORK_MANAGER; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.transform.ExtensionTransformerRegistration; import org.jboss.as.controller.transform.SubsystemTransformerRegistration; import org.jboss.as.controller.transform.description.AttributeConverter; import org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder; public class JcaTransformers implements ExtensionTransformerRegistration { private static final ModelVersion EAP_7_4 = ModelVersion.create(5, 0, 0); @Override public String getSubsystemName() { return SUBSYSTEM_NAME; } @Override public void registerTransformers(SubsystemTransformerRegistration subsystemRegistration) { ChainedTransformationDescriptionBuilder chainedBuilder = TransformationDescriptionBuilder.Factory.createChainedSubystemInstance(subsystemRegistration.getCurrentSubsystemVersion()); get500TransformationDescription(chainedBuilder.createBuilder(subsystemRegistration.getCurrentSubsystemVersion(), EAP_7_4)); chainedBuilder.buildAndRegister(subsystemRegistration, new ModelVersion[]{ EAP_7_4 }); } private static void get500TransformationDescription(ResourceTransformationDescriptionBuilder parentBuilder) { parentBuilder.addChildResource(PATH_WORK_MANAGER) .getAttributeBuilder() .setValueConverter(AttributeConverter.DEFAULT_VALUE, JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute()) .end(); parentBuilder.addChildResource(PATH_DISTRIBUTED_WORK_MANAGER) .getAttributeBuilder() .setValueConverter(AttributeConverter.DEFAULT_VALUE, JcaDistributedWorkManagerDefinition.DWmParameters.ELYTRON_ENABLED.getAttribute()) .end(); } }
3,422
49.338235
188
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/Namespace.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.jca; import java.util.HashMap; import java.util.Map; /** * A Namespace. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ public enum Namespace { // must be first UNKNOWN(null), JCA_1_1("urn:jboss:domain:jca:1.1"), JCA_2_0("urn:jboss:domain:jca:2.0"), JCA_3_0("urn:jboss:domain:jca:3.0"), JCA_4_0("urn:jboss:domain:jca:4.0"), JCA_5_0("urn:jboss:domain:jca:5.0"), JCA_6_0("urn:jboss:domain:jca:6.0"); /** * The current namespace version. */ public static final Namespace CURRENT = JCA_6_0; private final String name; Namespace(final String name) { this.name = name; } /** * Get the URI of this namespace. * @return the URI */ public String getUriString() { return name; } private static final Map<String, Namespace> MAP; static { final Map<String, Namespace> map = new HashMap<String, Namespace>(); for (Namespace namespace : values()) { final String name = namespace.getUriString(); if (name != null) map.put(name, namespace); } MAP = map; } public static Namespace forUri(String uri) { final Namespace element = MAP.get(uri); return element == null ? UNKNOWN : element; } }
2,419
27.139535
76
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaDistributedWorkManagerDefinition.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.DISTRIBUTED_WORKMANAGER; import static org.jboss.as.connector.subsystems.jca.Constants.ELYTRON_BY_DEFAULT_VERSION; import static org.jboss.as.connector.subsystems.jca.Constants.ELYTRON_ENABLED_NAME; import static org.jboss.as.connector.subsystems.jca.Constants.ELYTRON_MANAGED_SECURITY; import static org.jboss.as.connector.subsystems.jca.JcaWorkManagerDefinition.registerSubModels; import java.util.Arrays; import java.util.EnumSet; import org.jboss.as.connector.metadata.api.common.Security; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PropertiesAttributeDefinition; import org.jboss.as.controller.ReadResourceNameOperationStepHandler; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.operations.validation.EnumValidator; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.wildfly.clustering.server.service.ClusteringDefaultRequirement; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. */ public class JcaDistributedWorkManagerDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_DISTRIBUTED_WORK_MANAGER = PathElement.pathElement(DISTRIBUTED_WORKMANAGER); private final boolean registerRuntimeOnly; private JcaDistributedWorkManagerDefinition(final boolean registerRuntimeOnly) { super(PATH_DISTRIBUTED_WORK_MANAGER, JcaExtension.getResourceDescriptionResolver(PATH_DISTRIBUTED_WORK_MANAGER.getKey()), DistributedWorkManagerAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE); this.registerRuntimeOnly = registerRuntimeOnly; } public static JcaDistributedWorkManagerDefinition createInstance(final boolean registerRuntimeOnly) { return new JcaDistributedWorkManagerDefinition(registerRuntimeOnly); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { super.registerAttributes(resourceRegistration); for (final AttributeDefinition ad : DWmParameters.getReadOnlyAttributeDefinitions()) { resourceRegistration.registerReadOnlyAttribute(ad, ReadResourceNameOperationStepHandler.INSTANCE); } for (final AttributeDefinition ad : DWmParameters.getRuntimeAttributeDefinitions()) { resourceRegistration.registerReadWriteAttribute(ad, null, JcaDistributedWorkManagerWriteHandler.INSTANCE); } } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { registerSubModels(resourceRegistration, registerRuntimeOnly); } @Override public void registerCapabilities(ManagementResourceRegistration registration) { super.registerCapabilities(registration); for (DWmCapabilities capability : EnumSet.allOf(DWmCapabilities.class)) { registration.registerCapability(capability.getRuntimeCapability()); } } enum DWmParameters { NAME(SimpleAttributeDefinitionBuilder.create("name", ModelType.STRING) .setAllowExpression(false) .setRequired(true) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("name") .build()), SELECTOR(SimpleAttributeDefinitionBuilder.create("selector", ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName(Element.SELECTOR.getLocalName()) .setValidator(EnumValidator.create(SelectorValue.class)) .setDefaultValue(new ModelNode(SelectorValue.PING_TIME.name())) .build()), POLICY(SimpleAttributeDefinitionBuilder.create("policy", ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName(Element.POLICY.getLocalName()) .setValidator(EnumValidator.create(PolicyValue.class)) .setDefaultValue(new ModelNode(PolicyValue.WATERMARK.name())) .build()), POLICY_OPTIONS(new PropertiesAttributeDefinition.Builder("policy-options", true) .setAllowExpression(true) .setXmlName(Element.OPTION.getLocalName()) .build()), SELECTOR_OPTIONS(new PropertiesAttributeDefinition.Builder("selector-options", true) .setAllowExpression(true) .setXmlName(Element.OPTION.getLocalName()) .build()), ELYTRON_ENABLED(new SimpleAttributeDefinitionBuilder(ELYTRON_ENABLED_NAME, ModelType.BOOLEAN, true) .setXmlName(Security.Tag.ELYTRON_ENABLED.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(ELYTRON_MANAGED_SECURITY)) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .build()); public static AttributeDefinition[] getAttributeDefinitions() { final AttributeDefinition[] returnValue = new AttributeDefinition[DWmParameters.values().length]; int i = 0; for (DWmParameters entry : DWmParameters.values()) { returnValue[i] = entry.getAttribute(); i++; } return returnValue; } public static AttributeDefinition[] getRuntimeAttributeDefinitions() { return new AttributeDefinition[]{ POLICY.getAttribute(), SELECTOR.getAttribute(), POLICY_OPTIONS.getAttribute(), SELECTOR_OPTIONS.getAttribute(), ELYTRON_ENABLED.getAttribute() }; } public static AttributeDefinition[] getReadOnlyAttributeDefinitions() { return new AttributeDefinition[]{ NAME.getAttribute() }; } DWmParameters(AttributeDefinition attribute) { this.attribute = attribute; } public AttributeDefinition getAttribute() { return attribute; } private AttributeDefinition attribute; static AttributeDefinition[] getAttributes() { return Arrays.stream(DWmParameters.values()).map(DWmParameters::getAttribute).toArray(AttributeDefinition[]::new); } } enum DWmCapabilities { CHANNEL_FACTORY(RuntimeCapability.Builder.of("org.wildfly.connector.workmanager", true).addRequirements(ClusteringDefaultRequirement.COMMAND_DISPATCHER_FACTORY.getName()).build()); private final RuntimeCapability<Void> capability; DWmCapabilities(RuntimeCapability<Void> capability) { this.capability = capability; } RuntimeCapability<Void> getRuntimeCapability() { return this.capability; } } public enum PolicyValue { NEVER, ALWAYS, WATERMARK } public enum SelectorValue { FIRST_AVAILABLE, PING_TIME, MAX_FREE_THREADS } }
8,804
42.161765
188
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/ListOfConnectionsHandler.java
/* * 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.connector.subsystems.jca; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import java.util.Map; /** * * @author Stefano Maestri (c) 2011 Red Hat Inc. */ public class ListOfConnectionsHandler implements OperationStepHandler { public static final ListOfConnectionsHandler INSTANCE = new ListOfConnectionsHandler(); private ListOfConnectionsHandler() { } @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ModelNode result = new ModelNode(); CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.CCM_SERVICE).getValue(); Map<String, String> map = ccm.listConnections(); ModelNode txResult = new ModelNode(); for (Map.Entry<String, String> entry : map.entrySet()) { txResult.add(entry.getKey(), entry.getValue()); } ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.NON_TX_CCM_SERVICE).getValue(); map= ccm.listConnections(); ModelNode nonTxResult = new ModelNode(); for (Map.Entry<String, String> entry : map.entrySet()) { nonTxResult.add(entry.getKey(), entry.getValue()); } result.get(Constants.TX).set(txResult); result.get(Constants.NON_TX).set(nonTxResult); context.getResult().set(result); } }, OperationContext.Stage.RUNTIME); } } }
3,304
39.802469
163
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/JcaArchiveValidationDefinition.java
/* * 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.ARCHIVE_VALIDATION; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. */ public class JcaArchiveValidationDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_ARCHIVE_VALIDATION = PathElement.pathElement(ARCHIVE_VALIDATION, ARCHIVE_VALIDATION); JcaArchiveValidationDefinition() { super(PATH_ARCHIVE_VALIDATION, JcaExtension.getResourceDescriptionResolver(PATH_ARCHIVE_VALIDATION.getKey()), ArchiveValidationAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { super.registerAttributes(resourceRegistration); for (final ArchiveValidationParameters parameter : ArchiveValidationParameters.values()) { resourceRegistration.registerReadWriteAttribute(parameter.getAttribute(), null, JcaArchiveValidationWriteHandler.INSTANCE); } } public enum ArchiveValidationParameters { ARCHIVE_VALIDATION_ENABLED(SimpleAttributeDefinitionBuilder.create("enabled", ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.TRUE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("enabled") .build()), ARCHIVE_VALIDATION_FAIL_ON_ERROR(SimpleAttributeDefinitionBuilder.create("fail-on-error", ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.TRUE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("fail-on-error") .build()), ARCHIVE_VALIDATION_FAIL_ON_WARN(SimpleAttributeDefinitionBuilder.create("fail-on-warn", ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setMeasurementUnit(MeasurementUnit.NONE) .setRestartAllServices() .setXmlName("fail-on-warn") .build()); ArchiveValidationParameters(SimpleAttributeDefinition attribute) { this.attribute = attribute; } public SimpleAttributeDefinition getAttribute() { return attribute; } private SimpleAttributeDefinition attribute; } }
4,208
42.391753
135
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/jca/WorkManagerAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.jca; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_LONG_RUNNING; import static org.jboss.as.connector.subsystems.jca.Constants.WORKMANAGER_SHORT_RUNNING; import java.util.concurrent.Executor; import org.jboss.as.connector.services.workmanager.NamedWorkManager; import org.jboss.as.connector.services.workmanager.WorkManagerService; import org.jboss.as.connector.services.workmanager.statistics.WorkManagerStatisticsService; import org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.Resource; import org.jboss.as.threads.ThreadsServices; import org.jboss.as.txn.integration.JBossContextXATerminator; import org.jboss.as.txn.service.TxnServices; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.workmanager.WorkManager; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceTarget; /** * @author <a href="[email protected]">Jesper Pedersen</a> * @author <a href="[email protected]">Stefano Maestri</a> */ public class WorkManagerAdd extends AbstractAddStepHandler { public static final WorkManagerAdd INSTANCE = new WorkManagerAdd(); private WorkManagerAdd() { super(JcaWorkManagerDefinition.WmParameters.getAttributes()); } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException { String name = JcaWorkManagerDefinition.WmParameters.NAME.getAttribute().resolveModelAttribute(context, resource.getModel()).asString(); ServiceTarget serviceTarget = context.getServiceTarget(); NamedWorkManager wm = new NamedWorkManager(name); WorkManagerService wmService = new WorkManagerService(wm); ServiceBuilder builder = serviceTarget .addService(ConnectorServices.WORKMANAGER_SERVICE.append(name), wmService); if (resource.hasChild(PathElement.pathElement(Element.LONG_RUNNING_THREADS.getLocalName()))) { builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING).append(name), Executor.class, wmService.getExecutorLongInjector()); } builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING).append(name), Executor.class, wmService.getExecutorShortInjector()); builder.addDependency(TxnServices.JBOSS_TXN_CONTEXT_XA_TERMINATOR, JBossContextXATerminator.class, wmService.getXaTerminatorInjector()) .setInitialMode(ServiceController.Mode.ON_DEMAND) .install(); WorkManagerStatisticsService wmStatsService = new WorkManagerStatisticsService(context.getResourceRegistrationForUpdate(), name, true); serviceTarget .addService(ConnectorServices.WORKMANAGER_STATS_SERVICE.append(name), wmStatsService) .addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(name), WorkManager.class, wmStatsService.getWorkManagerInjector()) .setInitialMode(ServiceController.Mode.PASSIVE).install(); PathElement peLocaldWm = PathElement.pathElement(org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_NAME, "local"); final Resource wmResource = new IronJacamarResource.IronJacamarRuntimeResource(); if (!resource.hasChild(peLocaldWm)) resource.registerChild(peLocaldWm, wmResource); } }
4,824
48.742268
159
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/Constants.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DISABLE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ENABLE; import org.jboss.as.connector._private.Capabilities; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.metadata.api.common.Security; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.ObjectListAttributeDefinition; import org.jboss.as.controller.ObjectTypeAttributeDefinition; import org.jboss.as.controller.PrimitiveListAttributeDefinition; import org.jboss.as.controller.PropertiesAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleOperationDefinition; import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.access.constraint.SensitivityClassification; import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.descriptions.NonResolvingResourceDescriptionResolver; import org.jboss.as.controller.operations.validation.StringLengthValidator; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.security.CredentialReference; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.jca.common.api.metadata.Defaults; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.common.XaPool; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.Driver; import org.jboss.jca.common.api.metadata.ds.DsPool; import org.jboss.jca.common.api.metadata.ds.Statement; import org.jboss.jca.common.api.metadata.ds.TimeOut; import org.jboss.jca.common.api.metadata.ds.Validation; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import java.util.Arrays; import java.util.stream.Stream; /** * Defines contants and attributes for datasources subsystem. * * @author @author <a href="mailto:[email protected]">Stefano * Maestri</a> * @author Flavia Rainone */ public class Constants { private static final Boolean ELYTRON_MANAGED_SECURITY = Boolean.FALSE; private static final ModelVersion ELYTRON_BY_DEFAULT_VERSION = ModelVersion.create(6, 1, 0); public static final String DATASOURCES = "datasources"; static final String DATA_SOURCE = "data-source"; static final String XA_DATASOURCE = "xa-data-source"; private static final String CONNECTION_URL_NAME = "connection-url"; static final String JDBC_DRIVER_NAME = "jdbc-driver"; private static final String DATASOURCE_DRIVER_CLASS_NAME = "driver-class"; private static final String DATASOURCE_CLASS_NAME = "datasource-class"; private static final String DATASOURCE_DRIVER_NAME = "driver-name"; static final String DRIVER_NAME_NAME = "driver-name"; private static final String DRIVER_MODULE_NAME_NAME = "driver-module-name"; private static final String DRIVER_MAJOR_VERSION_NAME = "driver-major-version"; private static final String DRIVER_MINOR_VERSION_NAME = "driver-minor-version"; private static final String DRIVER_CLASS_NAME_NAME = "driver-class-name"; private static final String DRIVER_DATASOURCE_CLASS_NAME_NAME = "driver-datasource-class-name"; private static final String DRIVER_XA_DATASOURCE_CLASS_NAME_NAME = "driver-xa-datasource-class-name"; private static final String CONNECTION_PROPERTIES_NAME = "connection-properties"; private static final String CONNECTION_PROPERTY_VALUE_NAME = "value"; private static final String NEW_CONNECTION_SQL_NAME = "new-connection-sql"; private static final String TRANSACTION_ISOLATION_NAME = "transaction-isolation"; private static final String URL_DELIMITER_NAME = "url-delimiter"; private static final String URL_PROPERTY_NAME = "url-property"; private static final String URL_SELECTOR_STRATEGY_CLASS_NAME_NAME = "url-selector-strategy-class-name"; private static final String CONNECTABLE_NAME = "connectable"; private static final String MCP_NAME = "mcp"; private static final String ENLISTMENT_TRACE_NAME = "enlistment-trace"; private static final String TRACKING_NAME = "tracking"; static final String POOLNAME_NAME = "pool-name"; private static final String ENABLED_NAME = "enabled"; private static final String JTA_NAME = "jta"; private static final String ALLOCATION_RETRY_NAME = "allocation-retry"; private static final String ALLOCATION_RETRY_WAIT_MILLIS_NAME = "allocation-retry-wait-millis"; private static final String ALLOW_MULTIPLE_USERS_NAME = "allow-multiple-users"; private static final String CONNECTION_LISTENER_CLASS_NAME = "connection-listener-class"; private static final String CONNECTION_LISTENER_PROPERTY_NAME = "connection-listener-property"; private static final String SETTXQUERYTIMEOUT_NAME = "set-tx-query-timeout"; private static final String XA_RESOURCE_TIMEOUT_NAME = "xa-resource-timeout"; private static final String QUERYTIMEOUT_NAME = "query-timeout"; private static final String USETRYLOCK_NAME = "use-try-lock"; private static final String USERNAME_NAME = "user-name"; private static final String PASSWORD_NAME = "password"; private static final String SECURITY_DOMAIN_NAME = "security-domain"; private static final String ELYTRON_ENABLED_NAME = "elytron-enabled"; private static final String AUTHENTICATION_CONTEXT_NAME = "authentication-context"; private static final String SHAREPREPAREDSTATEMENTS_NAME = "share-prepared-statements"; private static final String PREPAREDSTATEMENTSCACHESIZE_NAME = "prepared-statements-cache-size"; private static final String TRACKSTATEMENTS_NAME = "track-statements"; private static final String VALID_CONNECTION_CHECKER_CLASSNAME_NAME = "valid-connection-checker-class-name"; private static final String VALID_CONNECTION_CHECKER_MODULE_NAME = "valid-connection-checker-module"; private static final String CHECKVALIDCONNECTIONSQL_NAME = "check-valid-connection-sql"; private static final String VALIDATEONMATCH_NAME = "validate-on-match"; private static final String SPY_NAME = "spy"; private static final String USE_CCM_NAME = "use-ccm"; private static final String STALECONNECTIONCHECKERCLASSNAME_NAME = "stale-connection-checker-class-name"; private static final String STALECONNECTIONCHECKERMODULE_NAME = "stale-connection-checker-module"; private static final String EXCEPTIONSORTERCLASSNAME_NAME = "exception-sorter-class-name"; private static final String EXCEPTIONSORTERMODULE_NAME = "exception-sorter-module"; private static final String XADATASOURCEPROPERTIES_NAME = "xa-datasource-properties"; private static final String XADATASOURCEPROPERTIES_VALUE_NAME = "value"; private static final String XADATASOURCECLASS_NAME = "xa-datasource-class"; private static final String INTERLEAVING_NAME = "interleaving"; private static final String NOTXSEPARATEPOOL_NAME = "no-tx-separate-pool"; private static final String PAD_XID_NAME = "pad-xid"; private static final String SAME_RM_OVERRIDE_NAME = "same-rm-override"; private static final String WRAP_XA_RESOURCE_NAME = "wrap-xa-resource"; private static final String EXCEPTIONSORTER_PROPERTIES_NAME = "exception-sorter-properties"; private static final String STALECONNECTIONCHECKER_PROPERTIES_NAME = "stale-connection-checker-properties"; private static final String VALIDCONNECTIONCHECKER_PROPERTIES_NAME = "valid-connection-checker-properties"; private static final String REAUTHPLUGIN_CLASSNAME_NAME = "reauth-plugin-class-name"; private static final String REAUTHPLUGIN_PROPERTIES_NAME = "reauth-plugin-properties"; private static final String RECOVERY_USERNAME_NAME = "recovery-username"; private static final String RECOVERY_PASSWORD_NAME = "recovery-password"; private static final String RECOVERY_SECURITY_DOMAIN_NAME = "recovery-security-domain"; private static final String RECOVERY_ELYTRON_ENABLED_NAME = "recovery-elytron-enabled"; private static final String RECOVERY_AUTHENTICATION_CONTEXT_NAME = "recovery-authentication-context"; private static final String RECOVER_PLUGIN_CLASSNAME_NAME = "recovery-plugin-class-name"; private static final String RECOVER_PLUGIN_PROPERTIES_NAME = "recovery-plugin-properties"; private static final String NO_RECOVERY_NAME = "no-recovery"; static final SensitivityClassification DS_SECURITY = new SensitivityClassification(DataSourcesExtension.SUBSYSTEM_NAME, "data-source-security", false, true, true); static final SensitiveTargetAccessConstraintDefinition DS_SECURITY_DEF = new SensitiveTargetAccessConstraintDefinition(DS_SECURITY); static final SimpleAttributeDefinition DEPLOYMENT_NAME = SimpleAttributeDefinitionBuilder.create("deployment-name", ModelType.STRING) .setRequired(false) .setDeprecated(ModelVersion.create(6, 0, 0)) .build(); static final SimpleAttributeDefinition MODULE_SLOT = SimpleAttributeDefinitionBuilder.create("module-slot", ModelType.STRING) .setRequired(false) .setAllowExpression(true) .build(); static final SimpleAttributeDefinition JDBC_COMPLIANT = SimpleAttributeDefinitionBuilder.create("jdbc-compliant", ModelType.BOOLEAN) .setRequired(false) .setDeprecated(ModelVersion.create(6, 0, 0)) .build(); @Deprecated static final SimpleAttributeDefinition PROFILE = SimpleAttributeDefinitionBuilder.create("profile", ModelType.STRING) .setRequired(false) .setAllowExpression(true) .setDeprecated(ModelVersion.create(4, 0, 0)) .build(); public static final String STATISTICS = "statistics"; static SimpleAttributeDefinition CONNECTION_URL = new SimpleAttributeDefinitionBuilder(CONNECTION_URL_NAME, ModelType.STRING, true) .setAllowExpression(true) .setXmlName(DataSource.Tag.CONNECTION_URL.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition DRIVER_CLASS = new SimpleAttributeDefinitionBuilder(DATASOURCE_DRIVER_CLASS_NAME, ModelType.STRING) .setRequired(false) .setAllowExpression(true) .setXmlName(DataSource.Tag.DRIVER_CLASS.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition DATASOURCE_CLASS = new SimpleAttributeDefinitionBuilder(DATASOURCE_CLASS_NAME, ModelType.STRING) .setXmlName(DataSource.Tag.DATASOURCE_CLASS.getLocalName()) .setAllowExpression(true) .setRequired(false) .setRestartAllServices() .build(); static SimpleAttributeDefinition DATASOURCE_DRIVER = new SimpleAttributeDefinitionBuilder(DATASOURCE_DRIVER_NAME, ModelType.STRING, false) .setXmlName(DataSource.Tag.DRIVER.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition NEW_CONNECTION_SQL = new SimpleAttributeDefinitionBuilder(NEW_CONNECTION_SQL_NAME, ModelType.STRING, true) .setAllowExpression(true) .setXmlName(DataSource.Tag.NEW_CONNECTION_SQL.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition URL_DELIMITER = new SimpleAttributeDefinitionBuilder(URL_DELIMITER_NAME, ModelType.STRING, true) .setXmlName(DataSource.Tag.URL_DELIMITER.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition URL_PROPERTY = new SimpleAttributeDefinitionBuilder(URL_PROPERTY_NAME, ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setXmlName(XaDataSource.Tag.URL_PROPERTY.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition URL_SELECTOR_STRATEGY_CLASS_NAME = new SimpleAttributeDefinitionBuilder(URL_SELECTOR_STRATEGY_CLASS_NAME_NAME, ModelType.STRING, true) .setXmlName(DataSource.Tag.URL_SELECTOR_STRATEGY_CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition ENABLED = new SimpleAttributeDefinitionBuilder(ENABLED_NAME, ModelType.BOOLEAN) .setXmlName(DataSource.Attribute.ENABLED.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(Defaults.ENABLED)) .setRequired(false) .setDeprecated(ModelVersion.create(3), false) .setRestartAllServices() .build(); static SimpleAttributeDefinition CONNECTABLE = new SimpleAttributeDefinitionBuilder(CONNECTABLE_NAME, ModelType.BOOLEAN) .setXmlName(DataSource.Attribute.CONNECTABLE.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(Defaults.CONNECTABLE)) .setRequired(false) .setRestartAllServices() .build(); static SimpleAttributeDefinition ENLISTMENT_TRACE = new SimpleAttributeDefinitionBuilder(ENLISTMENT_TRACE_NAME, ModelType.BOOLEAN) .setXmlName(DataSource.Attribute.ENLISTMENT_TRACE.getLocalName()) .setAllowExpression(true) .setDefaultValue(ModelNode.FALSE) .setRequired(false) .build(); static SimpleAttributeDefinition MCP = new SimpleAttributeDefinitionBuilder(MCP_NAME, ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setDefaultValue(new ModelNode(org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.class.getName())) .setXmlName(DataSource.Attribute.MCP.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition TRACKING = new SimpleAttributeDefinitionBuilder(TRACKING_NAME, ModelType.BOOLEAN) .setXmlName(DataSource.Attribute.TRACKING.getLocalName()) .setDefaultValue(ModelNode.FALSE) .setAllowExpression(true) .setRequired(false) .setRestartAllServices() .build(); static SimpleAttributeDefinition JTA = new SimpleAttributeDefinitionBuilder(JTA_NAME, ModelType.BOOLEAN, true) .setXmlName(DataSource.Attribute.JTA.getLocalName()) .setDefaultValue(new ModelNode(Defaults.JTA)) .setAllowExpression(true) .setRestartAllServices() .build(); static final PropertiesAttributeDefinition CONNECTION_PROPERTIES = new PropertiesAttributeDefinition.Builder(CONNECTION_PROPERTIES_NAME, true) .setXmlName(DataSource.Tag.CONNECTION_PROPERTY.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition CONNECTION_PROPERTY_VALUE = new SimpleAttributeDefinitionBuilder(CONNECTION_PROPERTY_VALUE_NAME, ModelType.STRING, true) .setXmlName(DataSource.Tag.CONNECTION_PROPERTY.getLocalName()) .setAllowExpression(true) .build(); public static final SimpleAttributeDefinition USERNAME = new SimpleAttributeDefinitionBuilder(USERNAME_NAME, ModelType.STRING, true) .setXmlName(Credential.Tag.USER_NAME.getLocalName()) .setAllowExpression(true) .addAlternatives(SECURITY_DOMAIN_NAME, AUTHENTICATION_CONTEXT_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .addAccessConstraint(DS_SECURITY_DEF) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition PASSWORD = new SimpleAttributeDefinitionBuilder(PASSWORD_NAME, ModelType.STRING) .setXmlName(Credential.Tag.PASSWORD.getLocalName()) .setAllowExpression(true) .setRequired(false) .setRequires(USERNAME_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .addAccessConstraint(DS_SECURITY_DEF) .addAlternatives(CredentialReference.CREDENTIAL_REFERENCE) .setRestartAllServices() .build(); static final ObjectTypeAttributeDefinition CREDENTIAL_REFERENCE = CredentialReference.getAttributeBuilder(true, true) .setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .addAccessConstraint(DS_SECURITY_DEF) .addAlternatives(PASSWORD_NAME) .build(); static SimpleAttributeDefinition SECURITY_DOMAIN = new SimpleAttributeDefinitionBuilder(SECURITY_DOMAIN_NAME, ModelType.STRING, true) .setXmlName(Security.Tag.SECURITY_DOMAIN.getLocalName()) .setAllowExpression(true) .addAlternatives(USERNAME_NAME, AUTHENTICATION_CONTEXT_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SECURITY_DOMAIN_REF) .addAccessConstraint(DS_SECURITY_DEF) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition ELYTRON_ENABLED = new SimpleAttributeDefinitionBuilder(ELYTRON_ENABLED_NAME, ModelType.BOOLEAN, true) .setXmlName(Security.Tag.ELYTRON_ENABLED.getLocalName()) .setDefaultValue(new ModelNode(ELYTRON_MANAGED_SECURITY)) .setAllowExpression(true) .addAccessConstraint(DS_SECURITY_DEF) .setNullSignificant(false) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition AUTHENTICATION_CONTEXT = new SimpleAttributeDefinitionBuilder(AUTHENTICATION_CONTEXT_NAME, ModelType.STRING, true) .setXmlName(Security.Tag.AUTHENTICATION_CONTEXT.getLocalName()) .setAllowExpression(false) .addAlternatives(SECURITY_DOMAIN_NAME, USERNAME_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.AUTHENTICATION_CLIENT_REF) .addAccessConstraint(DS_SECURITY_DEF) .setCapabilityReference(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, Capabilities.DATA_SOURCE_CAPABILITY) .setRestartAllServices() .build(); static SimpleAttributeDefinition PREPARED_STATEMENTS_CACHE_SIZE = new SimpleAttributeDefinitionBuilder(PREPAREDSTATEMENTSCACHESIZE_NAME, ModelType.LONG, true) .setAllowExpression(true) .setXmlName(Statement.Tag.PREPARED_STATEMENT_CACHE_SIZE.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition SHARE_PREPARED_STATEMENTS = new SimpleAttributeDefinitionBuilder(SHAREPREPAREDSTATEMENTS_NAME, ModelType.BOOLEAN, true) .setXmlName(Statement.Tag.SHARE_PREPARED_STATEMENTS.getLocalName()) .setDefaultValue(new ModelNode(Defaults.SHARE_PREPARED_STATEMENTS)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition TRACK_STATEMENTS = new SimpleAttributeDefinitionBuilder(TRACKSTATEMENTS_NAME, ModelType.STRING, true) .setAllowExpression(true) .setXmlName(Statement.Tag.TRACK_STATEMENTS.getLocalName()) .setDefaultValue(new ModelNode(Defaults.TRACK_STATEMENTS.name())) .setRestartAllServices() .build(); static SimpleAttributeDefinition ALLOCATION_RETRY = new SimpleAttributeDefinitionBuilder(ALLOCATION_RETRY_NAME, ModelType.INT, true) .setXmlName(TimeOut.Tag.ALLOCATION_RETRY.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition ALLOCATION_RETRY_WAIT_MILLIS = new SimpleAttributeDefinitionBuilder(ALLOCATION_RETRY_WAIT_MILLIS_NAME, ModelType.LONG, true) .setXmlName(TimeOut.Tag.ALLOCATION_RETRY_WAIT_MILLIS.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition ALLOW_MULTIPLE_USERS = new SimpleAttributeDefinitionBuilder(ALLOW_MULTIPLE_USERS_NAME, ModelType.BOOLEAN, true) .setXmlName(DsPool.Tag.ALLOW_MULTIPLE_USERS.getLocalName()) .setDefaultValue(new ModelNode(Defaults.ALLOW_MULTIPLE_USERS)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition CONNECTION_LISTENER_CLASS = new SimpleAttributeDefinitionBuilder(CONNECTION_LISTENER_CLASS_NAME, ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setRestartAllServices() .build(); static PropertiesAttributeDefinition CONNECTION_LISTENER_PROPERTIES = new PropertiesAttributeDefinition.Builder(CONNECTION_LISTENER_PROPERTY_NAME, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setRequired(false) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition QUERY_TIMEOUT = new SimpleAttributeDefinitionBuilder(QUERYTIMEOUT_NAME, ModelType.LONG, true) .setXmlName(TimeOut.Tag.QUERY_TIMEOUT.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition USE_TRY_LOCK = new SimpleAttributeDefinitionBuilder(USETRYLOCK_NAME, ModelType.LONG, true) .setXmlName(TimeOut.Tag.USE_TRY_LOCK.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition SET_TX_QUERY_TIMEOUT = new SimpleAttributeDefinitionBuilder(SETTXQUERYTIMEOUT_NAME, ModelType.BOOLEAN, true) .setXmlName(TimeOut.Tag.SET_TX_QUERY_TIMEOUT.getLocalName()) .setDefaultValue(new ModelNode(Defaults.SET_TX_QUERY_TIMEOUT)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition TRANSACTION_ISOLATION = new SimpleAttributeDefinitionBuilder(TRANSACTION_ISOLATION_NAME, ModelType.STRING, true) .setXmlName(DataSource.Tag.TRANSACTION_ISOLATION.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition CHECK_VALID_CONNECTION_SQL = new SimpleAttributeDefinitionBuilder(CHECKVALIDCONNECTIONSQL_NAME, ModelType.STRING, true) .setXmlName(Validation.Tag.CHECK_VALID_CONNECTION_SQL.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition EXCEPTION_SORTER_CLASSNAME = new SimpleAttributeDefinitionBuilder(EXCEPTIONSORTERCLASSNAME_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition EXCEPTION_SORTER_MODULE = new SimpleAttributeDefinitionBuilder(EXCEPTIONSORTERMODULE_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.MODULE.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static PropertiesAttributeDefinition EXCEPTION_SORTER_PROPERTIES = new PropertiesAttributeDefinition.Builder(EXCEPTIONSORTER_PROPERTIES_NAME, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setAllowExpression(true) .setRequires(EXCEPTIONSORTERCLASSNAME_NAME) .setRestartAllServices() .build(); static SimpleAttributeDefinition STALE_CONNECTION_CHECKER_CLASSNAME = new SimpleAttributeDefinitionBuilder(STALECONNECTIONCHECKERCLASSNAME_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition STALE_CONNECTION_CHECKER_MODULE = new SimpleAttributeDefinitionBuilder(STALECONNECTIONCHECKERMODULE_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.MODULE.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static PropertiesAttributeDefinition STALE_CONNECTION_CHECKER_PROPERTIES = new PropertiesAttributeDefinition.Builder(STALECONNECTIONCHECKER_PROPERTIES_NAME, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setRequired(false) .setAllowExpression(true) .setRequires(STALECONNECTIONCHECKERCLASSNAME_NAME) .setRestartAllServices() .build(); static SimpleAttributeDefinition VALID_CONNECTION_CHECKER_CLASSNAME = new SimpleAttributeDefinitionBuilder(VALID_CONNECTION_CHECKER_CLASSNAME_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition VALID_CONNECTION_CHECKER_MODULE = new SimpleAttributeDefinitionBuilder(VALID_CONNECTION_CHECKER_MODULE_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.MODULE.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static PropertiesAttributeDefinition VALID_CONNECTION_CHECKER_PROPERTIES = new PropertiesAttributeDefinition.Builder(VALIDCONNECTIONCHECKER_PROPERTIES_NAME, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setRequired(false) .setAllowExpression(true) .setRequires(VALID_CONNECTION_CHECKER_CLASSNAME_NAME) .setRestartAllServices() .build(); static SimpleAttributeDefinition VALIDATE_ON_MATCH = new SimpleAttributeDefinitionBuilder(VALIDATEONMATCH_NAME, ModelType.BOOLEAN, true) .setXmlName(Validation.Tag.VALIDATE_ON_MATCH.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition SPY = new SimpleAttributeDefinitionBuilder(SPY_NAME, ModelType.BOOLEAN, true) .setXmlName(DataSource.Attribute.SPY.getLocalName()) .setDefaultValue(new ModelNode(Defaults.SPY)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition USE_CCM = new SimpleAttributeDefinitionBuilder(USE_CCM_NAME, ModelType.BOOLEAN, true) .setXmlName(DataSource.Attribute.USE_CCM.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(Defaults.USE_CCM)) .setRestartAllServices() .build(); static SimpleAttributeDefinition XA_DATASOURCE_CLASS = new SimpleAttributeDefinitionBuilder(XADATASOURCECLASS_NAME, ModelType.STRING, true) .setXmlName(XaDataSource.Tag.XA_DATASOURCE_CLASS.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition INTERLEAVING = new SimpleAttributeDefinitionBuilder(INTERLEAVING_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.INTERLEAVING.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(Defaults.INTERLEAVING)) .setRestartAllServices() .build(); static SimpleAttributeDefinition NO_TX_SEPARATE_POOL = new SimpleAttributeDefinitionBuilder(NOTXSEPARATEPOOL_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.NO_TX_SEPARATE_POOLS.getLocalName()) .setDefaultValue(new ModelNode(Defaults.NO_TX_SEPARATE_POOL)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition PAD_XID = new SimpleAttributeDefinitionBuilder(PAD_XID_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.PAD_XID.getLocalName()) .setDefaultValue(new ModelNode(Defaults.PAD_XID)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition SAME_RM_OVERRIDE = new SimpleAttributeDefinitionBuilder(SAME_RM_OVERRIDE_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.IS_SAME_RM_OVERRIDE.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition WRAP_XA_RESOURCE = new SimpleAttributeDefinitionBuilder(WRAP_XA_RESOURCE_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.WRAP_XA_RESOURCE.getLocalName()) .setDefaultValue(new ModelNode(Defaults.WRAP_XA_RESOURCE)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition XA_RESOURCE_TIMEOUT = new SimpleAttributeDefinitionBuilder(XA_RESOURCE_TIMEOUT_NAME, ModelType.INT, true) .setXmlName(TimeOut.Tag.XA_RESOURCE_TIMEOUT.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition REAUTH_PLUGIN_CLASSNAME = new SimpleAttributeDefinitionBuilder(REAUTHPLUGIN_CLASSNAME_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static PropertiesAttributeDefinition REAUTHPLUGIN_PROPERTIES = new PropertiesAttributeDefinition.Builder(REAUTHPLUGIN_PROPERTIES_NAME, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setRequired(false) .setAllowExpression(true) .setRequires(REAUTHPLUGIN_CLASSNAME_NAME) .setRestartAllServices() .build(); static SimpleAttributeDefinition STATISTICS_ENABLED = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.STATISTICS_ENABLED, ModelType.BOOLEAN) .setDefaultValue(ModelNode.FALSE) .setRequired(false) .setAllowExpression(true) .setRestartAllServices() .build(); static final SimpleAttributeDefinition[] DATASOURCE_ATTRIBUTE = new SimpleAttributeDefinition[]{CONNECTION_URL, DRIVER_CLASS, Constants.DATASOURCE_CLASS, JNDI_NAME, DATASOURCE_DRIVER, NEW_CONNECTION_SQL, URL_DELIMITER, URL_SELECTOR_STRATEGY_CLASS_NAME, USE_JAVA_CONTEXT, JTA, org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE, org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE, org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN, org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS, org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS, USERNAME, PASSWORD, CREDENTIAL_REFERENCE, SECURITY_DOMAIN, ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, REAUTH_PLUGIN_CLASSNAME, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY, ALLOW_MULTIPLE_USERS, CONNECTION_LISTENER_CLASS, PREPARED_STATEMENTS_CACHE_SIZE, SHARE_PREPARED_STATEMENTS, TRACK_STATEMENTS, ALLOCATION_RETRY, ALLOCATION_RETRY_WAIT_MILLIS, org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS, org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES, QUERY_TIMEOUT, USE_TRY_LOCK, SET_TX_QUERY_TIMEOUT, TRANSACTION_ISOLATION, CHECK_VALID_CONNECTION_SQL, EXCEPTION_SORTER_CLASSNAME, EXCEPTION_SORTER_MODULE, STALE_CONNECTION_CHECKER_CLASSNAME, STALE_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_CLASSNAME, VALID_CONNECTION_CHECKER_MODULE, org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS, org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION, org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL, VALIDATE_ON_MATCH, SPY, USE_CCM, ENABLED, CONNECTABLE, STATISTICS_ENABLED, TRACKING, MCP, ENLISTMENT_TRACE}; static final PropertiesAttributeDefinition[] DATASOURCE_PROPERTIES_ATTRIBUTES = new PropertiesAttributeDefinition[]{ REAUTHPLUGIN_PROPERTIES, EXCEPTION_SORTER_PROPERTIES, STALE_CONNECTION_CHECKER_PROPERTIES, VALID_CONNECTION_CHECKER_PROPERTIES, CONNECTION_LISTENER_PROPERTIES, org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES, org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES, }; static SimpleAttributeDefinition RECOVERY_USERNAME = new SimpleAttributeDefinitionBuilder(RECOVERY_USERNAME_NAME, ModelType.STRING, true) .setXmlName(Credential.Tag.USER_NAME.getLocalName()) .setAllowExpression(true) .addAlternatives(RECOVERY_SECURITY_DOMAIN_NAME, RECOVERY_AUTHENTICATION_CONTEXT_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_PASSWORD = new SimpleAttributeDefinitionBuilder(RECOVERY_PASSWORD_NAME, ModelType.STRING) .setXmlName(Credential.Tag.PASSWORD.getLocalName()) .setAllowExpression(true) .setRequired(false) .setRequires(RECOVERY_USERNAME_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_SECURITY_DOMAIN = new SimpleAttributeDefinitionBuilder(RECOVERY_SECURITY_DOMAIN_NAME, ModelType.STRING) .setXmlName(Security.Tag.SECURITY_DOMAIN.getLocalName()) .setAllowExpression(true) .setRequired(false) .addAlternatives(RECOVERY_USERNAME_NAME, RECOVERY_AUTHENTICATION_CONTEXT_NAME) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_ELYTRON_ENABLED = new SimpleAttributeDefinitionBuilder(RECOVERY_ELYTRON_ENABLED_NAME, ModelType.BOOLEAN, true) .setXmlName(Security.Tag.ELYTRON_ENABLED.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(ELYTRON_MANAGED_SECURITY)) .setNullSignificant(false) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_AUTHENTICATION_CONTEXT = new SimpleAttributeDefinitionBuilder(RECOVERY_AUTHENTICATION_CONTEXT_NAME, ModelType.STRING, true) .setXmlName(Security.Tag.AUTHENTICATION_CONTEXT.getLocalName()) .setAllowExpression(false) .setRequires(RECOVERY_ELYTRON_ENABLED_NAME) .addAlternatives(RECOVERY_SECURITY_DOMAIN_NAME, RECOVERY_USERNAME_NAME) .setCapabilityReference(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, Capabilities.DATA_SOURCE_CAPABILITY) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.AUTHENTICATION_CLIENT_REF) .addAccessConstraint(DS_SECURITY_DEF) .setRestartAllServices() .build(); static final ObjectTypeAttributeDefinition RECOVERY_CREDENTIAL_REFERENCE = CredentialReference.getAttributeBuilder("recovery-credential-reference", CredentialReference.CREDENTIAL_REFERENCE, true, true) .setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .addAccessConstraint(DS_SECURITY_DEF) .addAlternatives(RECOVERY_PASSWORD_NAME) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVER_PLUGIN_CLASSNAME = new SimpleAttributeDefinitionBuilder(RECOVER_PLUGIN_CLASSNAME_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static PropertiesAttributeDefinition RECOVER_PLUGIN_PROPERTIES = new PropertiesAttributeDefinition.Builder(RECOVER_PLUGIN_PROPERTIES_NAME, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setRequired(false) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition NO_RECOVERY = new SimpleAttributeDefinitionBuilder(NO_RECOVERY_NAME, ModelType.BOOLEAN, true) .setXmlName(Recovery.Attribute.NO_RECOVERY.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static final SimpleAttributeDefinition[] XA_DATASOURCE_ATTRIBUTE = new SimpleAttributeDefinition[]{ Constants.XA_DATASOURCE_CLASS, JNDI_NAME, DATASOURCE_DRIVER, NEW_CONNECTION_SQL, URL_DELIMITER, URL_SELECTOR_STRATEGY_CLASS_NAME, USE_JAVA_CONTEXT, org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE, org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE, org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN, INTERLEAVING, org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS, org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS, NO_TX_SEPARATE_POOL, PAD_XID, SAME_RM_OVERRIDE, WRAP_XA_RESOURCE, USERNAME, PASSWORD, CREDENTIAL_REFERENCE, SECURITY_DOMAIN, ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, REAUTH_PLUGIN_CLASSNAME, org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY, ALLOW_MULTIPLE_USERS, CONNECTION_LISTENER_CLASS, PREPARED_STATEMENTS_CACHE_SIZE, SHARE_PREPARED_STATEMENTS, TRACK_STATEMENTS, ALLOCATION_RETRY, ALLOCATION_RETRY_WAIT_MILLIS, org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS, org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES, QUERY_TIMEOUT, USE_TRY_LOCK, SET_TX_QUERY_TIMEOUT, TRANSACTION_ISOLATION, CHECK_VALID_CONNECTION_SQL, EXCEPTION_SORTER_CLASSNAME, EXCEPTION_SORTER_MODULE, STALE_CONNECTION_CHECKER_CLASSNAME, STALE_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_CLASSNAME, VALID_CONNECTION_CHECKER_MODULE, org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS, org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION, org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL, VALIDATE_ON_MATCH, XA_RESOURCE_TIMEOUT, SPY, USE_CCM, ENABLED, CONNECTABLE, STATISTICS_ENABLED, TRACKING, MCP, ENLISTMENT_TRACE, RECOVERY_USERNAME, RECOVERY_PASSWORD, RECOVERY_SECURITY_DOMAIN, RECOVERY_ELYTRON_ENABLED, RECOVERY_AUTHENTICATION_CONTEXT, RECOVER_PLUGIN_CLASSNAME, RECOVERY_CREDENTIAL_REFERENCE, NO_RECOVERY, URL_PROPERTY}; static final PropertiesAttributeDefinition[] XA_DATASOURCE_PROPERTIES_ATTRIBUTES = new PropertiesAttributeDefinition[]{ REAUTHPLUGIN_PROPERTIES, EXCEPTION_SORTER_PROPERTIES, STALE_CONNECTION_CHECKER_PROPERTIES, VALID_CONNECTION_CHECKER_PROPERTIES, RECOVER_PLUGIN_PROPERTIES, CONNECTION_LISTENER_PROPERTIES, org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES, org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES, }; static final PropertiesAttributeDefinition XADATASOURCE_PROPERTIES = new PropertiesAttributeDefinition.Builder(XADATASOURCEPROPERTIES_NAME, false) .setXmlName(XaDataSource.Tag.XA_DATASOURCE_PROPERTY.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition XADATASOURCE_PROPERTY_VALUE = new SimpleAttributeDefinitionBuilder(XADATASOURCEPROPERTIES_VALUE_NAME, ModelType.STRING, true) .setXmlName(XaDataSource.Tag.XA_DATASOURCE_PROPERTY.getLocalName()) .setAllowExpression(true) .build(); @Deprecated static final SimpleAttributeDefinition DRIVER_NAME = new SimpleAttributeDefinitionBuilder(DRIVER_NAME_NAME, ModelType.STRING) .setXmlName(Driver.Attribute.NAME.getLocalName()) .setRequired(false) //.setResourceOnly() .setRestartAllServices() .setDeprecated(ModelVersion.create(7)) .build(); static final SimpleAttributeDefinition DRIVER_MODULE_NAME = new SimpleAttributeDefinitionBuilder(DRIVER_MODULE_NAME_NAME, ModelType.STRING) .setAllowExpression(true) .setXmlName(Driver.Attribute.MODULE.getLocalName()) .build(); static final SimpleAttributeDefinition DRIVER_MAJOR_VERSION = new SimpleAttributeDefinitionBuilder(DRIVER_MAJOR_VERSION_NAME, ModelType.INT) .setRequired(false) .setAllowExpression(true) .setXmlName(Driver.Attribute.MAJOR_VERSION.getLocalName()) .build(); static final SimpleAttributeDefinition DRIVER_MINOR_VERSION = new SimpleAttributeDefinitionBuilder(DRIVER_MINOR_VERSION_NAME, ModelType.INT) .setRequired(false) .setAllowExpression(true) .setXmlName(Driver.Attribute.MINOR_VERSION.getLocalName()) .build(); static final SimpleAttributeDefinition DRIVER_CLASS_NAME = new SimpleAttributeDefinitionBuilder(DRIVER_CLASS_NAME_NAME, ModelType.STRING) .setXmlName(Driver.Tag.DRIVER_CLASS.getLocalName()) .setRequired(false) .setAllowExpression(true) .build(); static final SimpleAttributeDefinition DRIVER_DATASOURCE_CLASS_NAME = new SimpleAttributeDefinitionBuilder(DRIVER_DATASOURCE_CLASS_NAME_NAME, ModelType.STRING) .setXmlName(Driver.Tag.DATASOURCE_CLASS.getLocalName()) .setRequired(false) .setAllowExpression(true) .build(); static final SimpleAttributeDefinition DRIVER_XA_DATASOURCE_CLASS_NAME = new SimpleAttributeDefinitionBuilder(DRIVER_XA_DATASOURCE_CLASS_NAME_NAME, ModelType.STRING) .setXmlName(Driver.Tag.XA_DATASOURCE_CLASS.getLocalName()) .setRequired(false) .setAllowExpression(true) .build(); static final PrimitiveListAttributeDefinition DATASOURCE_CLASS_INFO = PrimitiveListAttributeDefinition.Builder.of("datasource-class-info", ModelType.OBJECT) .setRequired(false) .setStorageRuntime() .build(); static final SimpleAttributeDefinition[] JDBC_DRIVER_ATTRIBUTES = { DEPLOYMENT_NAME, DRIVER_MODULE_NAME, MODULE_SLOT, DRIVER_CLASS_NAME, DRIVER_DATASOURCE_CLASS_NAME, DRIVER_XA_DATASOURCE_CLASS_NAME, DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION, JDBC_COMPLIANT, PROFILE }; static final SimpleAttributeDefinition INSTALLED_DRIVER_NAME = new SimpleAttributeDefinitionBuilder(DRIVER_NAME_NAME, ModelType.STRING) .setValidator(new StringLengthValidator(1)) .build(); private static final AttributeDefinition[] INSTALLED_DRIVER_ATTRIBUTES = Stream.concat(Arrays.stream(JDBC_DRIVER_ATTRIBUTES), Stream.of(INSTALLED_DRIVER_NAME, DATASOURCE_CLASS_INFO)) .toArray(AttributeDefinition[]::new); static final ObjectTypeAttributeDefinition INSTALLED_DRIVER = ObjectTypeAttributeDefinition.Builder.of("installed-driver", INSTALLED_DRIVER_ATTRIBUTES).build(); static final ObjectListAttributeDefinition INSTALLED_DRIVERS = ObjectListAttributeDefinition.Builder.of("installed-drivers", INSTALLED_DRIVER) .setResourceOnly().setFlags(AttributeAccess.Flag.STORAGE_RUNTIME) .build(); //static final SimpleOperationDefinition INSTALLED_DRIVERS_LIST = new SimpleOperationDefinitionBuilder("installed-drivers-list", DataSourcesExtension.getResourceDescriptionResolver()) static final SimpleOperationDefinition INSTALLED_DRIVERS_LIST = new SimpleOperationDefinitionBuilder("installed-drivers-list", NonResolvingResourceDescriptionResolver.INSTANCE) .setReadOnly() .setRuntimeOnly() .setReplyType(ModelType.LIST) .setReplyParameters(INSTALLED_DRIVER_ATTRIBUTES) .build(); static final SimpleOperationDefinition GET_INSTALLED_DRIVER = new SimpleOperationDefinitionBuilder("get-installed-driver", DataSourcesExtension.getResourceDescriptionResolver()) .setReadOnly() .setRuntimeOnly() .setParameters(INSTALLED_DRIVER_NAME) .setReplyParameters(INSTALLED_DRIVER_ATTRIBUTES) .setAttributeResolver(DataSourcesExtension.getResourceDescriptionResolver("jdbc-driver")) .build(); static final SimpleOperationDefinition DATASOURCE_ENABLE = new SimpleOperationDefinitionBuilder(ENABLE, DataSourcesExtension.getResourceDescriptionResolver()).setDeprecated(ModelVersion.create(3)).build(); static final SimpleOperationDefinition DATASOURCE_DISABLE = new SimpleOperationDefinitionBuilder(DISABLE, DataSourcesExtension.getResourceDescriptionResolver()).setDeprecated(ModelVersion.create(3)) .build(); static final SimpleOperationDefinition FLUSH_IDLE_CONNECTION = new SimpleOperationDefinitionBuilder("flush-idle-connection-in-pool", DataSourcesExtension.getResourceDescriptionResolver()) .setRuntimeOnly().build(); static final SimpleOperationDefinition FLUSH_ALL_CONNECTION = new SimpleOperationDefinitionBuilder("flush-all-connection-in-pool", DataSourcesExtension.getResourceDescriptionResolver()) .setRuntimeOnly().build(); static final SimpleOperationDefinition DUMP_QUEUED_THREADS = new SimpleOperationDefinitionBuilder("dump-queued-threads-in-pool", DataSourcesExtension.getResourceDescriptionResolver()) .setReadOnly() .setRuntimeOnly() .build(); static final SimpleOperationDefinition FLUSH_INVALID_CONNECTION = new SimpleOperationDefinitionBuilder("flush-invalid-connection-in-pool", DataSourcesExtension.getResourceDescriptionResolver()) .setRuntimeOnly().build(); static final SimpleOperationDefinition FLUSH_GRACEFULLY_CONNECTION = new SimpleOperationDefinitionBuilder("flush-gracefully-connection-in-pool", DataSourcesExtension.getResourceDescriptionResolver()) .setRuntimeOnly().build(); static final SimpleOperationDefinition TEST_CONNECTION = new SimpleOperationDefinitionBuilder("test-connection-in-pool", DataSourcesExtension.getResourceDescriptionResolver()) .setParameters(USERNAME, PASSWORD) .setRuntimeOnly().build(); }
51,033
52.607143
228
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/AbstractXMLDataSourceRuntimeHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.AbstractRuntimeOnlyHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; /** * Base type for runtime operations on datasources and XA datasources * * @author Stuart Douglas */ public abstract class AbstractXMLDataSourceRuntimeHandler<T> extends AbstractRuntimeOnlyHandler { protected static final String CONNECTION_PROPERTIES = "connection-properties"; protected static final String XA_DATASOURCE_PROPERTIES = "xa-datasource-properties"; protected static final String DATA_SOURCE = "data-source"; protected static final String XA_DATA_SOURCE = "xa-data-source"; private final Map<PathAddress, T> dataSourceConfigs = Collections.synchronizedMap(new HashMap<PathAddress, T>()); @Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { String opName = operation.require(ModelDescriptionConstants.OP).asString(); PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); final T dataSource = getDataSourceConfig(address); if (ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION.equals(opName)) { final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString(); executeReadAttribute(attributeName, context, dataSource, address); } else { throw unknownOperation(opName); } } public void registerDataSource(final PathAddress address, final T dataSource) { dataSourceConfigs.put(address, dataSource); } public void unregisterDataSource(final PathAddress address) { dataSourceConfigs.remove(address); } protected abstract void executeReadAttribute(final String attributeName, final OperationContext context, final T dataSource, final PathAddress address); private static IllegalStateException unknownOperation(String opName) { throw ConnectorLogger.ROOT_LOGGER.unknownOperation(opName); } private T getDataSourceConfig(final PathAddress operationAddress) throws OperationFailedException { final List<PathElement> relativeAddress = new ArrayList<PathElement>(); for (int i = operationAddress.size() - 1; i >= 0; i--) { PathElement pe = operationAddress.getElement(i); relativeAddress.add(0, pe); if (ModelDescriptionConstants.DEPLOYMENT.equals(pe.getKey())) { break; } } final PathAddress pa = PathAddress.pathAddress(relativeAddress); final T config; if(operationAddress.getLastElement().getKey().equals(CONNECTION_PROPERTIES) || operationAddress.getLastElement().getKey().equals(XA_DATASOURCE_PROPERTIES)) { config = dataSourceConfigs.get(pa.subAddress(0, pa.size() - 1)); } else { config = dataSourceConfigs.get(pa); } if (config == null) { String exceptionMessage = ConnectorLogger.ROOT_LOGGER.noDataSourceRegisteredForAddress(operationAddress); throw new OperationFailedException(exceptionMessage); } return config; } protected void setLongIfNotNull(final OperationContext context, final Long value) { if (value != null) { context.getResult().set(value); } } protected void setIntIfNotNull(final OperationContext context, final Integer value) { if (value != null) { context.getResult().set(value); } } protected void setBooleanIfNotNull(final OperationContext context, final Boolean value) { if (value != null) { context.getResult().set(value); } } protected void setStringIfNotNull(final OperationContext context, final String value) { if (value != null) { context.getResult().set(value); } } }
5,431
39.842105
156
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XADataSourceConfigService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import java.util.Map; import java.util.function.Supplier; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public class XADataSourceConfigService implements Service<ModifiableXaDataSource> { public static final ServiceName SERVICE_NAME_BASE = ServiceName.JBOSS.append("xa-data-source-config"); private final ModifiableXaDataSource dataSourceConfig; private final Map<String, Supplier<String>> xaDataSourceProperties; public XADataSourceConfigService(final ModifiableXaDataSource dataSourceConfig, final Map<String, Supplier<String>> xaDataSourceProperties) { this.dataSourceConfig = dataSourceConfig; this.xaDataSourceProperties = xaDataSourceProperties; } public void start(final StartContext startContext) throws StartException { for (Map.Entry<String, Supplier<String>> xaDataSourceProperty : xaDataSourceProperties.entrySet()) { dataSourceConfig.addXaDataSourceProperty(xaDataSourceProperty.getKey(), xaDataSourceProperty.getValue().get()); } } public void stop(final StopContext stopContext) { } @Override public ModifiableXaDataSource getValue() { return dataSourceConfig; } }
2,590
38.861538
145
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/ConnectionPropertiesService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.datasources; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class ConnectionPropertiesService implements Service<String> { private final String value; private final String name; /** * create an instance * */ public ConnectionPropertiesService(String name, String value) { this.name = name; this.value = value; } @Override public String getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { } @Override public void stop(StopContext context) { } public String getName() { return name; } }
2,007
28.529412
70
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourceRemove.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import javax.sql.DataSource; import org.jboss.as.connector._private.Capabilities; import org.jboss.as.controller.AbstractRemoveStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceName; /** * Operation handler responsible for removing a (XA)DataSource. * * @author Stefano Maestrioperation2.get(OP).set("write-attribute"); */ public class DataSourceRemove extends AbstractRemoveStepHandler { static final DataSourceRemove INSTANCE = new DataSourceRemove(false); static final DataSourceRemove XA_INSTANCE = new DataSourceRemove(true); private final boolean isXa; private DataSourceRemove(final boolean isXa) { this.isXa = isXa; } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { if (context.isResourceServiceRestartAllowed()) { final ModelNode address = operation.require(OP_ADDR); final String dsName = PathAddress.pathAddress(address).getLastElement().getValue(); final String jndiName = JNDI_NAME.resolveModelAttribute(context, model).asString(); final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class); final ServiceName dataSourceCongServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(dsName); final ServiceName xaDataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName); final ServiceName driverDemanderServiceName = ServiceName.JBOSS.append("driver-demander").append(jndiName); final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE .append(dsName); final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName); context.removeService(bindInfo.getBinderServiceName()); context.removeService(referenceFactoryServiceName); context.removeService(dataSourceServiceName.append(Constants.STATISTICS)); if (!isXa) { context.removeService(dataSourceCongServiceName); } else { context.removeService(xaDataSourceConfigServiceName); } context.removeService(dataSourceServiceName); context.removeService(driverDemanderServiceName); } else { context.reloadRequired(); } } }
4,070
42.774194
159
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/ModifiableDataSource.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.jboss.as.connector.metadata.api.ds.DsSecurity; import org.jboss.jca.common.CommonBundle; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.DsPool; import org.jboss.jca.common.api.metadata.ds.Statement; import org.jboss.jca.common.api.metadata.ds.TimeOut; import org.jboss.jca.common.api.metadata.ds.TransactionIsolation; import org.jboss.jca.common.api.metadata.ds.Validation; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.common.metadata.ds.DataSourceAbstractImpl; import org.jboss.jca.common.metadata.ds.DataSourceImpl; import org.jboss.logging.Messages; /** A modifiable DataSourceImpl to add connection properties * * @author <a href="[email protected]">Stefano Maestri</a> * */ public class ModifiableDataSource extends DataSourceAbstractImpl implements DataSource { /** * The serialVersionUID */ private static final long serialVersionUID = -5214100851560229431L; /** * The bundle */ private static CommonBundle bundle = Messages.getBundle(CommonBundle.class); private final Boolean jta; private final String connectionUrl; private String driverClass; private String dataSourceClass; private final HashMap<String, String> connectionProperties; private final DsPool pool; /** * Create a new DataSourceImpl. * * @param connectionUrl connectionUrl * @param driverClass driverClass * @param dataSourceClass dataSourceClass * @param driver driver * @param transactionIsolation transactionIsolation * @param connectionProperties connectionProperties * @param timeOut timeOut * @param security security * @param statement statement * @param validation validation * @param urlDelimiter urlDelimiter * @param urlSelectorStrategyClassName urlSelectorStrategyClassName * @param newConnectionSql newConnectionSql * @param useJavaContext useJavaContext * @param poolName poolName * @param enabled enabled * @param jndiName jndiName * @param spy spy * @param useccm useccm * @param jta jta * @param mcp mcp * @param enlistmentTrace enlistmentTrace * @param pool pool * @throws ValidateException * ValidateException */ public ModifiableDataSource(String connectionUrl, String driverClass, String dataSourceClass, String driver, TransactionIsolation transactionIsolation, Map<String, String> connectionProperties, TimeOut timeOut, DsSecurity security, Statement statement, Validation validation, String urlDelimiter, String urlSelectorStrategyClassName, String newConnectionSql, Boolean useJavaContext, String poolName, Boolean enabled, String jndiName, Boolean spy, Boolean useccm, Boolean jta, final Boolean connectable, final Boolean tracking, String mcp, Boolean enlistmentTrace, DsPool pool) throws ValidateException { super(transactionIsolation, timeOut, security, statement, validation, urlDelimiter, urlSelectorStrategyClassName, useJavaContext, poolName, enabled, jndiName, spy, useccm, driver, newConnectionSql, connectable, tracking, mcp, enlistmentTrace); this.jta = jta; this.connectionUrl = connectionUrl; this.driverClass = driverClass; this.dataSourceClass = dataSourceClass; if (connectionProperties != null) { this.connectionProperties = new HashMap<String, String>(connectionProperties.size()); this.connectionProperties.putAll(connectionProperties); } else { this.connectionProperties = new HashMap<String, String>(0); } this.pool = pool; this.validate(); } /** * {@inheritDoc} */ public Boolean isJTA() { return jta; } @Override public Boolean isConnectable() { return connectable; } @Override public Boolean isTracking() { return tracking; } /** * Get the connectionUrl. * * @return the connectionUrl. */ @Override public final String getConnectionUrl() { return connectionUrl; } /** * Get the driverClass. * * @return the driverClass. */ @Override public final String getDriverClass() { return driverClass; } /** * Get the dataSourceClass. * * @return the dataSourceClass. */ @Override public final String getDataSourceClass() { return dataSourceClass; } /** * Get the driver. * * @return the driver. */ @Override public final String getDriver() { return driver; } /** * Get the connectionProperties. * * @return the connectionProperties. */ @Override public final Map<String, String> getConnectionProperties() { return Collections.unmodifiableMap(connectionProperties); } public final void addConnectionProperty(String name, String value) { connectionProperties.put(name,value); } /** * Get the statement. * * @return the statement. */ @Override public final Statement getStatement() { return statement; } /** * Get the urlDelimiter. * * @return the urlDelimiter. */ @Override public final String getUrlDelimiter() { return urlDelimiter; } /** * Get the urlSelectorStrategyClassName. * * @return the urlSelectorStrategyClassName. */ @Override public final String getUrlSelectorStrategyClassName() { return urlSelectorStrategyClassName; } /** * Get the newConnectionSql. * * @return the newConnectionSql. */ @Override public final String getNewConnectionSql() { return newConnectionSql; } /** * Get the pool. * * @return the pool. */ @Override public final DsPool getPool() { return pool; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((connectionProperties == null) ? 0 : connectionProperties.hashCode()); result = prime * result + ((connectionUrl == null) ? 0 : connectionUrl.hashCode()); result = prime * result + ((driver == null) ? 0 : driver.hashCode()); result = prime * result + ((driverClass == null) ? 0 : driverClass.hashCode()); result = prime * result + ((dataSourceClass == null) ? 0 : dataSourceClass.hashCode()); result = prime * result + ((newConnectionSql == null) ? 0 : newConnectionSql.hashCode()); result = prime * result + ((pool == null) ? 0 : pool.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (!(obj instanceof ModifiableDataSource)) return false; ModifiableDataSource other = (ModifiableDataSource) obj; if (connectionProperties == null) { if (other.connectionProperties != null) return false; } else if (!connectionProperties.equals(other.connectionProperties)) return false; if (connectionUrl == null) { if (other.connectionUrl != null) return false; } else if (!connectionUrl.equals(other.connectionUrl)) return false; if (driver == null) { if (other.driver != null) return false; } else if (!driver.equals(other.driver)) return false; if (driverClass == null) { if (other.driverClass != null) return false; } else if (!driverClass.equals(other.driverClass)) return false; if (dataSourceClass == null) { if (other.dataSourceClass != null) return false; } else if (!dataSourceClass.equals(other.dataSourceClass)) return false; if (newConnectionSql == null) { if (other.newConnectionSql != null) return false; } else if (!newConnectionSql.equals(other.newConnectionSql)) return false; if (pool == null) { if (other.pool != null) return false; } else if (!pool.equals(other.pool)) return false; return true; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("<datasource"); if (jndiName != null) sb.append(" ").append(Attribute.JNDI_NAME).append("=\"").append(jndiName).append("\""); if (poolName != null) sb.append(" ").append(Attribute.POOL_NAME).append("=\"").append(poolName).append("\""); if (enabled != null) sb.append(" ").append(Attribute.ENABLED).append("=\"").append(enabled).append("\""); if (useJavaContext != null) { sb.append(" ").append(Attribute.USE_JAVA_CONTEXT); sb.append("=\"").append(useJavaContext).append("\""); } if (spy) sb.append(" ").append(Attribute.SPY).append("=\"").append(spy).append("\""); if (useCcm) sb.append(" ").append(Attribute.USE_CCM).append("=\"").append(useCcm).append("\""); if (jta) sb.append(" ").append(Attribute.JTA).append("=\"").append(jta).append("\""); sb.append(">"); if (connectionUrl != null) { sb.append("<").append(Tag.CONNECTION_URL).append(">"); sb.append(connectionUrl); sb.append("</").append(Tag.CONNECTION_URL).append(">"); } if (driverClass != null) { sb.append("<").append(Tag.DRIVER_CLASS).append(">"); sb.append(driverClass); sb.append("</").append(Tag.DRIVER_CLASS).append(">"); } if (dataSourceClass != null) { sb.append("<").append(Tag.DATASOURCE_CLASS).append(">"); sb.append(dataSourceClass); sb.append("</").append(Tag.DATASOURCE_CLASS).append(">"); } if (driver != null) { sb.append("<").append(Tag.DRIVER).append(">"); sb.append(driver); sb.append("</").append(Tag.DRIVER).append(">"); } if (connectionProperties != null && connectionProperties.size() > 0) { Iterator<Map.Entry<String, String>> it = connectionProperties.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> entry = it.next(); sb.append("<").append(Tag.CONNECTION_PROPERTY); sb.append(" name=\"").append(entry.getKey()).append("\">"); sb.append(entry.getValue()); sb.append("</").append(Tag.CONNECTION_PROPERTY).append(">"); } } if (newConnectionSql != null) { sb.append("<").append(Tag.NEW_CONNECTION_SQL).append(">"); sb.append(newConnectionSql); sb.append("</").append(Tag.NEW_CONNECTION_SQL).append(">"); } if (transactionIsolation != null) { sb.append("<").append(Tag.TRANSACTION_ISOLATION).append(">"); sb.append(transactionIsolation); sb.append("</").append(Tag.TRANSACTION_ISOLATION).append(">"); } if (urlDelimiter != null) { sb.append("<").append(Tag.URL_DELIMITER).append(">"); sb.append(urlDelimiter); sb.append("</").append(Tag.URL_DELIMITER).append(">"); } if (urlSelectorStrategyClassName != null) { sb.append("<").append(Tag.URL_SELECTOR_STRATEGY_CLASS_NAME).append(">"); sb.append(urlSelectorStrategyClassName); sb.append("</").append(Tag.URL_SELECTOR_STRATEGY_CLASS_NAME).append(">"); } if (pool != null) sb.append(pool); if (security != null) sb.append(security); if (validation != null) sb.append(validation); if (timeOut != null) sb.append(timeOut); if (statement != null) sb.append(statement); sb.append("</datasource>"); return sb.toString(); } @Override public void validate() throws ValidateException { if (this.driverClass != null && (this.connectionUrl == null || this.connectionUrl.trim().length() == 0)) throw new ValidateException(bundle.requiredElementMissing(Tag.CONNECTION_URL.getLocalName(), this.getClass().getCanonicalName())); if ((this.driverClass == null || this.driverClass.trim().length() == 0) && (this.dataSourceClass == null || this.dataSourceClass.trim().length() == 0) && (this.driver == null || this.driver.trim().length() == 0)) throw new ValidateException(bundle.requiredElementMissing(Tag.DRIVER_CLASS.getLocalName(), this.getClass().getCanonicalName())); } /** * Set the driverClass. * * @param driverClass The driverClass to set. */ public final void forceDriverClass(String driverClass) { this.driverClass = driverClass; } /** * Set the dataSourceClass. * * @param dataSourceClass The dataSourceClass to set. */ public final void forceDataSourceClass(String dataSourceClass) { this.dataSourceClass = dataSourceClass; } public final DataSource getUnModifiableInstance() throws ValidateException { return new DataSourceImpl(connectionUrl, driverClass, dataSourceClass, driver, transactionIsolation, connectionProperties, timeOut, security, statement, validation, urlDelimiter, urlSelectorStrategyClassName, newConnectionSql, useJavaContext, poolName, enabled, jndiName, spy, useCcm, jta, connectable, tracking, mcp, enlistmentTrace, pool); } }
15,848
33.454348
136
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/JdbcDriverAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MAJOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MINOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MODULE_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_XA_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.JDBC_DRIVER_ATTRIBUTES; import static org.jboss.as.connector.subsystems.datasources.Constants.MODULE_SLOT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; import java.sql.Driver; import java.util.Arrays; import java.util.Collection; import java.util.ServiceLoader; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.sql.DataSource; import javax.sql.XADataSource; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.services.driver.DriverService; import org.jboss.as.connector.services.driver.InstalledDriver; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.modules.Module; import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoadException; import org.jboss.modules.ModuleNotFoundException; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * Operation handler responsible for adding a jdbc driver. * * @author John Bailey */ public class JdbcDriverAdd extends AbstractAddStepHandler { private static final Collection<AttributeDefinition> ATTRIBUTES = Stream.concat(Arrays.stream(JDBC_DRIVER_ATTRIBUTES), Stream.of(DRIVER_NAME)).collect(Collectors.toList()); static final JdbcDriverAdd INSTANCE = new JdbcDriverAdd(ATTRIBUTES); private JdbcDriverAdd(Collection<AttributeDefinition> attributes) { super(attributes); } protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final ModelNode address = operation.require(OP_ADDR); final String driverName = PathAddress.pathAddress(address).getLastElement().getValue(); if (operation.get(DRIVER_NAME.getName()).isDefined() && !driverName.equals(operation.get(DRIVER_NAME.getName()).asString())) { throw ConnectorLogger.ROOT_LOGGER.driverNameAndResourceNameNotEquals(operation.get(DRIVER_NAME.getName()).asString(), driverName); } String moduleName = DRIVER_MODULE_NAME.resolveModelAttribute(context, model).asString(); final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? DRIVER_MAJOR_VERSION.resolveModelAttribute(context, model).asInt() : null; final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? DRIVER_MINOR_VERSION.resolveModelAttribute(context, model).asInt() : null; final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? DRIVER_CLASS_NAME.resolveModelAttribute(context, model).asString() : null; final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null; final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_XA_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null; final ServiceTarget target = context.getServiceTarget(); final ModuleIdentifier moduleId; final Module module; String slot = model.hasDefined(MODULE_SLOT.getName()) ? MODULE_SLOT.resolveModelAttribute(context, model).asString() : null; try { moduleId = ModuleIdentifier.create(moduleName, slot); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage()), e); } catch (ModuleLoadException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName), e); } if (dataSourceClassName != null) { Class<? extends DataSource> dsCls; try { dsCls = module.getClassLoader().loadClass(dataSourceClassName).asSubclass(DataSource.class); } catch (ClassNotFoundException e) { throw SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(dataSourceClassName, e); } catch (ClassCastException e) { throw SUBSYSTEM_DATASOURCES_LOGGER.notAValidDataSourceClass(dataSourceClassName, DataSource.class.getName()); } checkDSCls(dsCls, DataSource.class); } if (xaDataSourceClassName != null) { Class<? extends XADataSource> dsCls; try { dsCls = module.getClassLoader().loadClass(xaDataSourceClassName).asSubclass(XADataSource.class); } catch (ClassNotFoundException e) { throw SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(xaDataSourceClassName, e); } catch (ClassCastException e) { throw SUBSYSTEM_DATASOURCES_LOGGER.notAValidDataSourceClass(dataSourceClassName, DataSource.class.getName()); } checkDSCls(dsCls, XADataSource.class); } if (driverClassName == null) { final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class); boolean driverLoaded = false; if (serviceLoader != null) { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(module.getClassLoader()); try { for (Driver driver : serviceLoader) { startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName); driverLoaded = true; //just consider first definition and create service for this. User can use different implementation only // w/ explicit declaration of driver-class attribute break; } } finally { Thread.currentThread().setContextClassLoader(tccl); } } if (!driverLoaded) SUBSYSTEM_DATASOURCES_LOGGER.cannotFindDriverClassName(driverName); } else { try { final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName) .asSubclass(Driver.class); ClassLoader tccl = Thread.currentThread().getContextClassLoader(); Driver driver = null; try { Thread.currentThread().setContextClassLoader(module.getClassLoader()); final Constructor<? extends Driver> constructor = driverClass.getConstructor(); driver = constructor.newInstance(); } finally { Thread.currentThread().setContextClassLoader(tccl); } startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName); } catch (Exception e) { SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e); throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.cannotInstantiateDriverClass(driverClassName)); } } } public static void startDriverServices(final ServiceTarget target, final ModuleIdentifier moduleId, Driver driver, final String driverName, final Integer majorVersion, final Integer minorVersion, final String dataSourceClassName, final String xaDataSourceClassName) throws IllegalStateException { final int majorVer = driver.getMajorVersion(); final int minorVer = driver.getMinorVersion(); if ((majorVersion != null && majorVersion != majorVer) || (minorVersion != null && minorVersion != minorVer)) { throw ConnectorLogger.ROOT_LOGGER.driverVersionMismatch(); } final boolean compliant = driver.jdbcCompliant(); if (compliant) { SUBSYSTEM_DATASOURCES_LOGGER.deployingCompliantJdbcDriver(driver.getClass(), majorVer, minorVer); } else { SUBSYSTEM_DATASOURCES_LOGGER.deployingNonCompliantJdbcDriver(driver.getClass(), majorVer, minorVer); } InstalledDriver driverMetadata = new InstalledDriver(driverName, moduleId, driver.getClass().getName(), dataSourceClassName, xaDataSourceClassName, majorVer, minorVer, compliant); DriverService driverService = new DriverService(driverMetadata, driver); final ServiceBuilder<Driver> builder = target.addService(ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")), driverService) .addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, driverService.getDriverRegistryServiceInjector()) .setInitialMode(ServiceController.Mode.ACTIVE); builder.install(); } static <T> void checkDSCls(Class<? extends T> dsCls, Class<T> t) throws OperationFailedException { if (Modifier.isInterface(dsCls.getModifiers()) || Modifier.isAbstract(dsCls.getModifiers())) { throw SUBSYSTEM_DATASOURCES_LOGGER.notAValidDataSourceClass(dsCls.getName(), t.getName()); } } }
11,750
56.043689
195
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/ConnectionPropertyAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_PROPERTY_VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; import org.jboss.msc.service.ServiceTarget; /** * Adds a recovery-environment to the Transactions subsystem * */ public class ConnectionPropertyAdd extends AbstractAddStepHandler { public static final ConnectionPropertyAdd INSTANCE = new ConnectionPropertyAdd(); @Override protected void populateModel(ModelNode operation, ModelNode modelNode) throws OperationFailedException { CONNECTION_PROPERTY_VALUE.validateAndSet(operation, modelNode); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = CONNECTION_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String jndiName = path.getElement(path.size() - 2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = DataSourceConfigService.SERVICE_NAME_BASE.append(jndiName).append("connection-properties").append(configPropertyName); final ServiceRegistry registry = context.getServiceRegistry(true); final ServiceName dataSourceConfigServiceName = DataSourceConfigService.SERVICE_NAME_BASE .append(jndiName); final ServiceController<?> dataSourceConfigController = registry .getService(dataSourceConfigServiceName); if (dataSourceConfigController == null || !((DataSource) dataSourceConfigController.getValue()).isEnabled()) { final ServiceTarget serviceTarget = context.getServiceTarget(); final ConnectionPropertiesService service = new ConnectionPropertiesService(configPropertyName, configPropertyValue); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.NEVER) .install(); } else { context.reloadRequired(); } } }
3,794
44.178571
152
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/AbstractDataSourceService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import static java.lang.Thread.currentThread; import static java.security.AccessController.doPrivileged; import static org.jboss.as.connector.logging.ConnectorLogger.DS_DEPLOYER_LOGGER; import javax.naming.Reference; import jakarta.resource.spi.ManagedConnectionFactory; import javax.sql.DataSource; import javax.sql.XADataSource; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import java.sql.Driver; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.security.ElytronSubjectFactory; import org.jboss.as.connector.services.driver.InstalledDriver; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.subsystems.common.jndi.Util; import org.jboss.as.connector.util.Injection; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory; import org.jboss.jca.adapters.jdbc.JDBCResourceAdapter; import org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory; import org.jboss.jca.adapters.jdbc.spi.ClassLoaderPlugin; import org.jboss.jca.adapters.jdbc.xa.XAManagedConnectionFactory; import org.jboss.jca.common.api.metadata.common.Extension; import org.jboss.jca.common.api.metadata.ds.CommonDataSource; import org.jboss.jca.common.api.metadata.ds.DataSources; import org.jboss.jca.common.api.metadata.ds.DsSecurity; import org.jboss.jca.common.api.metadata.ds.Statement; import org.jboss.jca.common.api.metadata.ds.TimeOut; import org.jboss.jca.common.api.metadata.ds.Validation; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import org.jboss.jca.common.api.metadata.spec.ConfigProperty; import org.jboss.jca.common.api.metadata.spec.XsdString; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.common.metadata.ds.DatasourcesImpl; import org.jboss.jca.common.metadata.ds.DriverImpl; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.jca.core.bootstrapcontext.BootstrapContextCoordinator; import org.jboss.jca.core.connectionmanager.ConnectionManager; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.mdr.NotFoundException; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.jca.deployers.DeployersLogger; import org.jboss.jca.deployers.common.AbstractDsDeployer; import org.jboss.jca.deployers.common.CommonDeployment; import org.jboss.jca.deployers.common.DeployException; import org.jboss.logging.Logger; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceContainer; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; import org.wildfly.common.function.ExceptionSupplier; import org.wildfly.security.auth.client.AuthenticationContext; import org.wildfly.security.credential.source.CredentialSource; import org.wildfly.security.manager.WildFlySecurityManager; import org.wildfly.security.manager.action.ClearContextClassLoaderAction; import org.wildfly.security.manager.action.GetClassLoaderAction; import org.wildfly.security.manager.action.SetContextClassLoaderFromClassAction; /** * Base service for managing a data-source. * @author John Bailey * @author maeste */ public abstract class AbstractDataSourceService implements Service<DataSource> { /** * Consumers outside of the data-source subsystem should use the capability {@code org.wildfly.data-source} where * the dynamic name is the resource name in the model. */ public static final ServiceName SERVICE_NAME_BASE = ServiceName.JBOSS.append("data-source"); public static ServiceName getServiceName(ContextNames.BindInfo bindInfo) { return SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName().getCanonicalName()); } private static final DeployersLogger DEPLOYERS_LOGGER = Logger.getMessageLogger(DeployersLogger.class, AS7DataSourceDeployer.class.getName()); protected final InjectedValue<TransactionIntegration> transactionIntegrationValue = new InjectedValue<TransactionIntegration>(); private final InjectedValue<Driver> driverValue = new InjectedValue<Driver>(); private final InjectedValue<ManagementRepository> managementRepositoryValue = new InjectedValue<ManagementRepository>(); private final InjectedValue<DriverRegistry> driverRegistry = new InjectedValue<DriverRegistry>(); private final InjectedValue<CachedConnectionManager> ccmValue = new InjectedValue<CachedConnectionManager>(); private final InjectedValue<ExecutorService> executor = new InjectedValue<ExecutorService>(); private final InjectedValue<MetadataRepository> mdr = new InjectedValue<MetadataRepository>(); private final InjectedValue<ResourceAdapterRepository> raRepository = new InjectedValue<ResourceAdapterRepository>(); private final InjectedValue<AuthenticationContext> authenticationContext = new InjectedValue<>(); private final InjectedValue<AuthenticationContext> recoveryAuthenticationContext = new InjectedValue<>(); private final InjectedValue<ExceptionSupplier<CredentialSource, Exception>> credentialSourceSupplier = new InjectedValue<>(); private final InjectedValue<ExceptionSupplier<CredentialSource, Exception>> recoveryCredentialSourceSupplier = new InjectedValue<>(); private final String dsName; private final ContextNames.BindInfo jndiName; protected CommonDeployment deploymentMD; private WildFlyDataSource sqlDataSource; /** * The class loader to use. If null the Driver class loader will be used instead. */ private final ClassLoader classLoader; protected AbstractDataSourceService(final String dsName, final ContextNames.BindInfo jndiName, final ClassLoader classLoader ) { this.dsName = dsName; this.classLoader = classLoader; this.jndiName = jndiName; } public synchronized void start(StartContext startContext) throws StartException { try { final ServiceContainer container = startContext.getController().getServiceContainer(); deploymentMD = getDeployer().deploy(container); final Object[] cfs = deploymentMD.getCfs(); if (cfs.length == 0) { throw ConnectorLogger.ROOT_LOGGER.cannotStartDSNoConnectionFactory(jndiName.getAbsoluteJndiName()); } else if (cfs.length >= 2) { throw ConnectorLogger.ROOT_LOGGER.cannotStartDSTooManyConnectionFactories(jndiName.getAbsoluteJndiName(), cfs.length); } sqlDataSource = new WildFlyDataSource((DataSource) deploymentMD.getCfs()[0], jndiName.getAbsoluteJndiName()); DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]); CommonDeploymentService cdService = new CommonDeploymentService(deploymentMD); final ServiceName cdServiceName = CommonDeploymentService.getServiceName(jndiName); final ServiceBuilder cdServiceSB = startContext.getChildTarget().addService(cdServiceName, cdService); // The dependency added must be the JNDI name which for subsystem resources is an alias. This service // is also used in deployments where the capability service name is not registered for the service. cdServiceSB.requires(getServiceName(jndiName)); cdServiceSB.setInitialMode(ServiceController.Mode.ACTIVE).install(); } catch (Throwable t) { throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName); } } protected abstract AS7DataSourceDeployer getDeployer() throws ValidateException ; public void stop(final StopContext stopContext) { ExecutorService executorService = executor.getValue(); Runnable r = new Runnable() { @Override public void run() { try { stopService(); } finally { stopContext.complete(); } } }; try { executorService.execute(r); } catch (RejectedExecutionException e) { r.run(); } finally { stopContext.asynchronous(); } } /** * Performs the actual work of stopping the service. Should be called by {@link #stop(StopContext)} * asynchronously from the MSC thread that invoked stop. */ protected synchronized void stopService() { if (deploymentMD != null) { if (deploymentMD.getResourceAdapterKey() != null) { try { raRepository.getValue().unregisterResourceAdapter(deploymentMD.getResourceAdapterKey()); } catch (org.jboss.jca.core.spi.rar.NotFoundException nfe) { ConnectorLogger.ROOT_LOGGER.exceptionDuringUnregistering(nfe); } } if (deploymentMD.getResourceAdapter() != null) { deploymentMD.getResourceAdapter().stop(); if (BootstrapContextCoordinator.getInstance() != null && deploymentMD.getBootstrapContextIdentifier() != null) { BootstrapContextCoordinator.getInstance().removeBootstrapContext(deploymentMD.getBootstrapContextIdentifier()); } } if (deploymentMD.getDataSources() != null && managementRepositoryValue.getValue() != null) { for (org.jboss.jca.core.api.management.DataSource mgtDs : deploymentMD.getDataSources()) { managementRepositoryValue.getValue().getDataSources().remove(mgtDs); } } if (deploymentMD.getConnectionManagers() != null) { for (ConnectionManager cm : deploymentMD.getConnectionManagers()) { cm.shutdown(); } } } sqlDataSource = null; } public CommonDeployment getDeploymentMD() { return deploymentMD; } public synchronized DataSource getValue() throws IllegalStateException, IllegalArgumentException { return sqlDataSource; } public Injector<TransactionIntegration> getTransactionIntegrationInjector() { return transactionIntegrationValue; } public Injector<Driver> getDriverInjector() { return driverValue; } public Injector<ManagementRepository> getManagementRepositoryInjector() { return managementRepositoryValue; } public Injector<DriverRegistry> getDriverRegistryInjector() { return driverRegistry; } public Injector<CachedConnectionManager> getCcmInjector() { return ccmValue; } public Injector<ExecutorService> getExecutorServiceInjector() { return executor; } public Injector<MetadataRepository> getMdrInjector() { return mdr; } public Injector<ResourceAdapterRepository> getRaRepositoryInjector() { return raRepository; } Injector<AuthenticationContext> getAuthenticationContext() { return authenticationContext; } Injector<AuthenticationContext> getRecoveryAuthenticationContext() { return recoveryAuthenticationContext; } public InjectedValue<ExceptionSupplier<CredentialSource, Exception>> getCredentialSourceSupplierInjector() { return credentialSourceSupplier; } public InjectedValue<ExceptionSupplier<CredentialSource, Exception>> getRecoveryCredentialSourceSupplierInjector() { return recoveryCredentialSourceSupplier; } protected String buildConfigPropsString(Map<String, String> configProps) { final StringBuffer valueBuf = new StringBuffer(); for (Map.Entry<String, String> connProperty : configProps.entrySet()) { valueBuf.append(connProperty.getKey()); valueBuf.append("="); valueBuf.append(connProperty.getValue()); valueBuf.append(";"); } return valueBuf.toString(); } protected TransactionIntegration getTransactionIntegration() { if (! WildFlySecurityManager.isChecking()) { currentThread().setContextClassLoader(TransactionIntegration.class.getClassLoader()); } else { doPrivileged(new SetContextClassLoaderFromClassAction(TransactionIntegration.class)); } try { return transactionIntegrationValue.getValue(); } finally { doPrivileged(ClearContextClassLoaderAction.getInstance()); } } private ClassLoader driverClassLoader() { if(classLoader != null) { return classLoader; } final Class<? extends Driver> clazz = driverValue.getValue().getClass(); return ! WildFlySecurityManager.isChecking() ? clazz.getClassLoader() : doPrivileged(new GetClassLoaderAction(clazz)); } protected class AS7DataSourceDeployer extends AbstractDsDeployer { private final org.jboss.jca.common.api.metadata.ds.DataSource dataSourceConfig; private final XaDataSource xaDataSourceConfig; public AS7DataSourceDeployer(XaDataSource xaDataSourceConfig) { super(); this.xaDataSourceConfig = xaDataSourceConfig; this.dataSourceConfig = null; } public AS7DataSourceDeployer(org.jboss.jca.common.api.metadata.ds.DataSource dataSourceConfig) { super(); this.dataSourceConfig = dataSourceConfig; this.xaDataSourceConfig = null; } public CommonDeployment deploy(ServiceContainer serviceContainer) throws DeployException { try { if (serviceContainer == null) { throw new DeployException(ConnectorLogger.ROOT_LOGGER.nullVar("ServiceContainer")); } HashMap<String, org.jboss.jca.common.api.metadata.ds.Driver> drivers = new HashMap<String, org.jboss.jca.common.api.metadata.ds.Driver>( 1); DataSources dataSources = null; if (dataSourceConfig != null) { String dsClsName = dataSourceConfig.getDataSourceClass(); if (dsClsName != null) { try { Class<? extends DataSource> dsCls = driverClassLoader().loadClass(dsClsName).asSubclass(DataSource.class); JdbcDriverAdd.checkDSCls(dsCls, DataSource.class); } catch (OperationFailedException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(e); } catch (ClassCastException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(ConnectorLogger.ROOT_LOGGER.notAValidDataSourceClass(dsClsName, DataSource.class.getName())); } catch (ClassNotFoundException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(ConnectorLogger.ROOT_LOGGER.failedToLoadDataSourceClass(dsClsName, e)); } } String driverName = dataSourceConfig.getDriver(); InstalledDriver installedDriver = driverRegistry.getValue().getInstalledDriver(driverName); if (installedDriver != null) { String moduleName = installedDriver.getModuleName() != null ? installedDriver.getModuleName().getName() : null; org.jboss.jca.common.api.metadata.ds.Driver driver = new DriverImpl(installedDriver.getDriverName(), installedDriver.getMajorVersion(), installedDriver.getMinorVersion(), moduleName, installedDriver.getDriverClassName(), installedDriver.getDataSourceClassName(), installedDriver.getXaDataSourceClassName()); drivers.put(driverName, driver); } dataSources = new DatasourcesImpl(Arrays.asList(dataSourceConfig), null, drivers); } else if (xaDataSourceConfig != null) { String xaDSClsName = xaDataSourceConfig.getXaDataSourceClass(); if (xaDSClsName != null) { try { Class<? extends XADataSource> xaDsCls = driverClassLoader().loadClass(xaDSClsName).asSubclass(XADataSource.class); JdbcDriverAdd.checkDSCls(xaDsCls, XADataSource.class); } catch (OperationFailedException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(e); } catch (ClassCastException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(ConnectorLogger.ROOT_LOGGER.notAValidDataSourceClass(xaDSClsName, XADataSource.class.getName())); } catch (ClassNotFoundException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(ConnectorLogger.ROOT_LOGGER.failedToLoadDataSourceClass(xaDSClsName, e)); } } String driverName = xaDataSourceConfig.getDriver(); InstalledDriver installedDriver = driverRegistry.getValue().getInstalledDriver(driverName); if (installedDriver != null) { String moduleName = installedDriver.getModuleName() != null ? installedDriver.getModuleName().getName() : null; org.jboss.jca.common.api.metadata.ds.Driver driver = new DriverImpl(installedDriver.getDriverName(), installedDriver.getMajorVersion(), installedDriver.getMinorVersion(), moduleName, installedDriver.getDriverClassName(), installedDriver.getDataSourceClassName(), installedDriver.getXaDataSourceClassName()); drivers.put(driverName, driver); } dataSources = new DatasourcesImpl(null, Arrays.asList(xaDataSourceConfig), drivers); } CommonDeployment c = createObjectsAndInjectValue(new URL("file://DataSourceDeployment"), dsName, "uniqueJdbcLocalId", "uniqueJdbcXAId", dataSources, AbstractDataSourceService.class.getClassLoader()); return c; } catch (MalformedURLException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(e); } catch (ValidateException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeployAndValidate(e); } } @Override protected ClassLoader getDeploymentClassLoader(String uniqueId) { return driverClassLoader(); } @Override protected String[] bindConnectionFactory(String deployment, final String jndi, Object cf) throws Throwable { // AS7-2222: Just hack it if (cf instanceof jakarta.resource.Referenceable) { ((jakarta.resource.Referenceable)cf).setReference(new Reference(jndi)); } // don't register because it's one during add operation return new String[] { jndi }; } @Override protected Object initAndInject(String className, List<? extends ConfigProperty> configs, ClassLoader cl) throws DeployException { try { Class clz = Class.forName(className, true, cl); Object o = clz.newInstance(); if (configs != null) { Injection injector = new Injection(); for (ConfigProperty cpmd : configs) { if (cpmd.isValueSet()) { if (XsdString.isNull(cpmd.getConfigPropertyType())) { injector.inject(o, cpmd.getConfigPropertyName().getValue(), cpmd.getConfigPropertyValue().getValue()); } else { injector.inject(o, cpmd.getConfigPropertyName().getValue(), cpmd.getConfigPropertyValue().getValue(), cpmd.getConfigPropertyType().getValue()); } } } } return o; } catch (Throwable t) { throw ConnectorLogger.ROOT_LOGGER.deploymentFailed(t, className); } } @Override protected org.jboss.jca.core.spi.security.SubjectFactory getSubjectFactory( org.jboss.jca.common.api.metadata.common.Credential credential, final String jndiName) throws DeployException { if (credential == null) return null; // safe assertion because all parsers create Credential assert credential instanceof Credential; try { return new ElytronSubjectFactory(authenticationContext.getOptionalValue(), new java.net.URI(jndiName)); } catch (URISyntaxException e) { throw ConnectorLogger.ROOT_LOGGER.cannotDeploy(e); } } @Override public CachedConnectionManager getCachedConnectionManager() { return ccmValue.getOptionalValue(); } @Override public ManagementRepository getManagementRepository() { return managementRepositoryValue.getValue(); } @Override protected void initAndInjectClassLoaderPlugin(ManagedConnectionFactory mcf, CommonDataSource dsMetadata) throws DeployException { ((BaseWrapperManagedConnectionFactory) mcf).setClassLoaderPlugin(new ClassLoaderPlugin() { @Override public ClassLoader getClassLoader() { return driverClassLoader(); } }); } @Override public TransactionIntegration getTransactionIntegration() { if (! WildFlySecurityManager.isChecking()) { currentThread().setContextClassLoader(TransactionIntegration.class.getClassLoader()); } else { doPrivileged(new SetContextClassLoaderFromClassAction(TransactionIntegration.class)); } try { return transactionIntegrationValue.getValue(); } finally { if (! WildFlySecurityManager.isChecking()) { currentThread().setContextClassLoader(null); } else { doPrivileged(ClearContextClassLoaderAction.getInstance()); } } } @Override protected ManagedConnectionFactory createMcf(XaDataSource arg0, String arg1, ClassLoader arg2) throws NotFoundException, DeployException { final XAManagedConnectionFactory xaManagedConnectionFactory = new XAManagedConnectionFactory(xaDataSourceConfig.getXaDataSourceProperty()); if (xaDataSourceConfig.getUrlDelimiter() != null) { xaManagedConnectionFactory.setURLDelimiter(xaDataSourceConfig.getUrlDelimiter()); } if (xaDataSourceConfig.getXaDataSourceClass() != null) { xaManagedConnectionFactory.setXADataSourceClass(xaDataSourceConfig.getXaDataSourceClass()); } if (xaDataSourceConfig.getUrlSelectorStrategyClassName() != null) { xaManagedConnectionFactory .setUrlSelectorStrategyClassName(xaDataSourceConfig.getUrlSelectorStrategyClassName()); } if (xaDataSourceConfig.getXaPool() != null && xaDataSourceConfig.getXaPool().isSameRmOverride() != null) { xaManagedConnectionFactory.setIsSameRMOverrideValue(xaDataSourceConfig.getXaPool().isSameRmOverride()); } if (xaDataSourceConfig.getNewConnectionSql() != null) { xaManagedConnectionFactory.setNewConnectionSQL(xaDataSourceConfig.getNewConnectionSql()); } if (xaDataSourceConfig.getUrlSelectorStrategyClassName() != null) { xaManagedConnectionFactory .setUrlSelectorStrategyClassName(xaDataSourceConfig.getUrlSelectorStrategyClassName()); } setMcfProperties(xaManagedConnectionFactory, xaDataSourceConfig, xaDataSourceConfig.getStatement()); return xaManagedConnectionFactory; } @Override protected ManagedConnectionFactory createMcf(org.jboss.jca.common.api.metadata.ds.DataSource arg0, String arg1, ClassLoader arg2) throws NotFoundException, DeployException { final LocalManagedConnectionFactory managedConnectionFactory = new LocalManagedConnectionFactory(); managedConnectionFactory.setDriverClass(dataSourceConfig.getDriverClass()); if (dataSourceConfig.getUrlDelimiter() != null) { try { managedConnectionFactory.setURLDelimiter(dataSourceConfig.getUrlDelimiter()); } catch (Exception e) { throw ConnectorLogger.ROOT_LOGGER.failedToGetUrlDelimiter(e); } } if (dataSourceConfig.getDataSourceClass() != null) { managedConnectionFactory.setDataSourceClass(dataSourceConfig.getDataSourceClass()); } if (dataSourceConfig.getConnectionProperties() != null) { managedConnectionFactory.setConnectionProperties(buildConfigPropsString(dataSourceConfig .getConnectionProperties())); } if (dataSourceConfig.getConnectionUrl() != null) { managedConnectionFactory.setConnectionURL(dataSourceConfig.getConnectionUrl()); } if (dataSourceConfig.getNewConnectionSql() != null) { managedConnectionFactory.setNewConnectionSQL(dataSourceConfig.getNewConnectionSql()); } if (dataSourceConfig.getUrlSelectorStrategyClassName() != null) { managedConnectionFactory.setUrlSelectorStrategyClassName(dataSourceConfig.getUrlSelectorStrategyClassName()); } if (dataSourceConfig.getPoolName() != null) { if (PoolConfiguration.getPoolsWithDisabledValidationLogging().contains(dataSourceConfig.getPoolName())) { managedConnectionFactory.setPoolValidationLoggingEnabled(false); } } setMcfProperties(managedConnectionFactory, dataSourceConfig, dataSourceConfig.getStatement()); return managedConnectionFactory; } private void setMcfProperties(final BaseWrapperManagedConnectionFactory managedConnectionFactory, CommonDataSource dataSourceConfig, final Statement statement) throws DeployException { if (dataSourceConfig.getTransactionIsolation() != null) { managedConnectionFactory.setTransactionIsolation(dataSourceConfig.getTransactionIsolation().name()); } final DsSecurity security = dataSourceConfig.getSecurity(); if (security != null) { if (security.getUserName() != null) { managedConnectionFactory.setUserName(security.getUserName()); } if (security.getPassword() != null) { managedConnectionFactory.setPassword(security.getPassword()); } } final TimeOut timeOut = dataSourceConfig.getTimeOut(); if (timeOut != null) { if (timeOut.getUseTryLock() != null) { managedConnectionFactory.setUseTryLock(timeOut.getUseTryLock().intValue()); } if (timeOut.getQueryTimeout() != null) { managedConnectionFactory.setQueryTimeout(timeOut.getQueryTimeout().intValue()); } if (timeOut.isSetTxQueryTimeout()) { managedConnectionFactory.setTransactionQueryTimeout(true); } } if (statement != null) { if (statement.getTrackStatements() != null) { managedConnectionFactory.setTrackStatements(statement.getTrackStatements().name()); } if (statement.isSharePreparedStatements() != null) { managedConnectionFactory.setSharePreparedStatements(statement.isSharePreparedStatements()); } if (statement.getPreparedStatementsCacheSize() != null) { managedConnectionFactory.setPreparedStatementCacheSize(statement.getPreparedStatementsCacheSize() .intValue()); } } final Validation validation = dataSourceConfig.getValidation(); if (validation != null) { if (validation.getCheckValidConnectionSql() != null) { managedConnectionFactory.setCheckValidConnectionSQL(validation.getCheckValidConnectionSql()); } final Extension validConnectionChecker = validation.getValidConnectionChecker(); if (validConnectionChecker != null) { if (validConnectionChecker.getClassName() != null) { managedConnectionFactory.setValidConnectionCheckerClassName(validConnectionChecker.getClassName()); } if (validConnectionChecker.getClassLoader() != null) { managedConnectionFactory.setValidConnectionCheckerClassLoader(validConnectionChecker.getClassLoader()); } if (validConnectionChecker.getConfigPropertiesMap() != null) { managedConnectionFactory .setValidConnectionCheckerProperties(buildConfigPropsString(validConnectionChecker .getConfigPropertiesMap())); } } final Extension exceptionSorter = validation.getExceptionSorter(); if (exceptionSorter != null) { if (exceptionSorter.getClassName() != null) { managedConnectionFactory.setExceptionSorterClassName(exceptionSorter.getClassName()); } if (exceptionSorter.getClassLoader() != null) { managedConnectionFactory.setExceptionSorterClassLoader(exceptionSorter.getClassLoader()); } if (exceptionSorter.getConfigPropertiesMap() != null) { managedConnectionFactory.setExceptionSorterProperties(buildConfigPropsString(exceptionSorter .getConfigPropertiesMap())); } } final Extension staleConnectionChecker = validation.getStaleConnectionChecker(); if (staleConnectionChecker != null) { if (staleConnectionChecker.getClassName() != null) { managedConnectionFactory.setStaleConnectionCheckerClassName(staleConnectionChecker.getClassName()); } if (staleConnectionChecker.getClassLoader() != null) { managedConnectionFactory.setExceptionSorterClassLoader(staleConnectionChecker.getClassLoader()); } if (staleConnectionChecker.getConfigPropertiesMap() != null) { managedConnectionFactory .setStaleConnectionCheckerProperties(buildConfigPropsString(staleConnectionChecker .getConfigPropertiesMap())); } } } } // Override this method to change how dsName is build in AS7 @Override protected String buildJndiName(String rawJndiName, Boolean javaContext) { return Util.cleanJndiName(rawJndiName, javaContext); } @Override protected DeployersLogger getLogger() { return DEPLOYERS_LOGGER; } @Override protected jakarta.resource.spi.ResourceAdapter createRa(String uniqueId, ClassLoader cl) throws NotFoundException, DeployException { List<? extends ConfigProperty> l = new ArrayList<ConfigProperty>(); jakarta.resource.spi.ResourceAdapter rar = (jakarta.resource.spi.ResourceAdapter) initAndInject(JDBCResourceAdapter.class.getName(), l, cl); return rar; } @Override protected String registerResourceAdapterToResourceAdapterRepository(jakarta.resource.spi.ResourceAdapter instance) { return raRepository.getValue().registerResourceAdapter(instance); } } }
35,153
47.02459
172
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DsParser.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, Red Hat Middleware LLC, 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.connector.subsystems.datasources; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOCATION_RETRY; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOCATION_RETRY_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOW_MULTIPLE_USERS; import static org.jboss.as.connector.subsystems.datasources.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.datasources.Constants.CHECK_VALID_CONNECTION_SQL; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTABLE; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_LISTENER_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_LISTENER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_PROPERTY_VALUE; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_URL; import static org.jboss.as.connector.subsystems.datasources.Constants.CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_DRIVER; import static org.jboss.as.connector.subsystems.datasources.Constants.DATA_SOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MAJOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MINOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MODULE_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_XA_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.INTERLEAVING; import static org.jboss.as.connector.subsystems.datasources.Constants.JDBC_DRIVER_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.JTA; import static org.jboss.as.connector.subsystems.datasources.Constants.MCP; import static org.jboss.as.connector.subsystems.datasources.Constants.MODULE_SLOT; import static org.jboss.as.connector.subsystems.datasources.Constants.NEW_CONNECTION_SQL; import static org.jboss.as.connector.subsystems.datasources.Constants.NO_RECOVERY; import static org.jboss.as.connector.subsystems.datasources.Constants.NO_TX_SEPARATE_POOL; import static org.jboss.as.connector.subsystems.datasources.Constants.PAD_XID; import static org.jboss.as.connector.subsystems.datasources.Constants.PASSWORD; import static org.jboss.as.connector.subsystems.datasources.Constants.POOLNAME_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.PREPARED_STATEMENTS_CACHE_SIZE; import static org.jboss.as.connector.subsystems.datasources.Constants.QUERY_TIMEOUT; import static org.jboss.as.connector.subsystems.datasources.Constants.REAUTHPLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.REAUTH_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_PASSWORD; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_USERNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVER_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVER_PLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.SAME_RM_OVERRIDE; import static org.jboss.as.connector.subsystems.datasources.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.datasources.Constants.SET_TX_QUERY_TIMEOUT; import static org.jboss.as.connector.subsystems.datasources.Constants.SHARE_PREPARED_STATEMENTS; import static org.jboss.as.connector.subsystems.datasources.Constants.SPY; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.TRACKING; import static org.jboss.as.connector.subsystems.datasources.Constants.TRACK_STATEMENTS; import static org.jboss.as.connector.subsystems.datasources.Constants.TRANSACTION_ISOLATION; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_DELIMITER; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_PROPERTY; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_SELECTOR_STRATEGY_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.USERNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.USE_CCM; import static org.jboss.as.connector.subsystems.datasources.Constants.USE_TRY_LOCK; import static org.jboss.as.connector.subsystems.datasources.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.WRAP_XA_RESOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.XADATASOURCE_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.XADATASOURCE_PROPERTY_VALUE; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_RESOURCE_TIMEOUT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ENABLE; 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.PERSISTENT; import static org.jboss.as.controller.parsing.ParseUtils.isNoNamespaceAttribute; import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.stream.XMLStreamException; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.metadata.api.ds.DsSecurity; import org.jboss.as.connector.util.AbstractParser; import org.jboss.as.connector.util.ParserException; import org.jboss.as.controller.parsing.ParseUtils; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.CommonBundle; import org.jboss.jca.common.api.metadata.Defaults; import org.jboss.jca.common.api.metadata.common.Capacity; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.DataSources; import org.jboss.jca.common.api.metadata.ds.Driver; import org.jboss.jca.common.api.metadata.ds.DsPool; import org.jboss.jca.common.api.metadata.ds.DsXaPool; import org.jboss.jca.common.api.metadata.ds.Statement; import org.jboss.jca.common.api.metadata.ds.TimeOut; import org.jboss.jca.common.api.metadata.ds.Validation; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.logging.Messages; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * A DsParser. * * @author <a href="[email protected]">Stefano Maestri</a> */ public class DsParser extends AbstractParser { /** * The bundle */ private static CommonBundle bundle = Messages.getBundle(CommonBundle.class); public void parse(final XMLExtendedStreamReader reader, final List<ModelNode> list, ModelNode parentAddress) throws Exception { //iterate over tags int iterate; try { iterate = reader.nextTag(); } catch (XMLStreamException e) { //founding a non tag..go on. Normally non-tag found at beginning are comments or DTD declaration iterate = reader.nextTag(); } switch (iterate) { case END_ELEMENT: { // should mean we're done, so ignore it. break; } case START_ELEMENT: { switch (Tag.forName(reader.getLocalName())) { case DATASOURCES: { parseDataSources(reader, list, parentAddress); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } default: throw new IllegalStateException(); } } private void parseDataSources(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Tag.forName(reader.getLocalName()) == Tag.DATASOURCES) // should mean we're done, so ignore it. return; } case START_ELEMENT: { switch (DataSources.Tag.forName(reader.getLocalName())) { case DATASOURCE: { switch (Namespace.forUri(reader.getNamespaceURI())) { case DATASOURCES_1_1: case DATASOURCES_2_0: parseDataSource_1_0(reader, list, parentAddress); break; case DATASOURCES_1_2: parseDataSource_1_2(reader, list, parentAddress); break; case DATASOURCES_3_0: parseDataSource_3_0(reader, list, parentAddress); break; case DATASOURCES_4_0: parseDataSource_4_0(reader, list, parentAddress); break; default: parseDataSource_7_0(reader, list, parentAddress); break; } break; } case XA_DATASOURCE: { switch (Namespace.forUri(reader.getNamespaceURI())) { case DATASOURCES_1_1: case DATASOURCES_2_0: parseXADataSource_1_0(reader, list, parentAddress); break; case DATASOURCES_1_2: parseXADataSource_1_2(reader, list, parentAddress); break; case DATASOURCES_3_0: parseXADataSource_3_0(reader, list, parentAddress); break; case DATASOURCES_4_0: parseXADataSource_4_0(reader, list, parentAddress); break; default: parseXADataSource_7_0(reader, list, parentAddress); break; } break; } case DRIVERS: { break; } case DRIVER: { parseDriver(reader, list, parentAddress); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseDataSource_1_2(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); boolean enabled = Defaults.ENABLED.booleanValue(); // Persist the enabled flag because xml default is != from DMR default boolean persistEnabled = true; final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final DataSource.Attribute attribute = DataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { enabled = Boolean.parseBoolean(value); //ENABLED.parseAndSetParameter(value, operation, reader); persistEnabled = true; } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } case JTA: { final String value = rawAttributeText(reader, JTA.getXmlName()); if (value != null) { JTA.parseAndSetParameter(value, operation, reader); } break; } case CONNECTABLE: { final String value = rawAttributeText(reader, CONNECTABLE.getXmlName()); if (value != null) { CONNECTABLE.parseAndSetParameter(value, operation, reader); } break; } default: if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); } break; } else { throw ParseUtils.unexpectedAttribute(reader, i); } } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(DATA_SOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> configPropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DATASOURCE) { list.add(operation); list.addAll(configPropertiesOperations); if (enabled) { final ModelNode enableOperation = new ModelNode(); enableOperation.get(OP).set(ENABLE); enableOperation.get(OP_ADDR).set(dsAddress); enableOperation.get(PERSISTENT).set(persistEnabled); list.add(enableOperation); } return; } else { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (DataSource.Tag.forName(reader.getLocalName())) { case CONNECTION_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(CONNECTION_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); CONNECTION_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); configPropertiesOperations.add(configOperation); break; } case CONNECTION_URL: { String value = rawElementText(reader); CONNECTION_URL.parseAndSetParameter(value, operation, reader); break; } case DRIVER_CLASS: { String value = rawElementText(reader); DRIVER_CLASS.parseAndSetParameter(value, operation, reader); break; } case DATASOURCE_CLASS: { String value = rawElementText(reader); DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case POOL: { parsePool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { parseDsSecurity(reader, operation); break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSettings(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseXADataSource_1_2(XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); boolean enabled = Defaults.ENABLED.booleanValue(); // Persist the enabled flag because xml default is != from DMR default boolean persistEnabled = true; final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final XaDataSource.Attribute attribute = XaDataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { enabled = Boolean.parseBoolean(value); //ENABLED.parseAndSetParameter(value, operation, reader); persistEnabled = true; } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } default: if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); } break; } else { throw ParseUtils.unexpectedAttribute(reader, i); } } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(XA_DATASOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> xadatasourcePropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.XA_DATASOURCE) { list.add(operation); list.addAll(xadatasourcePropertiesOperations); if (enabled) { final ModelNode enableOperation = new ModelNode(); enableOperation.get(OP).set(ENABLE); enableOperation.get(OP_ADDR).set(dsAddress); enableOperation.get(PERSISTENT).set(persistEnabled); list.add(enableOperation); } return; } else { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (XaDataSource.Tag.forName(reader.getLocalName())) { case XA_DATASOURCE_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(XADATASOURCE_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); XADATASOURCE_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); xadatasourcePropertiesOperations.add(configOperation); break; } case XA_DATASOURCE_CLASS: { String value = rawElementText(reader); XA_DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case XA_POOL: { parseXaPool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { parseDsSecurity(reader, operation); break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSettings(reader, operation); break; } case RECOVERY: { parseRecovery(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseDriver(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { final ModelNode driverAddress = parentAddress.clone(); final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); String driverName = null; for (Driver.Attribute attribute : Driver.Attribute.values()) { switch (attribute) { case NAME: { driverName = rawAttributeText(reader, attribute.getLocalName()); break; } case MAJOR_VERSION: { String value = rawAttributeText(reader, DRIVER_MAJOR_VERSION.getXmlName()); DRIVER_MAJOR_VERSION.parseAndSetParameter(value, operation, reader); break; } case MINOR_VERSION: { String value = rawAttributeText(reader, DRIVER_MINOR_VERSION.getXmlName()); DRIVER_MINOR_VERSION.parseAndSetParameter(value, operation, reader); break; } case MODULE: { String moduleName = rawAttributeText(reader, DRIVER_MODULE_NAME.getXmlName()); String slot = null; int slotId = findSlot(moduleName); if(slotId != -1) { slot = moduleName.substring(slotId + 1); moduleName = moduleName.substring(0, slotId); } DRIVER_MODULE_NAME.parseAndSetParameter(moduleName, operation, reader); if (slot != null) { MODULE_SLOT.parseAndSetParameter(slot, operation, reader); } break; } default: break; } } driverAddress.add(JDBC_DRIVER_NAME, driverName); driverAddress.protect(); operation.get(OP_ADDR).set(driverAddress); boolean driverClassMatched = false; boolean xaDatasourceClassMatched = false; boolean datasourceClassMatched = false; //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DRIVER) { list.add(operation); return; } else { if (Driver.Tag.forName(reader.getLocalName()) == Driver.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (Driver.Tag.forName(reader.getLocalName())) { case DATASOURCE_CLASS: { if (datasourceClassMatched) { throw new ParserException(bundle.unexpectedElement(DRIVER_DATASOURCE_CLASS_NAME.getXmlName())); } String value = rawElementText(reader); DRIVER_DATASOURCE_CLASS_NAME.parseAndSetParameter(value, operation, reader); datasourceClassMatched = true; break; } case XA_DATASOURCE_CLASS: { if (xaDatasourceClassMatched) { throw new ParserException(bundle.unexpectedElement(DRIVER_XA_DATASOURCE_CLASS_NAME.getXmlName())); } String value = rawElementText(reader); DRIVER_XA_DATASOURCE_CLASS_NAME.parseAndSetParameter(value, operation, reader); xaDatasourceClassMatched = true; break; } case DRIVER_CLASS: { if (driverClassMatched) { throw new ParserException(bundle.unexpectedElement(DRIVER_CLASS_NAME.getXmlName())); } String value = rawElementText(reader); DRIVER_CLASS_NAME.parseAndSetParameter(value, operation, reader); driverClassMatched = true; break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseXADataSource_1_0(XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final XaDataSource.Attribute attribute = XaDataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, operation, reader); } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } default: throw ParseUtils.unexpectedAttribute(reader, i); } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(XA_DATASOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> xadatasourcePropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.XA_DATASOURCE) { list.add(operation); list.addAll(xadatasourcePropertiesOperations); return; } else { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (XaDataSource.Tag.forName(reader.getLocalName())) { case XA_DATASOURCE_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(XADATASOURCE_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); XADATASOURCE_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); xadatasourcePropertiesOperations.add(configOperation); break; } case XA_DATASOURCE_CLASS: { String value = rawElementText(reader); XA_DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case XA_POOL: { parseXaPool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_PROPERTY: { String value = rawElementText(reader); URL_PROPERTY.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { parseDsSecurity(reader, operation); break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSettings(reader, operation); break; } case RECOVERY: { parseRecovery(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseXADataSource_3_0(XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final XaDataSource.Attribute attribute = XaDataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, operation, reader); } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } case CONNECTABLE: { final String value = rawAttributeText(reader, CONNECTABLE.getXmlName()); if (value != null) { CONNECTABLE.parseAndSetParameter(value, operation, reader); } break; } case TRACKING: { final String value = rawAttributeText(reader, TRACKING.getXmlName()); if (value != null) { TRACKING.parseAndSetParameter(value, operation, reader); } break; } default: if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); } break; } else { throw ParseUtils.unexpectedAttribute(reader, i); } } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(XA_DATASOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> xadatasourcePropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.XA_DATASOURCE) { list.add(operation); list.addAll(xadatasourcePropertiesOperations); return; } else { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (XaDataSource.Tag.forName(reader.getLocalName())) { case XA_DATASOURCE_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(XADATASOURCE_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); XADATASOURCE_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); xadatasourcePropertiesOperations.add(configOperation); break; } case XA_DATASOURCE_CLASS: { String value = rawElementText(reader); XA_DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case XA_POOL: { parseXaPool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_PROPERTY: { String value = rawElementText(reader); URL_PROPERTY.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { parseDsSecurity(reader, operation); break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSettings(reader, operation); break; } case RECOVERY: { parseRecovery(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseXADataSource_4_0(XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final XaDataSource.Attribute attribute = XaDataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, operation, reader); } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } case CONNECTABLE: { final String value = rawAttributeText(reader, CONNECTABLE.getXmlName()); if (value != null) { CONNECTABLE.parseAndSetParameter(value, operation, reader); } break; } case MCP: { final String value = rawAttributeText(reader, MCP.getXmlName()); if (value != null) { MCP.parseAndSetParameter(value, operation, reader); } break; } case ENLISTMENT_TRACE: { final String value = rawAttributeText(reader, ENLISTMENT_TRACE.getXmlName()); ENLISTMENT_TRACE.parseAndSetParameter(value, operation, reader); break; } case TRACKING: { final String value = rawAttributeText(reader, TRACKING.getXmlName()); if (value != null) { TRACKING.parseAndSetParameter(value, operation, reader); } break; } default: if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); } break; } else { throw ParseUtils.unexpectedAttribute(reader, i); } } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(XA_DATASOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> xadatasourcePropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.XA_DATASOURCE) { list.add(operation); list.addAll(xadatasourcePropertiesOperations); return; } else { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (XaDataSource.Tag.forName(reader.getLocalName())) { case XA_DATASOURCE_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(XADATASOURCE_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); XADATASOURCE_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); xadatasourcePropertiesOperations.add(configOperation); break; } case XA_DATASOURCE_CLASS: { String value = rawElementText(reader); XA_DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case XA_POOL: { parseXaPool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_PROPERTY: { String value = rawElementText(reader); URL_PROPERTY.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { switch (Namespace.forUri(reader.getNamespaceURI())) { // This method is only called for version 4 and later. case DATASOURCES_4_0: parseDsSecurity(reader, operation); break; default: parseDsSecurity_5_0(reader, operation); break; } break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSettings(reader, operation); break; } case RECOVERY: { parseRecovery(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseXADataSource_7_0(XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final XaDataSource.Attribute attribute = XaDataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, operation, reader); } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } case CONNECTABLE: { final String value = rawAttributeText(reader, CONNECTABLE.getXmlName()); if (value != null) { CONNECTABLE.parseAndSetParameter(value, operation, reader); } break; } case MCP: { final String value = rawAttributeText(reader, MCP.getXmlName()); if (value != null) { MCP.parseAndSetParameter(value, operation, reader); } break; } case ENLISTMENT_TRACE: { final String value = rawAttributeText(reader, ENLISTMENT_TRACE.getXmlName()); ENLISTMENT_TRACE.parseAndSetParameter(value, operation, reader); break; } case TRACKING: { final String value = rawAttributeText(reader, TRACKING.getXmlName()); if (value != null) { TRACKING.parseAndSetParameter(value, operation, reader); } break; } default: if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); } break; } else { throw ParseUtils.unexpectedAttribute(reader, i); } } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(XA_DATASOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> xadatasourcePropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.XA_DATASOURCE) { list.add(operation); list.addAll(xadatasourcePropertiesOperations); return; } else { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (XaDataSource.Tag.forName(reader.getLocalName())) { case XA_DATASOURCE_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(XADATASOURCE_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); XADATASOURCE_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); xadatasourcePropertiesOperations.add(configOperation); break; } case XA_DATASOURCE_CLASS: { String value = rawElementText(reader); XA_DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case XA_POOL: { parseXaPool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_PROPERTY: { String value = rawElementText(reader); URL_PROPERTY.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { switch (Namespace.forUri(reader.getNamespaceURI())) { // This method is only called for version 4 and later. case DATASOURCES_4_0: parseDsSecurity(reader, operation); break; default: parseDsSecurity_5_0(reader, operation); break; } break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSetting_7_0(reader, operation); break; } case RECOVERY: { parseRecovery(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseDsSecurity(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { boolean securityDomainMatched = false; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY) { //it's fine, do nothing return; } else { if (DsSecurity.Tag.forName(reader.getLocalName()) == DsSecurity.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { final String localName = reader.getLocalName(); DsSecurity.Tag tag = DsSecurity.Tag.forName(localName); if (localName == null) break; if (localName.equals(DsSecurity.Tag.PASSWORD.getLocalName())) { String value = rawElementText(reader); PASSWORD.parseAndSetParameter(value, operation, reader); break; } else if (localName.equals(DsSecurity.Tag.USER_NAME.getLocalName())) { String value = rawElementText(reader); USERNAME.parseAndSetParameter(value, operation, reader); break; } else if (localName.equals(DsSecurity.Tag.SECURITY_DOMAIN.getLocalName())) { if (securityDomainMatched) { throw new ParserException(bundle.unexpectedElement(SECURITY_DOMAIN.getXmlName())); } String value = rawElementText(reader); SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader); securityDomainMatched = true; break; } else if (localName.equals(DsSecurity.Tag.REAUTH_PLUGIN.getLocalName())) { parseExtension(reader, tag.getLocalName(), operation, REAUTH_PLUGIN_CLASSNAME, REAUTHPLUGIN_PROPERTIES); break; } else if (localName.equals(CREDENTIAL_REFERENCE.getXmlName())) { CREDENTIAL_REFERENCE.getParser().parseElement(CREDENTIAL_REFERENCE, reader, operation); break; } else { throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseDsSecurity_5_0(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { boolean securityDomainMatched = false; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY) { //it's fine, do nothing return; } else { if (DsSecurity.Tag.forName(reader.getLocalName()) == DsSecurity.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { DsSecurity.Tag tag = DsSecurity.Tag.forName(reader.getLocalName()); switch (tag) { case PASSWORD: { String value = rawElementText(reader); PASSWORD.parseAndSetParameter(value, operation, reader); break; } case USER_NAME: { String value = rawElementText(reader); USERNAME.parseAndSetParameter(value, operation, reader); break; } case SECURITY_DOMAIN: { if (securityDomainMatched) { throw new ParserException(bundle.unexpectedElement(SECURITY_DOMAIN.getXmlName())); } String value = rawElementText(reader); SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader); securityDomainMatched = true; break; } case ELYTRON_ENABLED: { String value = rawElementText(reader); value = value == null ? "true" : value; ELYTRON_ENABLED.parseAndSetParameter(value, operation, reader); break; } case AUTHENTICATION_CONTEXT: { String value = rawElementText(reader); AUTHENTICATION_CONTEXT.parseAndSetParameter(value, operation, reader); break; } case REAUTH_PLUGIN: { parseExtension(reader, tag.getLocalName(), operation, REAUTH_PLUGIN_CLASSNAME, REAUTHPLUGIN_PROPERTIES); break; } case CREDENTIAL_REFERENCE: { CREDENTIAL_REFERENCE.getParser().parseElement(CREDENTIAL_REFERENCE, reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseDataSource_1_0(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final DataSource.Attribute attribute = DataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, operation, reader); } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } case JTA: { final String value = rawAttributeText(reader, JTA.getXmlName()); if (value != null) { JTA.parseAndSetParameter(value, operation, reader); } break; } default: throw ParseUtils.unexpectedAttribute(reader, i); } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(DATA_SOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> configPropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DATASOURCE) { list.add(operation); list.addAll(configPropertiesOperations); return; } else { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (DataSource.Tag.forName(reader.getLocalName())) { case CONNECTION_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(CONNECTION_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); CONNECTION_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); configPropertiesOperations.add(configOperation); break; } case CONNECTION_URL: { String value = rawElementText(reader); CONNECTION_URL.parseAndSetParameter(value, operation, reader); break; } case DRIVER_CLASS: { String value = rawElementText(reader); DRIVER_CLASS.parseAndSetParameter(value, operation, reader); break; } case DATASOURCE_CLASS: { String value = rawElementText(reader); DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case POOL: { parsePool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { parseDsSecurity(reader, operation); break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSettings(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseDataSource_3_0(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final DataSource.Attribute attribute = DataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, operation, reader); } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } case JTA: { final String value = rawAttributeText(reader, JTA.getXmlName()); if (value != null) { JTA.parseAndSetParameter(value, operation, reader); } break; } case CONNECTABLE: { final String value = rawAttributeText(reader, CONNECTABLE.getXmlName()); if (value != null) { CONNECTABLE.parseAndSetParameter(value, operation, reader); } break; } case TRACKING: { final String value = rawAttributeText(reader, TRACKING.getXmlName()); if (value != null) { TRACKING.parseAndSetParameter(value, operation, reader); } break; } default: if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); } break; } else { throw ParseUtils.unexpectedAttribute(reader, i); } } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(DATA_SOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> configPropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DATASOURCE) { list.add(operation); list.addAll(configPropertiesOperations); return; } else { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (DataSource.Tag.forName(reader.getLocalName())) { case CONNECTION_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(CONNECTION_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); CONNECTION_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); configPropertiesOperations.add(configOperation); break; } case CONNECTION_URL: { String value = rawElementText(reader); CONNECTION_URL.parseAndSetParameter(value, operation, reader); break; } case DRIVER_CLASS: { String value = rawElementText(reader); DRIVER_CLASS.parseAndSetParameter(value, operation, reader); break; } case DATASOURCE_CLASS: { String value = rawElementText(reader); DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case POOL: { parsePool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { parseDsSecurity(reader, operation); break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSettings(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseDataSource_4_0(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final DataSource.Attribute attribute = DataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, operation, reader); } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } case JTA: { final String value = rawAttributeText(reader, JTA.getXmlName()); if (value != null) { JTA.parseAndSetParameter(value, operation, reader); } break; } case CONNECTABLE: { final String value = rawAttributeText(reader, CONNECTABLE.getXmlName()); if (value != null) { CONNECTABLE.parseAndSetParameter(value, operation, reader); } break; } case MCP: { final String value = rawAttributeText(reader, MCP.getXmlName()); if (value != null) { MCP.parseAndSetParameter(value, operation, reader); } break; } case ENLISTMENT_TRACE: { final String value = rawAttributeText(reader, ENLISTMENT_TRACE.getXmlName()); ENLISTMENT_TRACE.parseAndSetParameter(value, operation, reader); break; } case TRACKING: { final String value = rawAttributeText(reader, TRACKING.getXmlName()); if (value != null) { TRACKING.parseAndSetParameter(value, operation, reader); } break; } default: if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); } break; } else { throw ParseUtils.unexpectedAttribute(reader, i); } } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(DATA_SOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> configPropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DATASOURCE) { list.add(operation); list.addAll(configPropertiesOperations); return; } else { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (DataSource.Tag.forName(reader.getLocalName())) { case CONNECTION_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(CONNECTION_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); CONNECTION_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); configPropertiesOperations.add(configOperation); break; } case CONNECTION_URL: { String value = rawElementText(reader); CONNECTION_URL.parseAndSetParameter(value, operation, reader); break; } case DRIVER_CLASS: { String value = rawElementText(reader); DRIVER_CLASS.parseAndSetParameter(value, operation, reader); break; } case DATASOURCE_CLASS: { String value = rawElementText(reader); DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case POOL: { parsePool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { switch (Namespace.forUri(reader.getNamespaceURI())) { // This method is only called for version 4 and later. case DATASOURCES_4_0: parseDsSecurity(reader, operation); break; default: parseDsSecurity_5_0(reader, operation); break; } break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSettings(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseDataSource_7_0(final XMLExtendedStreamReader reader, final List<ModelNode> list, final ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { String poolName = null; final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); } final DataSource.Attribute attribute = DataSource.Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { final String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, operation, reader); } break; } case JNDI_NAME: { final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOLNAME_NAME); break; } case USE_JAVA_CONTEXT: { final String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, operation, reader); } break; } case SPY: { final String value = rawAttributeText(reader, SPY.getXmlName()); if (value != null) { SPY.parseAndSetParameter(value, operation, reader); } break; } case USE_CCM: { final String value = rawAttributeText(reader, USE_CCM.getXmlName()); if (value != null) { USE_CCM.parseAndSetParameter(value, operation, reader); } break; } case JTA: { final String value = rawAttributeText(reader, JTA.getXmlName()); if (value != null) { JTA.parseAndSetParameter(value, operation, reader); } break; } case CONNECTABLE: { final String value = rawAttributeText(reader, CONNECTABLE.getXmlName()); if (value != null) { CONNECTABLE.parseAndSetParameter(value, operation, reader); } break; } case MCP: { final String value = rawAttributeText(reader, MCP.getXmlName()); if (value != null) { MCP.parseAndSetParameter(value, operation, reader); } break; } case ENLISTMENT_TRACE: { final String value = rawAttributeText(reader, ENLISTMENT_TRACE.getXmlName()); ENLISTMENT_TRACE.parseAndSetParameter(value, operation, reader); break; } case TRACKING: { final String value = rawAttributeText(reader, TRACKING.getXmlName()); if (value != null) { TRACKING.parseAndSetParameter(value, operation, reader); } break; } default: if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { Constants.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); } break; } else { throw ParseUtils.unexpectedAttribute(reader, i); } } } final ModelNode dsAddress = parentAddress.clone(); dsAddress.add(DATA_SOURCE, poolName); dsAddress.protect(); operation.get(OP_ADDR).set(dsAddress); List<ModelNode> configPropertiesOperations = new ArrayList<ModelNode>(0); //elements reading while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.DATASOURCE) { list.add(operation); list.addAll(configPropertiesOperations); return; } else { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (DataSource.Tag.forName(reader.getLocalName())) { case CONNECTION_PROPERTY: { String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final ModelNode configOperation = new ModelNode(); configOperation.get(OP).set(ADD); final ModelNode configAddress = dsAddress.clone(); configAddress.add(CONNECTION_PROPERTIES.getName(), name); configAddress.protect(); configOperation.get(OP_ADDR).set(configAddress); CONNECTION_PROPERTY_VALUE.parseAndSetParameter(value, configOperation, reader); configPropertiesOperations.add(configOperation); break; } case CONNECTION_URL: { String value = rawElementText(reader); CONNECTION_URL.parseAndSetParameter(value, operation, reader); break; } case DRIVER_CLASS: { String value = rawElementText(reader); DRIVER_CLASS.parseAndSetParameter(value, operation, reader); break; } case DATASOURCE_CLASS: { String value = rawElementText(reader); DATASOURCE_CLASS.parseAndSetParameter(value, operation, reader); break; } case DRIVER: { String value = rawElementText(reader); DATASOURCE_DRIVER.parseAndSetParameter(value, operation, reader); break; } case POOL: { parsePool(reader, operation); break; } case NEW_CONNECTION_SQL: { String value = rawElementText(reader); NEW_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case URL_DELIMITER: { String value = rawElementText(reader); URL_DELIMITER.parseAndSetParameter(value, operation, reader); break; } case URL_SELECTOR_STRATEGY_CLASS_NAME: { String value = rawElementText(reader); URL_SELECTOR_STRATEGY_CLASS_NAME.parseAndSetParameter(value, operation, reader); break; } case TRANSACTION_ISOLATION: { String value = rawElementText(reader); TRANSACTION_ISOLATION.parseAndSetParameter(value, operation, reader); break; } case SECURITY: { switch (Namespace.forUri(reader.getNamespaceURI())) { // This method is only called for version 4 and later. case DATASOURCES_4_0: parseDsSecurity(reader, operation); break; default: parseDsSecurity_5_0(reader, operation); break; } break; } case STATEMENT: { parseStatementSettings(reader, operation); break; } case TIMEOUT: { parseTimeOutSettings(reader, operation); break; } case VALIDATION: { parseValidationSetting_7_0(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parsePool(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.POOL) { return; //it's fine. Do nothing } else { if (DsPool.Tag.forName(reader.getLocalName()) == DsPool.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (DsPool.Tag.forName(reader.getLocalName())) { case MAX_POOL_SIZE: { String value = rawElementText(reader); MAX_POOL_SIZE.parseAndSetParameter(value, operation, reader); break; } case INITIAL_POOL_SIZE: { String value = rawElementText(reader); INITIAL_POOL_SIZE.parseAndSetParameter(value, operation, reader); break; } case MIN_POOL_SIZE: { String value = rawElementText(reader); MIN_POOL_SIZE.parseAndSetParameter(value, operation, reader); break; } case PREFILL: { String value = rawElementText(reader); POOL_PREFILL.parseAndSetParameter(value, operation, reader); break; } case FAIR: { String value = rawElementText(reader); POOL_FAIR.parseAndSetParameter(value, operation, reader); break; } case USE_STRICT_MIN: { String value = rawElementText(reader); POOL_USE_STRICT_MIN.parseAndSetParameter(value, operation, reader); break; } case FLUSH_STRATEGY: { String value = rawElementText(reader); POOL_FLUSH_STRATEGY.parseAndSetParameter(value, operation, reader); break; } case ALLOW_MULTIPLE_USERS: { String value = rawElementText(reader); ALLOW_MULTIPLE_USERS.parseAndSetParameter(value, operation, reader); break; } case CAPACITY: { parseCapacity(reader, operation); break; } case CONNECTION_LISTENER: { parseExtension(reader, reader.getLocalName(), operation, CONNECTION_LISTENER_CLASS, CONNECTION_LISTENER_PROPERTIES); break; } case UNKNOWN: { throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } default: { throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseXaPool(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.XA_POOL) { return; //it's fine. Do nothing } else { if (DsXaPool.Tag.forName(reader.getLocalName()) == DsXaPool.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (DsXaPool.Tag.forName(reader.getLocalName())) { case MAX_POOL_SIZE: { String value = rawElementText(reader); MAX_POOL_SIZE.parseAndSetParameter(value, operation, reader); break; } case INITIAL_POOL_SIZE: { String value = rawElementText(reader); INITIAL_POOL_SIZE.parseAndSetParameter(value, operation, reader); break; } case MIN_POOL_SIZE: { String value = rawElementText(reader); MIN_POOL_SIZE.parseAndSetParameter(value, operation, reader); break; } case PREFILL: { String value = rawElementText(reader); POOL_PREFILL.parseAndSetParameter(value, operation, reader); break; } case FAIR: { String value = rawElementText(reader); POOL_FAIR.parseAndSetParameter(value, operation, reader); break; } case USE_STRICT_MIN: { String value = rawElementText(reader); POOL_USE_STRICT_MIN.parseAndSetParameter(value, operation, reader); break; } case FLUSH_STRATEGY: { String value = rawElementText(reader); POOL_FLUSH_STRATEGY.parseAndSetParameter(value, operation, reader); break; } case ALLOW_MULTIPLE_USERS: { String value = rawElementText(reader); ALLOW_MULTIPLE_USERS.parseAndSetParameter(value, operation, reader); break; } case CONNECTION_LISTENER: { parseExtension(reader, reader.getLocalName(), operation, CONNECTION_LISTENER_CLASS, CONNECTION_LISTENER_PROPERTIES); break; } case INTERLEAVING: { //tag presence is sufficient to set it to true String value = rawElementText(reader); value = value == null ? "true" : value; INTERLEAVING.parseAndSetParameter(value, operation, reader); break; } case IS_SAME_RM_OVERRIDE: { String value = rawElementText(reader); SAME_RM_OVERRIDE.parseAndSetParameter(value, operation, reader); break; } case NO_TX_SEPARATE_POOLS: { //tag presence is sufficient to set it to true String value = rawElementText(reader); value = value == null ? "true" : value; NO_TX_SEPARATE_POOL.parseAndSetParameter(value, operation, reader); break; } case PAD_XID: { String value = rawElementText(reader); PAD_XID.parseAndSetParameter(value, operation, reader); break; } case WRAP_XA_RESOURCE: { String value = rawElementText(reader); WRAP_XA_RESOURCE.parseAndSetParameter(value, operation, reader); break; } case CAPACITY: { parseCapacity(reader, operation); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseCapacity(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DsPool.Tag.forName(reader.getLocalName()) == DsPool.Tag.CAPACITY) { return; } else { if (Capacity.Tag.forName(reader.getLocalName()) == Capacity.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (Capacity.Tag.forName(reader.getLocalName())) { case INCREMENTER: { parseExtension(reader, reader.getLocalName(), operation, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES); break; } case DECREMENTER: { parseExtension(reader, reader.getLocalName(), operation, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseRecovery(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { for (Recovery.Attribute attribute : Recovery.Attribute.values()) { switch (attribute) { case NO_RECOVERY: { String value = rawAttributeText(reader, NO_RECOVERY.getXmlName()); NO_RECOVERY.parseAndSetParameter(value, operation, reader); break; } default: break; } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.RECOVERY) { return; } else { if (Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { Recovery.Tag tag = Recovery.Tag.forName(reader.getLocalName()); switch (tag) { case RECOVER_CREDENTIAL: { switch (Namespace.forUri(reader.getNamespaceURI())) { case DATASOURCES_1_1: case DATASOURCES_1_2: case DATASOURCES_2_0: case DATASOURCES_3_0: case DATASOURCES_4_0: parseCredential(reader, operation); break; default: parseCredential_5_0(reader, operation); break; } break; } case RECOVER_PLUGIN: { parseExtension(reader, tag.getLocalName(), operation, RECOVER_PLUGIN_CLASSNAME, RECOVER_PLUGIN_PROPERTIES); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseCredential(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY || Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.RECOVER_CREDENTIAL) { return; } else { if (Credential.Tag.forName(reader.getLocalName()) == Credential.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (Credential.Tag.forName(reader.getLocalName())) { case PASSWORD: { String value = rawElementText(reader); RECOVERY_PASSWORD.parseAndSetParameter(value, operation, reader); break; } case USER_NAME: { String value = rawElementText(reader); RECOVERY_USERNAME.parseAndSetParameter(value, operation, reader); break; } case SECURITY_DOMAIN: { String value = rawElementText(reader); RECOVERY_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseCredential_5_0(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY || Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.RECOVER_CREDENTIAL) { return; } else { if (Credential.Tag.forName(reader.getLocalName()) == Credential.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (Credential.Tag.forName(reader.getLocalName())) { case PASSWORD: { String value = rawElementText(reader); RECOVERY_PASSWORD.parseAndSetParameter(value, operation, reader); break; } case USER_NAME: { String value = rawElementText(reader); RECOVERY_USERNAME.parseAndSetParameter(value, operation, reader); break; } case SECURITY_DOMAIN: { String value = rawElementText(reader); RECOVERY_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader); break; } case ELYTRON_ENABLED: { String value = rawElementText(reader); value = value == null ? "true" : value; RECOVERY_ELYTRON_ENABLED.parseAndSetParameter(value, operation, reader); break; } case AUTHENTICATION_CONTEXT: { String value = rawElementText(reader); RECOVERY_AUTHENTICATION_CONTEXT.parseAndSetParameter(value, operation, reader); break; } case CREDENTIAL_REFERENCE: RECOVERY_CREDENTIAL_REFERENCE.getParser().parseElement(RECOVERY_CREDENTIAL_REFERENCE, reader, operation); break; default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseValidationSettings(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.VALIDATION) { return; } else { if (Validation.Tag.forName(reader.getLocalName()) == Validation.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { Validation.Tag currTag = Validation.Tag.forName(reader.getLocalName()); switch (currTag) { case BACKGROUND_VALIDATION: { String value = rawElementText(reader); BACKGROUNDVALIDATION.parseAndSetParameter(value, operation, reader); break; } case BACKGROUND_VALIDATION_MILLIS: { String value = rawElementText(reader); BACKGROUNDVALIDATIONMILLIS.parseAndSetParameter(value, operation, reader); break; } case CHECK_VALID_CONNECTION_SQL: { String value = rawElementText(reader); CHECK_VALID_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case EXCEPTION_SORTER: { parseExtension(reader, currTag.getLocalName(), operation, EXCEPTION_SORTER_CLASSNAME, EXCEPTION_SORTER_PROPERTIES); break; } case STALE_CONNECTION_CHECKER: { parseExtension(reader, currTag.getLocalName(), operation, STALE_CONNECTION_CHECKER_CLASSNAME, STALE_CONNECTION_CHECKER_PROPERTIES); break; } case USE_FAST_FAIL: { String value = rawElementText(reader); USE_FAST_FAIL.parseAndSetParameter(value, operation, reader); break; } case VALIDATE_ON_MATCH: { String value = rawElementText(reader); VALIDATE_ON_MATCH.parseAndSetParameter(value, operation, reader); break; } case VALID_CONNECTION_CHECKER: { parseExtension(reader, currTag.getLocalName(), operation, VALID_CONNECTION_CHECKER_CLASSNAME, VALID_CONNECTION_CHECKER_PROPERTIES); break; } default: { throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseValidationSetting_7_0(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.VALIDATION) { return; } else { if (Validation.Tag.forName(reader.getLocalName()) == Validation.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { Validation.Tag currTag = Validation.Tag.forName(reader.getLocalName()); switch (currTag) { case BACKGROUND_VALIDATION: { String value = rawElementText(reader); BACKGROUNDVALIDATION.parseAndSetParameter(value, operation, reader); break; } case BACKGROUND_VALIDATION_MILLIS: { String value = rawElementText(reader); BACKGROUNDVALIDATIONMILLIS.parseAndSetParameter(value, operation, reader); break; } case CHECK_VALID_CONNECTION_SQL: { String value = rawElementText(reader); CHECK_VALID_CONNECTION_SQL.parseAndSetParameter(value, operation, reader); break; } case EXCEPTION_SORTER: { parseModuleExtension(reader, currTag.getLocalName(), operation, EXCEPTION_SORTER_CLASSNAME, EXCEPTION_SORTER_MODULE, EXCEPTION_SORTER_PROPERTIES); break; } case STALE_CONNECTION_CHECKER: { parseModuleExtension(reader, currTag.getLocalName(), operation, STALE_CONNECTION_CHECKER_CLASSNAME, STALE_CONNECTION_CHECKER_MODULE, STALE_CONNECTION_CHECKER_PROPERTIES); break; } case USE_FAST_FAIL: { String value = rawElementText(reader); USE_FAST_FAIL.parseAndSetParameter(value, operation, reader); break; } case VALIDATE_ON_MATCH: { String value = rawElementText(reader); VALIDATE_ON_MATCH.parseAndSetParameter(value, operation, reader); break; } case VALID_CONNECTION_CHECKER: { parseModuleExtension(reader, currTag.getLocalName(), operation, VALID_CONNECTION_CHECKER_CLASSNAME, VALID_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_PROPERTIES); break; } default: { throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseTimeOutSettings(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.TIMEOUT) { return; } else { if (TimeOut.Tag.forName(reader.getLocalName()) == TimeOut.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (TimeOut.Tag.forName(reader.getLocalName())) { case ALLOCATION_RETRY: { String value = rawElementText(reader); ALLOCATION_RETRY.parseAndSetParameter(value, operation, reader); break; } case ALLOCATION_RETRY_WAIT_MILLIS: { String value = rawElementText(reader); ALLOCATION_RETRY_WAIT_MILLIS.parseAndSetParameter(value, operation, reader); break; } case BLOCKING_TIMEOUT_MILLIS: { String value = rawElementText(reader); BLOCKING_TIMEOUT_WAIT_MILLIS.parseAndSetParameter(value, operation, reader); break; } case IDLE_TIMEOUT_MINUTES: { String value = rawElementText(reader); IDLETIMEOUTMINUTES.parseAndSetParameter(value, operation, reader); break; } case QUERY_TIMEOUT: { String value = rawElementText(reader); QUERY_TIMEOUT.parseAndSetParameter(value, operation, reader); break; } case SET_TX_QUERY_TIMEOUT: { //tag presence is sufficient to set it to true String value = rawElementText(reader); value = value == null ? "true" : value; SET_TX_QUERY_TIMEOUT.parseAndSetParameter(value, operation, reader); break; } case USE_TRY_LOCK: { String value = rawElementText(reader); USE_TRY_LOCK.parseAndSetParameter(value, operation, reader); break; } case XA_RESOURCE_TIMEOUT: { String value = rawElementText(reader); XA_RESOURCE_TIMEOUT.parseAndSetParameter(value, operation, reader); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseStatementSettings(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.STATEMENT) { return; } else { if (Statement.Tag.forName(reader.getLocalName()) == Statement.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (Statement.Tag.forName(reader.getLocalName())) { case PREPARED_STATEMENT_CACHE_SIZE: { String value = rawElementText(reader); PREPARED_STATEMENTS_CACHE_SIZE.parseAndSetParameter(value, operation, reader); break; } case TRACK_STATEMENTS: { String value = rawElementText(reader); TRACK_STATEMENTS.parseAndSetParameter(value, operation, reader); break; } case SHARE_PREPARED_STATEMENTS: { //tag presence is sufficient to set it to true String value = rawElementText(reader); value = value == null ? "true" : value; SHARE_PREPARED_STATEMENTS.parseAndSetParameter(value, operation, reader); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private int findSlot(String moduleName) { boolean insideVariable = false; int i = 0; while (i < moduleName.length()) { if (!insideVariable) { if (moduleName.charAt(i) == ':') { return i; } if ((moduleName.charAt(i) == '$') && (i + 1 < moduleName.length()) && (moduleName.charAt(i+1) == '{')) { insideVariable = true; i += 2; continue; } } else { if (moduleName.charAt(i) == '}') { insideVariable = false; } } i++; } return -1; } /** * A Tag. * * @author <a href="[email protected]">Stefano Maestri</a> */ public enum Tag { /** * always first */ UNKNOWN(null), /** * jboss-ra tag name */ DATASOURCES("datasources"); private final String name; /** * Create a new Tag. * * @param name a name */ Tag(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } private static final Map<String, Tag> MAP; static { final Map<String, Tag> map = new HashMap<String, Tag>(); for (Tag element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } /** * Static method to get enum instance given localName string * * @param localName a string used as localname (typically tag name as defined in xsd) * @return the enum instance */ public static Tag forName(String localName) { final Tag element = MAP.get(localName); return element == null ? UNKNOWN : element; } } }
153,754
47.153774
198
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/GetInstalledDriverOperationHandler.java
/* * 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_CLASS_INFO; import static org.jboss.as.connector.subsystems.datasources.Constants.DEPLOYMENT_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MAJOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MINOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MODULE_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_XA_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.INSTALLED_DRIVER_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.JDBC_COMPLIANT; import static org.jboss.as.connector.subsystems.datasources.Constants.MODULE_SLOT; import static org.jboss.as.connector.subsystems.datasources.GetDataSourceClassInfoOperationHandler.dsClsInfoNode; import org.jboss.as.connector.services.driver.InstalledDriver; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.server.Services; import org.jboss.as.server.moduleservice.ServiceModuleLoader; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceRegistry; /** * Reads the "installed-drivers" attribute. * @author Brian Stansberry (c) 2011 Red Hat Inc. */ public class GetInstalledDriverOperationHandler implements OperationStepHandler { public static final GetInstalledDriverOperationHandler INSTANCE = new GetInstalledDriverOperationHandler(); private GetInstalledDriverOperationHandler() { } @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final String name = INSTALLED_DRIVER_NAME.validateOperation(operation).asString(); if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(false); DriverRegistry driverRegistry = (DriverRegistry)registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue(); ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader)registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue(); ModelNode result = new ModelNode(); InstalledDriver driver = driverRegistry.getInstalledDriver(name); ModelNode driverNode = new ModelNode(); driverNode.get(INSTALLED_DRIVER_NAME.getName()).set(driver.getDriverName()); if (driver.isFromDeployment()) { driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName()); driverNode.get(DRIVER_MODULE_NAME.getName()); driverNode.get(MODULE_SLOT.getName()); driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName()); driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()); } else { driverNode.get(DEPLOYMENT_NAME.getName()); driverNode.get(DRIVER_MODULE_NAME.getName()).set(driver.getModuleName().getName()); driverNode.get(MODULE_SLOT.getName()).set(driver.getModuleName() != null ? driver.getModuleName().getSlot() : ""); driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).set( driver.getDataSourceClassName() != null ? driver.getDataSourceClassName() : ""); driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).set(driver.getXaDataSourceClassName() != null ? driver.getXaDataSourceClassName() : ""); } driverNode.get(DATASOURCE_CLASS_INFO.getName()).set( dsClsInfoNode(serviceModuleLoader, driver.getModuleName(), driver.getDataSourceClassName(), driver.getXaDataSourceClassName())); driverNode.get(DRIVER_CLASS_NAME.getName()).set(driver.getDriverClassName()); driverNode.get(DRIVER_MAJOR_VERSION.getName()).set(driver.getMajorVersion()); driverNode.get(DRIVER_MINOR_VERSION.getName()).set(driver.getMinorVersion()); driverNode.get(JDBC_COMPLIANT.getName()).set(driver.isJdbcCompliant()); result.add(driverNode); context.getResult().set(result); } }, OperationContext.Stage.RUNTIME); } } }
6,246
56.311927
170
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/Element.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.datasources; import java.util.HashMap; import java.util.Map; /** * An Element. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public enum Element { /** always the first **/ UNKNOWN(null), SUBSYSTEM("subsystem"), DATASOURCES("datasources"), DRIVERS("drivers"), DRIVER("driver"); private final String name; Element(final String name) { this.name = name; } /** * Get the local name of this element. * @return the local name */ public String getLocalName() { return name; } private static final Map<String, Element> MAP; static { final Map<String, Element> map = new HashMap<String, Element>(); for (Element element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } public static Element forName(String localName) { final Element element = MAP.get(localName); return element == null ? UNKNOWN : element; } }
2,149
30.617647
109
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XaDataSourcePropertyAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.XADATASOURCE_PROPERTY_VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; import org.jboss.msc.service.ServiceTarget; /** * Adds a recovery-environment to the Transactions subsystem * */ public class XaDataSourcePropertyAdd extends AbstractAddStepHandler { public static final XaDataSourcePropertyAdd INSTANCE = new XaDataSourcePropertyAdd(); @Override protected void populateModel(ModelNode operation, ModelNode modelNode) throws OperationFailedException { XADATASOURCE_PROPERTY_VALUE.validateAndSet(operation, modelNode); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = XADATASOURCE_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String dsName = path.getElement(path.size() - 2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName).append("xa-datasource-properties").append(configPropertyName); final ServiceRegistry registry = context.getServiceRegistry(true); final ServiceName dataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE .append(dsName); final ServiceController<?> dataSourceConfigController = registry .getService(dataSourceConfigServiceName); if (dataSourceConfigController == null || !((XaDataSource) dataSourceConfigController.getValue()).isEnabled()) { final ServiceTarget serviceTarget = context.getServiceTarget(); final XaDataSourcePropertiesService service = new XaDataSourcePropertiesService(configPropertyName, configPropertyValue); ServiceController<?> controller = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.NEVER) .install(); } else { context.reloadRequired(); } } }
3,846
46.493827
155
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XaDataSourcePropertiesService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.datasources; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class XaDataSourcePropertiesService implements Service<String> { private final String value; private final String name; /** * create an instance * */ public XaDataSourcePropertiesService(String name, String value) { this.name = name; this.value = value; } @Override public String getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { } @Override public void stop(StopContext context) { } public String getName() { return name; } }
2,012
28.173913
70
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/ModifiableXaDataSource.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import java.util.Map; import org.jboss.jca.common.CommonBundle; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.ds.DsSecurity; import org.jboss.jca.common.api.metadata.ds.DsXaPool; import org.jboss.jca.common.api.metadata.ds.Statement; import org.jboss.jca.common.api.metadata.ds.TimeOut; import org.jboss.jca.common.api.metadata.ds.TransactionIsolation; import org.jboss.jca.common.api.metadata.ds.Validation; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.common.metadata.ds.XADataSourceImpl; import org.jboss.logging.Messages; /** * A modifiable DataSourceImpl to add connection properties * * @author <a href="[email protected]">Stefano Maestri</a> */ public class ModifiableXaDataSource extends XADataSourceImpl implements XaDataSource { /** * The serialVersionUID */ private static final long serialVersionUID = -1401087499308709724L; /** * The bundle */ private static CommonBundle bundle = Messages.getBundle(CommonBundle.class); /** * Create a new XADataSourceImpl. * * @param transactionIsolation transactionIsolation * @param timeOut timeOut * @param security security * @param statement statement * @param validation validation * @param urlDelimiter urlDelimiter * @param urlSelectorStrategyClassName urlSelectorStrategyClassName * @param useJavaContext useJavaContext * @param poolName poolName * @param enabled enabled * @param jndiName jndiName * @param spy spy * @param useCcm useCcm * @param mcp mcp * @param enlistmentTrace enlistmentTrace * @param xaDataSourceProperty xaDataSourceProperty * @param xaDataSourceClass xaDataSourceClass * @param driver driver * @param newConnectionSql newConnectionSql * @param xaPool xaPool * @param recovery recovery * @throws ValidateException ValidateException */ public ModifiableXaDataSource(TransactionIsolation transactionIsolation, TimeOut timeOut, DsSecurity security, Statement statement, Validation validation, String urlDelimiter, String urlProperty, String urlSelectorStrategyClassName, Boolean useJavaContext, String poolName, Boolean enabled, String jndiName, Boolean spy, Boolean useCcm, final Boolean connectable, final Boolean tracking, String mcp, Boolean enlistmentTrace, Map<String, String> xaDataSourceProperty, String xaDataSourceClass, String driver, String newConnectionSql, DsXaPool xaPool, Recovery recovery) throws ValidateException { super(transactionIsolation, timeOut, security, statement, validation, urlDelimiter, urlProperty, urlSelectorStrategyClassName, useJavaContext, poolName, enabled, jndiName, spy, useCcm, connectable, tracking, mcp, enlistmentTrace, xaDataSourceProperty, xaDataSourceClass, driver, newConnectionSql, xaPool, recovery); } public final void addXaDataSourceProperty(String name, String value) { xaDataSourceProperty.put(name, value); } @Override public void validate() throws ValidateException { if ((this.xaDataSourceClass == null || this.xaDataSourceClass.trim().length() == 0) && (this.driver == null || this.driver.trim().length() == 0)) throw new ValidateException(bundle.requiredElementMissing(Tag.XA_DATASOURCE_CLASS.getLocalName(), this.getClass().getCanonicalName())); } public final XaDataSource getUnModifiableInstance() throws ValidateException { return new XADataSourceImpl(transactionIsolation, timeOut, security, statement, validation, urlDelimiter, urlProperty, urlSelectorStrategyClassName, useJavaContext, poolName, enabled, jndiName, spy, useCcm, connectable, tracking, mcp, enlistmentTrace, xaDataSourceProperty, xaDataSourceClass, driver, newConnectionSql, getXaPool(), recovery); } }
5,662
45.801653
155
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourceReferenceFactoryService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import javax.sql.DataSource; import org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory; import org.jboss.as.naming.ContextListManagedReferenceFactory; import org.jboss.as.naming.ManagedReference; import org.jboss.as.naming.ManagedReferenceFactory; import org.jboss.as.naming.ValueManagedReference; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * Service responsible for exposing a {@link ManagedReferenceFactory} for a {@link DataSource}. * * @author John Bailey */ public class DataSourceReferenceFactoryService implements Service<ManagedReferenceFactory>, ContextListAndJndiViewManagedReferenceFactory { public static final ServiceName SERVICE_NAME_BASE = AbstractDataSourceService.SERVICE_NAME_BASE.append("reference-factory"); private final InjectedValue<DataSource> dataSourceValue = new InjectedValue<DataSource>(); private ManagedReference reference; public synchronized void start(StartContext startContext) throws StartException { reference = new ValueManagedReference(dataSourceValue.getValue()); } public synchronized void stop(StopContext stopContext) { reference = null; } public synchronized ManagedReferenceFactory getValue() throws IllegalStateException, IllegalArgumentException { return this; } public synchronized ManagedReference getReference() { return reference; } public Injector<DataSource> getDataSourceInjector() { return dataSourceValue; // TODO: Should we use unique references } @Override public String getInstanceClassName() { final Object value = reference != null ? reference.getInstance() : null; return value != null ? value.getClass().getName() : ContextListManagedReferenceFactory.DEFAULT_INSTANCE_CLASS_NAME; } @Override public String getJndiViewInstanceValue() { final Object value = reference != null ? reference.getInstance() : null; return String.valueOf(value); } }
3,313
38.927711
139
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourceDefinition.java
/* * * 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_ATTRIBUTE; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_DISABLE; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_ENABLE; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_PROPERTIES_ATTRIBUTES; import static org.jboss.as.connector.subsystems.datasources.Constants.DATA_SOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.DUMP_QUEUED_THREADS; import static org.jboss.as.connector.subsystems.datasources.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.datasources.Constants.FLUSH_ALL_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.FLUSH_GRACEFULLY_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.FLUSH_IDLE_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.FLUSH_INVALID_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.datasources.Constants.TEST_CONNECTION; import org.jboss.as.connector._private.Capabilities; import org.jboss.as.connector.subsystems.common.pool.PoolConfigurationRWHandler; import org.jboss.as.connector.subsystems.common.pool.PoolOperations; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PropertiesAttributeDefinition; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.access.constraint.ApplicationTypeConfig; import org.jboss.as.controller.access.management.ApplicationTypeAccessConstraintDefinition; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.security.CredentialReferenceWriteAttributeHandler; /** * @author Stefano Maestri */ public class DataSourceDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_DATASOURCE = PathElement.pathElement(DATA_SOURCE); private final boolean registerRuntimeOnly; private final boolean deployed; private DataSourceDefinition(final boolean registerRuntimeOnly, final boolean deployed) { super(new Parameters(PATH_DATASOURCE, DataSourcesExtension.getResourceDescriptionResolver(DATA_SOURCE)) .setAddHandler(deployed ? null : DataSourceAdd.INSTANCE) .setRemoveHandler(deployed ? null : DataSourceRemove.INSTANCE) .setAccessConstraints( new ApplicationTypeAccessConstraintDefinition( new ApplicationTypeConfig(DataSourcesExtension.SUBSYSTEM_NAME, DATA_SOURCE))) .setCapabilities(getCapabilities(deployed)) ); this.registerRuntimeOnly = registerRuntimeOnly; this.deployed = deployed; } public static DataSourceDefinition createInstance(final boolean registerRuntimeOnly, final boolean deployed) { return new DataSourceDefinition(registerRuntimeOnly, deployed); } @SuppressWarnings("rawtypes") private static RuntimeCapability[] getCapabilities(boolean deployed) { return deployed ? new RuntimeCapability[0] : new RuntimeCapability[] {Capabilities.DATA_SOURCE_CAPABILITY}; } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); if (!deployed) { resourceRegistration.registerOperationHandler(DATASOURCE_ENABLE, DataSourceEnableDisable.ENABLE); resourceRegistration.registerOperationHandler(DATASOURCE_DISABLE, DataSourceEnableDisable.DISABLE); } if (registerRuntimeOnly) { resourceRegistration.registerOperationHandler(FLUSH_IDLE_CONNECTION, PoolOperations.FlushIdleConnectionInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_ALL_CONNECTION, PoolOperations.FlushAllConnectionInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(DUMP_QUEUED_THREADS, PoolOperations.DumpQueuedThreadInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_INVALID_CONNECTION, PoolOperations.FlushInvalidConnectionInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_GRACEFULLY_CONNECTION, PoolOperations.FlushGracefullyConnectionInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(TEST_CONNECTION, PoolOperations.TestConnectionInPool.DS_INSTANCE); } } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { if (deployed) { for (final SimpleAttributeDefinition attribute : DATASOURCE_ATTRIBUTE) { SimpleAttributeDefinition runtimeAttribute = new SimpleAttributeDefinitionBuilder(attribute).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLDataSourceRuntimeHandler.INSTANCE); } for (final PropertiesAttributeDefinition attribute : DATASOURCE_PROPERTIES_ATTRIBUTES) { PropertiesAttributeDefinition runtimeAttribute = new PropertiesAttributeDefinition.Builder(attribute).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLDataSourceRuntimeHandler.INSTANCE); } } else { ReloadRequiredWriteAttributeHandler reloadRequiredWriteAttributeHandler = new ReloadRequiredWriteAttributeHandler(DATASOURCE_ATTRIBUTE); CredentialReferenceWriteAttributeHandler credentialReferenceWriteAttributeHandler = new CredentialReferenceWriteAttributeHandler(CREDENTIAL_REFERENCE, RECOVERY_CREDENTIAL_REFERENCE); for (final SimpleAttributeDefinition attribute : DATASOURCE_ATTRIBUTE) { if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) { resourceRegistration.registerReadWriteAttribute(attribute, PoolConfigurationRWHandler.PoolConfigurationReadHandler.INSTANCE, PoolConfigurationRWHandler.LocalAndXaDataSourcePoolConfigurationWriteHandler.INSTANCE); } else if (attribute.getName().equals(ENLISTMENT_TRACE.getName())) { resourceRegistration.registerReadWriteAttribute(attribute, null, new EnlistmentTraceAttributeWriteHandler()); } else if (attribute.getName().equals(CREDENTIAL_REFERENCE.getName()) || attribute.getName().equals(RECOVERY_CREDENTIAL_REFERENCE.getName())) { resourceRegistration.registerReadWriteAttribute(attribute, null, credentialReferenceWriteAttributeHandler); } else { resourceRegistration.registerReadWriteAttribute(attribute, null, reloadRequiredWriteAttributeHandler); } } ReloadRequiredWriteAttributeHandler reloadRequiredPropertiesWriteHandler = new ReloadRequiredWriteAttributeHandler(DATASOURCE_PROPERTIES_ATTRIBUTES); for (final PropertiesAttributeDefinition attribute : DATASOURCE_PROPERTIES_ATTRIBUTES) { if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) { resourceRegistration.registerReadWriteAttribute(attribute, PoolConfigurationRWHandler.PoolConfigurationReadHandler.INSTANCE, PoolConfigurationRWHandler.LocalAndXaDataSourcePoolConfigurationWriteHandler.INSTANCE); } else { resourceRegistration.registerReadWriteAttribute(attribute, null, reloadRequiredPropertiesWriteHandler); } } } } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerSubModel(new ConnectionPropertyDefinition(this.deployed)); } }
9,508
61.559211
232
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourcesSubsystemRootDefinition.java
/* * * 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.GET_INSTALLED_DRIVER; import static org.jboss.as.connector.subsystems.datasources.Constants.INSTALLED_DRIVERS; import static org.jboss.as.connector.subsystems.datasources.Constants.INSTALLED_DRIVERS_LIST; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * @author Stefano Maestri */ public class DataSourcesSubsystemRootDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_SUBSYSTEM = PathElement.pathElement(SUBSYSTEM, DataSourcesExtension.SUBSYSTEM_NAME); private final boolean registerRuntimeOnly; private final boolean deployed; private DataSourcesSubsystemRootDefinition(final boolean registerRuntimeOnly, final boolean deployed) { super(new Parameters(PATH_SUBSYSTEM, DataSourcesExtension.getResourceDescriptionResolver()) .setAddHandler(deployed ? null : DataSourcesSubsystemAdd.INSTANCE) .setRemoveHandler(deployed ? null : ReloadRequiredRemoveStepHandler.INSTANCE) .setFeature(!deployed) .setRuntime(deployed)); this.registerRuntimeOnly = registerRuntimeOnly; this.deployed = deployed; } public static DataSourcesSubsystemRootDefinition createInstance(final boolean registerRuntimeOnly) { return new DataSourcesSubsystemRootDefinition(registerRuntimeOnly, false); } public static DataSourcesSubsystemRootDefinition createDeployedInstance(final boolean registerRuntimeOnly) { return new DataSourcesSubsystemRootDefinition(registerRuntimeOnly, true); } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); resourceRegistration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE); if (registerRuntimeOnly && ! deployed) { resourceRegistration.registerOperationHandler(INSTALLED_DRIVERS_LIST, InstalledDriversListOperationHandler.INSTANCE); resourceRegistration.registerOperationHandler(GET_INSTALLED_DRIVER, GetInstalledDriverOperationHandler.INSTANCE); } } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { if (registerRuntimeOnly && ! deployed ) resourceRegistration.registerReadOnlyAttribute(INSTALLED_DRIVERS, InstalledDriversListOperationHandler.INSTANCE); } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { if (! deployed ) resourceRegistration.registerSubModel(new JdbcDriverDefinition()); resourceRegistration.registerSubModel(DataSourceDefinition.createInstance(registerRuntimeOnly, deployed)); resourceRegistration.registerSubModel(XaDataSourceDefinition.createInstance(registerRuntimeOnly, deployed)); } }
4,442
47.824176
140
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourcesSubsystemProviders.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.STATISTICS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION; import java.util.Collections; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; import org.jboss.as.controller.descriptions.OverrideDescriptionProvider; import org.jboss.dmr.ModelNode; /** * @author @author <a href="mailto:[email protected]">Stefano * Maestri</a> * @author John Bailey */ public class DataSourcesSubsystemProviders { public static final String RESOURCE_NAME = DataSourcesSubsystemProviders.class.getPackage().getName() + ".LocalDescriptions"; public static final OverrideDescriptionProvider OVERRIDE_DS_DESC = new OverrideDescriptionProvider() { @Override public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) { return Collections.emptyMap(); } @Override public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) { final ResourceBundle bundle = getResourceBundle(locale); Map<String, ModelNode> children = new HashMap<String, ModelNode>(); ModelNode node = new ModelNode(); node.get(DESCRIPTION).set(bundle.getString("statistics")); children.put(STATISTICS, node); return children; } }; private static ResourceBundle getResourceBundle(Locale locale) { if (locale == null) { locale = Locale.getDefault(); } return ResourceBundle.getBundle(RESOURCE_NAME, locale); } }
2,757
35.289474
129
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XaDataSourceDefinition.java
/* * * 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_DISABLE; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_ENABLE; import static org.jboss.as.connector.subsystems.datasources.Constants.DUMP_QUEUED_THREADS; import static org.jboss.as.connector.subsystems.datasources.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.datasources.Constants.FLUSH_ALL_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.FLUSH_GRACEFULLY_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.FLUSH_IDLE_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.FLUSH_INVALID_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.TEST_CONNECTION; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE_ATTRIBUTE; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE_PROPERTIES_ATTRIBUTES; import org.jboss.as.connector._private.Capabilities; import org.jboss.as.connector.subsystems.common.pool.PoolConfigurationRWHandler; import org.jboss.as.connector.subsystems.common.pool.PoolOperations; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PropertiesAttributeDefinition; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.access.constraint.ApplicationTypeConfig; import org.jboss.as.controller.access.management.ApplicationTypeAccessConstraintDefinition; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * @author Stefano Maestri */ public class XaDataSourceDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_XA_DATASOURCE = PathElement.pathElement(XA_DATASOURCE); // The ManagedConnectionPool implementation used by default by versions < 4.0.0 (WildFly 10) private static final String LEGACY_MCP = "org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool"; private final boolean registerRuntimeOnly; private final boolean deployed; private XaDataSourceDefinition(final boolean registerRuntimeOnly, final boolean deployed) { super(new Parameters(PATH_XA_DATASOURCE, DataSourcesExtension.getResourceDescriptionResolver(XA_DATASOURCE)) .setAddHandler(deployed ? null : XaDataSourceAdd.INSTANCE) .setRemoveHandler(deployed ? null : DataSourceRemove.XA_INSTANCE) .setAccessConstraints(new ApplicationTypeAccessConstraintDefinition(new ApplicationTypeConfig(DataSourcesExtension.SUBSYSTEM_NAME, XA_DATASOURCE))) .setCapabilities(getCapabilities(deployed)) ); this.registerRuntimeOnly = registerRuntimeOnly; this.deployed = deployed; } public static XaDataSourceDefinition createInstance(final boolean registerRuntimeOnly, final boolean deployed) { return new XaDataSourceDefinition(registerRuntimeOnly, deployed); } @SuppressWarnings("rawtypes") private static RuntimeCapability[] getCapabilities(boolean deployed) { return deployed ? new RuntimeCapability[0] : new RuntimeCapability[] {Capabilities.DATA_SOURCE_CAPABILITY}; } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); if (!deployed) { resourceRegistration.registerOperationHandler(DATASOURCE_ENABLE, DataSourceEnableDisable.ENABLE); resourceRegistration.registerOperationHandler(DATASOURCE_DISABLE, DataSourceEnableDisable.DISABLE); } if (registerRuntimeOnly) { resourceRegistration.registerOperationHandler(FLUSH_IDLE_CONNECTION, PoolOperations.FlushIdleConnectionInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_ALL_CONNECTION, PoolOperations.FlushAllConnectionInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(DUMP_QUEUED_THREADS, PoolOperations.DumpQueuedThreadInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_INVALID_CONNECTION, PoolOperations.FlushInvalidConnectionInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_GRACEFULLY_CONNECTION, PoolOperations.FlushGracefullyConnectionInPool.DS_INSTANCE); resourceRegistration.registerOperationHandler(TEST_CONNECTION, PoolOperations.TestConnectionInPool.DS_INSTANCE); } } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { if (deployed) { for (final SimpleAttributeDefinition attribute : XA_DATASOURCE_ATTRIBUTE) { SimpleAttributeDefinition runtimeAttribute = new SimpleAttributeDefinitionBuilder(attribute).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLXaDataSourceRuntimeHandler.INSTANCE); } for (final PropertiesAttributeDefinition attribute : XA_DATASOURCE_PROPERTIES_ATTRIBUTES) { PropertiesAttributeDefinition runtimeAttribute = new PropertiesAttributeDefinition.Builder(attribute).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLXaDataSourceRuntimeHandler.INSTANCE); } } else { ReloadRequiredWriteAttributeHandler reloadRequiredWriteHandler = new ReloadRequiredWriteAttributeHandler(XA_DATASOURCE_ATTRIBUTE); for (final SimpleAttributeDefinition attribute : XA_DATASOURCE_ATTRIBUTE) { if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) { resourceRegistration.registerReadWriteAttribute(attribute, PoolConfigurationRWHandler.PoolConfigurationReadHandler.INSTANCE, PoolConfigurationRWHandler.LocalAndXaDataSourcePoolConfigurationWriteHandler.INSTANCE); } else if (attribute.getName().equals(ENLISTMENT_TRACE.getName())) { resourceRegistration.registerReadWriteAttribute(attribute, null, new EnlistmentTraceAttributeWriteHandler()); } else { resourceRegistration.registerReadWriteAttribute(attribute, null, reloadRequiredWriteHandler); } } ReloadRequiredWriteAttributeHandler reloadRequiredPropertiesWriteHandler = new ReloadRequiredWriteAttributeHandler(XA_DATASOURCE_PROPERTIES_ATTRIBUTES); for (final PropertiesAttributeDefinition attribute : XA_DATASOURCE_PROPERTIES_ATTRIBUTES) { if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) { resourceRegistration.registerReadWriteAttribute(attribute, PoolConfigurationRWHandler.PoolConfigurationReadHandler.INSTANCE, PoolConfigurationRWHandler.LocalAndXaDataSourcePoolConfigurationWriteHandler.INSTANCE); } else { resourceRegistration.registerReadWriteAttribute(attribute, null, reloadRequiredPropertiesWriteHandler); } } } } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerSubModel(new XaDataSourcePropertyDefinition(this.deployed)); } }
8,962
60.390411
232
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/AbstractDataSourceAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_DRIVER; import static org.jboss.as.connector.subsystems.datasources.Constants.ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.JTA; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.datasources.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.datasources.Constants.STATISTICS_ENABLED; import static org.jboss.as.connector.subsystems.datasources.DataSourceModelNodeUtil.from; import static org.jboss.as.connector.subsystems.datasources.DataSourceModelNodeUtil.xaFrom; import static org.jboss.as.connector.subsystems.jca.Constants.DEFAULT_NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.security.CredentialReference.CREDENTIAL_REFERENCE; import static org.jboss.as.controller.security.CredentialReference.handleCredentialReferenceUpdate; import static org.jboss.as.controller.security.CredentialReference.rollbackCredentialStoreUpdate; import java.sql.Driver; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; import javax.sql.DataSource; import org.jboss.as.connector._private.Capabilities; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.as.controller.security.CredentialReference; import org.jboss.as.naming.ManagedReferenceFactory; import org.jboss.as.naming.ServiceBasedNamingStore; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.service.BinderService; import org.jboss.as.naming.service.NamingService; import org.jboss.as.server.Services; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.common.Credential; import org.jboss.jca.common.api.metadata.ds.DsSecurity; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.jca.core.spi.mdr.MetadataRepository; import org.jboss.jca.core.spi.rar.ResourceAdapterRepository; import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.jca.deployers.common.CommonDeployment; import org.jboss.msc.Service; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StopContext; import org.jboss.msc.service.ServiceTarget; import org.wildfly.common.function.ExceptionSupplier; import org.wildfly.security.auth.client.AuthenticationContext; import org.wildfly.security.credential.source.CredentialSource; /** * Abstract operation handler responsible for adding a DataSource. * * @author John Bailey */ public abstract class AbstractDataSourceAdd extends AbstractAddStepHandler { private static final ServiceName SECURITY_DOMAIN_SERVICE = ServiceName.JBOSS.append("security", "security-domain"); private static final ServiceName SECURITY_MANAGER_SERVICE = ServiceName.JBOSS.append("security", "simple-security-manager"); private static final ServiceName SUBJECT_FACTORY_SERVICE = ServiceName.JBOSS.append("security", "subject-factory"); AbstractDataSourceAdd(Collection<AttributeDefinition> attributes) { super(attributes); } @Override protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException { if (context.getProcessType().isServer()) { DataSourceStatisticsService.registerStatisticsResources(resource); } super.populateModel(context, operation, resource); final ModelNode model = resource.getModel(); handleCredentialReferenceUpdate(context, model.get(CREDENTIAL_REFERENCE), CREDENTIAL_REFERENCE); handleCredentialReferenceUpdate(context, model.get(Constants.RECOVERY_CREDENTIAL_REFERENCE.getName()), Constants.RECOVERY_CREDENTIAL_REFERENCE.getName()); } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final boolean enabled = ENABLED.resolveModelAttribute(context, model).asBoolean(); if (enabled) { firstRuntimeStep(context, operation, model); context.addStep(new OperationStepHandler() { @Override public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException { secondRuntimeStep(context, operation, context.getResourceRegistrationForUpdate(), model, isXa()); } }, OperationContext.Stage.RUNTIME); } } @Override protected void rollbackRuntime(OperationContext context, final ModelNode operation, final Resource resource) { rollbackCredentialStoreUpdate(Constants.CREDENTIAL_REFERENCE, context, resource); rollbackCredentialStoreUpdate(Constants.RECOVERY_CREDENTIAL_REFERENCE, context, resource); } void firstRuntimeStep(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final String jndiName = JNDI_NAME.resolveModelAttribute(context, model).asString(); final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName); final boolean jta = JTA.resolveModelAttribute(context, operation).asBoolean(); final String dsName = context.getCurrentAddressValue();// The STATISTICS_ENABLED.resolveModelAttribute(context, model) call should remain as it serves to validate that any // expression in the model can be resolved to a correct value. @SuppressWarnings("unused") final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean(); final CapabilityServiceSupport support = context.getCapabilityServiceSupport(); final ServiceTarget serviceTarget = context.getServiceTarget(); final ModelNode node = DATASOURCE_DRIVER.resolveModelAttribute(context, model); final String driverName = node.asString(); final ServiceName driverServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")); final ServiceName driverDemanderServiceName = ServiceName.JBOSS.append("driver-demander").append(jndiName); final ServiceBuilder<?> driverDemanderBuilder = serviceTarget.addService(driverDemanderServiceName); final Consumer<Driver> driverConsumer = driverDemanderBuilder.provides(driverDemanderServiceName); final Supplier<Driver> driverSupplier = driverDemanderBuilder.requires(driverServiceName); driverDemanderBuilder.setInstance(new DriverDemanderService(driverConsumer, driverSupplier)); driverDemanderBuilder.install(); AbstractDataSourceService dataSourceService = createDataSourceService(dsName, jndiName); final ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate(); final ServiceName dataSourceServiceNameAlias = AbstractDataSourceService.getServiceName(bindInfo); final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class); final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency( serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector()) .addAliases(dataSourceServiceNameAlias) .addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, dataSourceService.getManagementRepositoryInjector()) .addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, dataSourceService.getDriverRegistryInjector()); dataSourceServiceBuilder.requires(ConnectorServices.IDLE_REMOVER_SERVICE); dataSourceServiceBuilder.requires(ConnectorServices.CONNECTION_VALIDATOR_SERVICE); dataSourceServiceBuilder.addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector()); dataSourceServiceBuilder.requires(support.getCapabilityServiceName(NamingService.CAPABILITY_NAME)); if (jta) { dataSourceServiceBuilder.addDependency(support.getCapabilityServiceName(ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME), TransactionIntegration.class, dataSourceService.getTransactionIntegrationInjector()); dataSourceServiceBuilder.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector()); dataSourceServiceBuilder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME)); dataSourceServiceBuilder.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()); } else { dataSourceServiceBuilder.addDependency(ConnectorServices.NON_JTA_DS_RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()) .addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector()); } //Register an empty override model regardless of we're enabled or not - the statistics listener will add the relevant childresources if (registration.isAllowsOverride()) { registration.registerOverrideModel(dsName, DataSourcesSubsystemProviders.OVERRIDE_DS_DESC); } startConfigAndAddDependency(dataSourceServiceBuilder, dataSourceService, dsName, serviceTarget, operation); dataSourceServiceBuilder.addDependency(driverServiceName, Driver.class, dataSourceService.getDriverInjector()); // If the authentication context is defined, add the capability boolean requireLegacySecurity = false; if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) { if (model.hasDefined(AUTHENTICATION_CONTEXT.getName())) { dataSourceServiceBuilder.addDependency( context.getCapabilityServiceName( Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT.resolveModelAttribute(context, model).asString(), AuthenticationContext.class), AuthenticationContext.class, dataSourceService.getAuthenticationContext() ); } } else { String secDomain = SECURITY_DOMAIN.resolveModelAttribute(context, model).asStringOrNull(); requireLegacySecurity = (secDomain != null && secDomain.length() > 0) ; } if (isXa()) { if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) { if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName())) { dataSourceServiceBuilder.addDependency( context.getCapabilityServiceName( Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, RECOVERY_AUTHENTICATION_CONTEXT.resolveModelAttribute(context, model).asString(), AuthenticationContext.class), AuthenticationContext.class, dataSourceService.getRecoveryAuthenticationContext() ); } } else if (!requireLegacySecurity) { String secDomain = RECOVERY_SECURITY_DOMAIN.resolveModelAttribute(context, model).asStringOrNull(); requireLegacySecurity = (secDomain != null && secDomain.length() > 0); } } if (requireLegacySecurity) { context.setRollbackOnly(); throw SUBSYSTEM_RA_LOGGER.legacySecurityNotAvailable(dsName); } ModelNode credentialReference = Constants.CREDENTIAL_REFERENCE.resolveModelAttribute(context, model); if (credentialReference.isDefined()) { dataSourceService.getCredentialSourceSupplierInjector() .inject( CredentialReference.getCredentialSourceSupplier(context, Constants.CREDENTIAL_REFERENCE, model, dataSourceServiceBuilder)); } ModelNode recoveryCredentialReference = Constants.RECOVERY_CREDENTIAL_REFERENCE.resolveModelAttribute(context, model); if (recoveryCredentialReference.isDefined()) { dataSourceService.getRecoveryCredentialSourceSupplierInjector() .inject( CredentialReference.getCredentialSourceSupplier(context, Constants.RECOVERY_CREDENTIAL_REFERENCE, model, dataSourceServiceBuilder)); } dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.NEVER); dataSourceServiceBuilder.install(); } static void secondRuntimeStep(OperationContext context, ModelNode operation, ManagementResourceRegistration datasourceRegistration, ModelNode model, boolean isXa) throws OperationFailedException { final ServiceTarget serviceTarget = context.getServiceTarget(); final ModelNode address = operation.require(OP_ADDR); final String dsName = PathAddress.pathAddress(address).getLastElement().getValue(); final String jndiName = JNDI_NAME.resolveModelAttribute(context, model).asString(); final ServiceRegistry registry = context.getServiceRegistry(true); final List<ServiceName> serviceNames = registry.getServiceNames(); final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean(); final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class); final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName); final ExceptionSupplier<CredentialSource, Exception> credentialSourceExceptionExceptionSupplier = dataSourceController.getService() instanceof AbstractDataSourceService ? ((AbstractDataSourceService)dataSourceController.getService()).getCredentialSourceSupplierInjector().getOptionalValue() : null; final ExceptionSupplier<CredentialSource, Exception> recoveryCredentialSourceExceptionExceptionSupplier = dataSourceController.getService() instanceof AbstractDataSourceService ? ((AbstractDataSourceService)dataSourceController.getService()).getRecoveryCredentialSourceSupplierInjector().getOptionalValue() : null; final boolean jta; if (isXa) { jta = true; final ModifiableXaDataSource dataSourceConfig; try { dataSourceConfig = xaFrom(context, model, dsName, credentialSourceExceptionExceptionSupplier, recoveryCredentialSourceExceptionExceptionSupplier); } catch (ValidateException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("XaDataSource", operation, e.getLocalizedMessage())); } final ServiceName xaDataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName); final ServiceBuilder<?> builder = serviceTarget.addService(xaDataSourceConfigServiceName); // add dependency on security domain service if applicable final DsSecurity dsSecurityConfig = dataSourceConfig.getSecurity(); if (dsSecurityConfig != null) { final String securityDomainName = dsSecurityConfig.getSecurityDomain(); if (!elytronEnabled && securityDomainName != null) { builder.requires(SECURITY_DOMAIN_SERVICE.append(securityDomainName)); } } // add dependency on security domain service if applicable for recovery config if (dataSourceConfig.getRecovery() != null) { final Credential credential = dataSourceConfig.getRecovery().getCredential(); if (credential != null) { final String securityDomainName = credential.getSecurityDomain(); if (!RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean() && securityDomainName != null) { builder.requires(SECURITY_DOMAIN_SERVICE.append(securityDomainName)); } } } int propertiesCount = 0; final Map<String, Supplier<String>> xaDataSourceProperties = new HashMap<>(); for (ServiceName name : serviceNames) { if (xaDataSourceConfigServiceName.append("xa-datasource-properties").isParentOf(name)) { final ServiceController<?> xaConfigPropertyController = registry.getService(name); XaDataSourcePropertiesService xaPropService = (XaDataSourcePropertiesService) xaConfigPropertyController.getService(); if (!ServiceController.State.UP.equals(xaConfigPropertyController.getState())) { propertiesCount++; xaConfigPropertyController.setMode(ServiceController.Mode.ACTIVE); xaDataSourceProperties.put(xaPropService.getName(), builder.requires(name)); } else { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.xa-config-property", name)); } } } if (propertiesCount == 0) { throw ConnectorLogger.ROOT_LOGGER.xaDataSourcePropertiesNotPresent(); } final XADataSourceConfigService xaDataSourceConfigService = new XADataSourceConfigService(dataSourceConfig, xaDataSourceProperties); builder.setInstance(xaDataSourceConfigService); builder.install(); } else { final ModifiableDataSource dataSourceConfig; try { dataSourceConfig = from(context, model, dsName, credentialSourceExceptionExceptionSupplier); } catch (ValidateException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("DataSource", operation, e.getLocalizedMessage())); } jta = dataSourceConfig.isJTA(); final ServiceName dataSourceCongServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(dsName); final ServiceBuilder<?> builder = serviceTarget.addService(dataSourceCongServiceName); // add dependency on security domain service if applicable final DsSecurity dsSecurityConfig = dataSourceConfig.getSecurity(); if (dsSecurityConfig != null) { final String securityDomainName = dsSecurityConfig.getSecurityDomain(); if (!elytronEnabled && securityDomainName != null) { builder.requires(SECURITY_DOMAIN_SERVICE.append(securityDomainName)); } } final Map<String, Supplier<String>> connectionProperties = new HashMap<>(); for (ServiceName name : serviceNames) { if (dataSourceCongServiceName.append("connection-properties").isParentOf(name)) { final ServiceController<?> connPropServiceController = registry.getService(name); ConnectionPropertiesService connPropService = (ConnectionPropertiesService) connPropServiceController.getService(); if (!ServiceController.State.UP.equals(connPropServiceController.getState())) { connPropServiceController.setMode(ServiceController.Mode.ACTIVE); connectionProperties.put(connPropService.getName(), builder.requires(name)); } else { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.connectionProperty", name)); } } } final DataSourceConfigService configService = new DataSourceConfigService(dataSourceConfig, connectionProperties); builder.setInstance(configService); builder.install(); } final ServiceName dataSourceServiceNameAlias = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName).append(Constants.STATISTICS); if (dataSourceController != null) { if (!ServiceController.State.UP.equals(dataSourceController.getState())) { final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean(); DataSourceStatisticsService statsService = new DataSourceStatisticsService(datasourceRegistration, statsEnabled); final ServiceBuilder statsServiceSB = serviceTarget.addService(dataSourceServiceName.append(Constants.STATISTICS), statsService); statsServiceSB.addAliases(dataSourceServiceNameAlias); statsServiceSB.requires(dataSourceServiceName); statsServiceSB.addDependency(CommonDeploymentService.getServiceName( ContextNames.bindInfoFor(jndiName)), CommonDeployment.class, statsService.getCommonDeploymentInjector()); statsServiceSB.setInitialMode(ServiceController.Mode.PASSIVE); statsServiceSB.install(); dataSourceController.setMode(ServiceController.Mode.ACTIVE); } else { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source", dsName)); } } else { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceNotAvailable("Data-source", dsName)); } final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService(); final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE .append(dsName); final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, DataSource.class, referenceFactoryService.getDataSourceInjector()); referenceBuilder.install(); final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName); final BinderService binderService = new BinderService(bindInfo.getBindName()); final ServiceBuilder<?> binderBuilder = serviceTarget .addService(bindInfo.getBinderServiceName(), binderService) .addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()) .addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new LifecycleListener() { private volatile boolean bound; public void handleEvent(final ServiceController<? extends Object> controller, final LifecycleEvent event) { switch (event) { case UP: { if (jta) { SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName); } else { SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName); } bound = true; break; } case DOWN: { if (bound) { if (jta) { SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName); } else { SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName); } } break; } case REMOVED: { SUBSYSTEM_DATASOURCES_LOGGER.debugf("Removed JDBC Data-source [%s]", jndiName); break; } } } }); binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE); binderBuilder.install(); } protected abstract void startConfigAndAddDependency(ServiceBuilder<?> dataSourceServiceBuilder, AbstractDataSourceService dataSourceService, String jndiName, ServiceTarget serviceTarget, final ModelNode operation) throws OperationFailedException; protected abstract AbstractDataSourceService createDataSourceService(final String dsName, final String jndiName) throws OperationFailedException; protected abstract boolean isXa(); static Collection<AttributeDefinition> join(final AttributeDefinition[] a, final AttributeDefinition[] b) { final List<AttributeDefinition> result = new ArrayList<>(); result.addAll(Arrays.asList(a)); result.addAll(Arrays.asList(b)); return result; } private static final class DriverDemanderService implements Service { private final Consumer<Driver> driverConsumer; private final Supplier<Driver> driverSupplier; private DriverDemanderService(final Consumer<Driver> driverConsumer, final Supplier<Driver> driverSupplier) { this.driverConsumer = driverConsumer; this.driverSupplier = driverSupplier; } @Override public void start(final StartContext startContext) { driverConsumer.accept(driverSupplier.get()); } @Override public void stop(final StopContext stopContext) { driverConsumer.accept(null); } } }
29,483
58.684211
229
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XMLDataSourceRuntimeHandler.java
/* * 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.connector.subsystems.datasources; import java.util.Map; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.common.Pool; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.DsPool; import org.jboss.modules.ModuleClassLoader; /** * Runtime attribute handler for XML datasources * * @author Stuart Douglas */ public class XMLDataSourceRuntimeHandler extends AbstractXMLDataSourceRuntimeHandler<DataSource> { public static final XMLDataSourceRuntimeHandler INSTANCE = new XMLDataSourceRuntimeHandler(); @Override protected void executeReadAttribute(final String attributeName, final OperationContext context, final DataSource dataSource, final PathAddress address) { final String target = address.getLastElement().getKey(); if(target.equals(CONNECTION_PROPERTIES)) { handlePropertyAttribute(attributeName, context, dataSource, address.getLastElement().getValue()); } else if(target.equals(DATA_SOURCE)) { handleDatasourceAttribute(attributeName, context, dataSource); } } private void handlePropertyAttribute(final String attributeName, final OperationContext context, final DataSource dataSource, final String propName) { if(attributeName.equals(ModelDescriptionConstants.VALUE)) { setStringIfNotNull(context, dataSource.getConnectionProperties().get(propName)); } else { throw ConnectorLogger.ROOT_LOGGER.unknownAttribute(attributeName); } } private void handleDatasourceAttribute(final String attributeName, final OperationContext context, final DataSource dataSource) { if (attributeName.equals(Constants.CONNECTION_URL.getName())) { setStringIfNotNull(context, dataSource.getConnectionUrl()); } else if (attributeName.equals(Constants.CONNECTION_PROPERTIES.getName())) { final Map<String, String> propertiesMap = dataSource.getConnectionProperties(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.DRIVER_CLASS.getName())) { setStringIfNotNull(context, dataSource.getDriverClass()); } else if (attributeName.equals(Constants.DATASOURCE_CLASS.getName())) { setStringIfNotNull(context, dataSource.getDataSourceClass()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME.getName())) { setStringIfNotNull(context, dataSource.getJndiName()); } else if (attributeName.equals(Constants.DATASOURCE_DRIVER.getName())) { setStringIfNotNull(context, dataSource.getDriver()); } else if (attributeName.equals(Constants.NEW_CONNECTION_SQL.getName())) { setStringIfNotNull(context, dataSource.getNewConnectionSql()); } else if (attributeName.equals(Constants.URL_DELIMITER.getName())) { setStringIfNotNull(context, dataSource.getUrlDelimiter()); } else if (attributeName.equals(Constants.URL_SELECTOR_STRATEGY_CLASS_NAME.getName())) { setStringIfNotNull(context, dataSource.getUrlSelectorStrategyClassName()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT.getName())) { setBooleanIfNotNull(context, dataSource.isUseJavaContext()); } else if (attributeName.equals(Constants.JTA.getName())) { setBooleanIfNotNull(context, dataSource.isJTA()); } else if (attributeName.equals(Constants.ENABLED.getName())) { setBooleanIfNotNull(context, dataSource.isEnabled()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE.getName())) { if (dataSource.getPool() == null) { return; } setIntIfNotNull(context, dataSource.getPool().getMaxPoolSize()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE.getName())) { if (dataSource.getPool() == null) { return; } setIntIfNotNull(context, dataSource.getPool().getInitialPoolSize()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE.getName())) { if (dataSource.getPool() == null) { return; } setIntIfNotNull(context, dataSource.getPool().getMinPoolSize()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL.getName())) { if (dataSource.getPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getPool().isPrefill()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR.getName())) { if (dataSource.getPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getPool().isFair()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN.getName())) { if (dataSource.getPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getPool().isUseStrictMin()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS.getName())) { if (dataSource.getPool() == null || dataSource.getPool().getCapacity() == null || dataSource.getPool().getCapacity().getIncrementer() == null) { return; } setStringIfNotNull(context, dataSource.getPool().getCapacity().getIncrementer().getClassName()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS.getName())) { if (dataSource.getPool() == null || dataSource.getPool().getCapacity() == null || dataSource.getPool().getCapacity().getDecrementer() == null) { return; } setStringIfNotNull(context, dataSource.getPool().getCapacity().getDecrementer().getClassName()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES.getName())) { Pool pool = dataSource.getPool(); if (pool == null || pool.getCapacity() == null || pool.getCapacity().getIncrementer() == null) return; final Map<String, String> propertiesMap = pool.getCapacity().getIncrementer().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES.getName())) { Pool pool = dataSource.getPool(); if (pool == null || pool.getCapacity() == null || pool.getCapacity().getDecrementer() == null) return; final Map<String, String> propertiesMap = pool.getCapacity().getDecrementer().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.USERNAME.getName())) { if (dataSource.getSecurity() == null) { return; } setStringIfNotNull(context, dataSource.getSecurity().getUserName()); } else if (attributeName.equals(Constants.PASSWORD.getName())) { //don't give out the password } else if (attributeName.equals(Constants.CREDENTIAL_REFERENCE.getName())) { //don't give out the credential-reference } else if (attributeName.equals(Constants.SECURITY_DOMAIN.getName())) { if (dataSource.getSecurity() == null) { return; } if (dataSource.getSecurity().getSecurityDomain() == null) { return; } throw new IllegalStateException(ConnectorLogger.ROOT_LOGGER.legacySecurityNotSupported()); } else if (attributeName.equals(Constants.ELYTRON_ENABLED.getName())) { setBooleanIfNotNull(context, true); } else if (attributeName.equals(Constants.AUTHENTICATION_CONTEXT.getName())) { setStringIfNotNull(context, dataSource.getSecurity().getSecurityDomain()); } else if (attributeName.equals(Constants.REAUTH_PLUGIN_CLASSNAME.getName())) { if (dataSource.getSecurity() == null) { return; } if (dataSource.getSecurity().getReauthPlugin() == null) { return; } setStringIfNotNull(context, dataSource.getSecurity().getReauthPlugin().getClassName()); } else if (attributeName.equals(Constants.REAUTHPLUGIN_PROPERTIES.getName())) { if (dataSource.getSecurity() == null) { return; } if (dataSource.getSecurity().getReauthPlugin() == null) { return; } final Map<String, String> propertiesMap = dataSource.getSecurity().getReauthPlugin().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY.getName())) { if (dataSource.getPool() == null) { return; } setStringIfNotNull(context, dataSource.getPool().getFlushStrategy().getName()); } else if (attributeName.equals(Constants.PREPARED_STATEMENTS_CACHE_SIZE.getName())) { if (dataSource.getStatement() == null) { return; } setLongIfNotNull(context, dataSource.getStatement().getPreparedStatementsCacheSize()); } else if (attributeName.equals(Constants.SHARE_PREPARED_STATEMENTS.getName())) { if (dataSource.getStatement() == null) { return; } setBooleanIfNotNull(context, dataSource.getStatement().isSharePreparedStatements()); } else if (attributeName.equals(Constants.TRACK_STATEMENTS.getName())) { if (dataSource.getStatement() == null) { return; } if (dataSource.getStatement().getTrackStatements() == null) { return; } setStringIfNotNull(context, dataSource.getStatement().getTrackStatements().name()); } else if (attributeName.equals(Constants.ALLOCATION_RETRY.getName())) { if (dataSource.getTimeOut() == null) { return; } setIntIfNotNull(context, dataSource.getTimeOut().getAllocationRetry()); } else if (attributeName.equals(Constants.ALLOCATION_RETRY_WAIT_MILLIS.getName())) { if (dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getAllocationRetryWaitMillis()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS.getName())) { if (dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getBlockingTimeoutMillis()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES.getName())) { if (dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getIdleTimeoutMinutes()); } else if (attributeName.equals(Constants.QUERY_TIMEOUT.getName())) { if (dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getQueryTimeout()); } else if (attributeName.equals(Constants.USE_TRY_LOCK.getName())) { if (dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getUseTryLock()); } else if (attributeName.equals(Constants.SET_TX_QUERY_TIMEOUT.getName())) { if (dataSource.getTimeOut() == null) { return; } setBooleanIfNotNull(context, dataSource.getTimeOut().isSetTxQueryTimeout()); } else if (attributeName.equals(Constants.TRANSACTION_ISOLATION.getName())) { if (dataSource.getTransactionIsolation() == null) { return; } setStringIfNotNull(context, dataSource.getTransactionIsolation().name()); } else if (attributeName.equals(Constants.CHECK_VALID_CONNECTION_SQL.getName())) { if (dataSource.getValidation() == null) { return; } setStringIfNotNull(context, dataSource.getValidation().getCheckValidConnectionSql()); } else if (attributeName.equals(Constants.EXCEPTION_SORTER_CLASSNAME.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getExceptionSorter() == null) { return; } setStringIfNotNull(context, dataSource.getValidation().getExceptionSorter().getClassName()); } else if (attributeName.equals(Constants.EXCEPTION_SORTER_MODULE.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getExceptionSorter() == null) { return; } ClassLoader exceptionSorterClassLoader = dataSource.getValidation().getExceptionSorter().getClassLoader(); if (exceptionSorterClassLoader instanceof ModuleClassLoader) { setStringIfNotNull(context, ((ModuleClassLoader) exceptionSorterClassLoader).getModule().toString()); } } else if (attributeName.equals(Constants.EXCEPTION_SORTER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getExceptionSorter() == null) { return; } final Map<String, String> propertiesMap = dataSource.getValidation().getExceptionSorter().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_CLASSNAME.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getStaleConnectionChecker() == null) { return; } setStringIfNotNull(context, dataSource.getValidation().getStaleConnectionChecker().getClassName()); } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_MODULE.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getStaleConnectionChecker() == null) { return; } ClassLoader staleConnectionCheckerClassLoader = dataSource.getValidation().getStaleConnectionChecker().getClassLoader(); if (staleConnectionCheckerClassLoader instanceof ModuleClassLoader) { setStringIfNotNull(context, ((ModuleClassLoader) staleConnectionCheckerClassLoader).getModule().toString()); } } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getStaleConnectionChecker() == null) { return; } final Map<String, String> propertiesMap = dataSource.getValidation().getStaleConnectionChecker().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_CLASSNAME.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getValidConnectionChecker() == null) { return; } setStringIfNotNull(context, dataSource.getValidation().getValidConnectionChecker().getClassName()); } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_MODULE.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getValidConnectionChecker() == null) { return; } ClassLoader validConnectionCheckerClassLoader = dataSource.getValidation().getValidConnectionChecker().getClassLoader(); if (validConnectionCheckerClassLoader instanceof ModuleClassLoader) { setStringIfNotNull(context, ((ModuleClassLoader) validConnectionCheckerClassLoader).getModule().toString()); } } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getValidConnectionChecker() == null) { return; } final Map<String, String> propertiesMap = dataSource.getValidation().getValidConnectionChecker().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS.getName())) { if (dataSource.getValidation() == null) { return; } setLongIfNotNull(context, dataSource.getValidation().getBackgroundValidationMillis()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION.getName())) { if (dataSource.getValidation() == null) { return; } setBooleanIfNotNull(context, dataSource.getValidation().isBackgroundValidation()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL.getName())) { if (dataSource.getValidation() == null) { return; } setBooleanIfNotNull(context, dataSource.getValidation().isUseFastFail()); } else if (attributeName.equals(Constants.VALIDATE_ON_MATCH.getName())) { if (dataSource.getValidation() == null) { return; } setBooleanIfNotNull(context, dataSource.getValidation().isValidateOnMatch()); } else if (attributeName.equals(Constants.SPY.getName())) { setBooleanIfNotNull(context, dataSource.isSpy()); } else if (attributeName.equals(Constants.USE_CCM.getName())) { setBooleanIfNotNull(context, dataSource.isUseCcm()); } else if (attributeName.equals(Constants.ALLOW_MULTIPLE_USERS.getName())) { Pool pool = dataSource.getPool(); if (!(pool instanceof DsPool)) { return; } setBooleanIfNotNull(context, ((DsPool) pool).isAllowMultipleUsers()); } else if (attributeName.equals(Constants.CONNECTION_LISTENER_CLASS.getName())) { Pool pool = dataSource.getPool(); if (!(pool instanceof DsPool) || ((DsPool) pool).getConnectionListener() == null) { return; } setStringIfNotNull(context, ((DsPool) pool).getConnectionListener().getClassName()); } else if (attributeName.equals(Constants.CONNECTION_LISTENER_PROPERTIES.getName())) { Pool pool = dataSource.getPool(); if (!(pool instanceof DsPool) || ((DsPool) pool).getConnectionListener() == null) { return; } final Map<String, String> propertiesMap = ((DsPool) pool).getConnectionListener().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.CONNECTABLE.getName())) { //Just set to false context.getResult().set(false); } else if (attributeName.equals(Constants.STATISTICS_ENABLED.getName())) { //Just set to false context.getResult().set(false); } else if (attributeName.equals(Constants.TRACKING.getName())) { //Just return w/o setting a result return; } else if (attributeName.equals(Constants.MCP.getName())) { //Just return w/o setting a result return; } else if (attributeName.equals(Constants.ENLISTMENT_TRACE.getName())) { //Just return w/o setting a result return; } else { throw ConnectorLogger.ROOT_LOGGER.unknownAttribute(attributeName); } } }
24,388
53.683857
157
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XaDataSourcePropertyDefinition.java
/* * * 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.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.XADATASOURCE_PROPERTIES; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * @author Stefano Maestri */ public class XaDataSourcePropertyDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_PROPERTIES = PathElement.pathElement(XADATASOURCE_PROPERTIES.getName()); private final boolean deployed; XaDataSourcePropertyDefinition(final boolean deployed) { super(PATH_PROPERTIES, DataSourcesExtension.getResourceDescriptionResolver("xa-data-source", "xa-datasource-properties"), deployed ? null : XaDataSourcePropertyAdd.INSTANCE, deployed ? null : XaDataSourcePropertyRemove.INSTANCE); this.deployed = deployed; } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { if (deployed) { SimpleAttributeDefinition runtimeAttribute = new SimpleAttributeDefinitionBuilder(Constants.XADATASOURCE_PROPERTY_VALUE).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLXaDataSourceRuntimeHandler.INSTANCE); } else { resourceRegistration.registerReadOnlyAttribute(Constants.XADATASOURCE_PROPERTY_VALUE, null); } } }
2,788
42.578125
188
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/ConnectionPropertyRemove.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, 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.connector.subsystems.datasources; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.controller.AbstractRemoveStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceName; /** * Operation handler responsible for removing a (XA)DataSource. * * @author Stefano Maestrioperation2.get(OP).set("write-attribute"); */ public class ConnectionPropertyRemove extends AbstractRemoveStepHandler { public static final ConnectionPropertyRemove INSTANCE = new ConnectionPropertyRemove(); @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { if (context.isResourceServiceRestartAllowed()) { final ModelNode address = operation.require(OP_ADDR); final PathAddress path = PathAddress.pathAddress(address); final String jndiName = path.getElement(path.size() - 2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName configPropertyServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(jndiName) .append("connection-properties").append(configPropertyName); context.removeService(configPropertyServiceName); } else { context.reloadRequired(); } } }
2,626
38.80303
131
java