Search in sources :

Example 6 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class EjbBundleDescriptorImpl method getEjbResourceReferenceDescriptors.

/**
 * Return the set of references to resources held by ejbs defined in this module.
 */
public Set<ResourceReferenceDescriptor> getEjbResourceReferenceDescriptors() {
    Set<ResourceReferenceDescriptor> resourceReferences = new HashSet<ResourceReferenceDescriptor>();
    for (Iterator itr = getEjbs().iterator(); itr.hasNext(); ) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
        resourceReferences.addAll(ejbDescriptor.getResourceReferenceDescriptors());
    }
    return resourceReferences;
}
Also used : Iterator(java.util.Iterator) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) HashSet(java.util.HashSet)

Example 7 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class MappingGenerator method checkOrCreateCMPResource.

/**
 * Check if cmp resource is specified in the deployment descriptor.
 * If the beans are mapped (sun-cmp-mapping.xml is present), the cmp
 * resource must be present, otherwise (in java2db case) we will create
 * a default one. If it's java2db, we will also parse the CLI overrides,
 * as the cmp resource provides the default values.
 *
 * @param mappedBeans true if beans are mapped in this module.
 * @throws GeneratorException if beans are mapped but cmp resource is not
 * specified.
 */
private ResourceReferenceDescriptor checkOrCreateCMPResource(boolean mappedBeans) throws GeneratorException {
    ResourceReferenceDescriptor cmpResource = bundle.getCMPResourceReference();
    if (mappedBeans) {
        if (cmpResource == null) {
            // database or a PMF JNDI name.
            throw JDOCodeGeneratorHelper.createGeneratorException("EXC_MissingCMPResource", // NOI18N
            bundle);
        }
    } else {
        if (cmpResource == null) {
            // In JavaToDB case we can deploy to the default jdbc-resource.
            cmpResource = new ResourceReferenceDescriptor();
            cmpResource.setJndiName("jdbc/__default");
            cmpResource.setDatabaseVendorName(DBVendorTypeHelper.DERBY);
            cmpResource.setCreateTablesAtDeploy(true);
            cmpResource.setDropTablesAtUndeploy(true);
            bundle.setCMPResourceReference(cmpResource);
        }
    }
    return cmpResource;
}
Also used : ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor)

Example 8 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class MappingGenerator method generateMapping.

/**
 * This method will load mapping classes if there is sun-cmp-mappings.xml,
 * otherwise it will call the database generation backend to create
 * mapping classes and schema.  It also generates *.dbschema and
 * sun-cmp-mappings.xml in application dir if it is
 * in creating mapping classes mode.
 * @param ctx an object containing CLI options for
 * the database generation backend
 * @param inputFilesPath the directory where sun-cmp-mappings.xml is located
 * @param generatedXmlsPath the directory where the generated files are located
 * @param classout the directory where the classes are located
 * @param ignoreSunDeploymentDescriptors use java2db generation if set to <code>true</code>.
 * @return a SchemaElement for mapping classes mapped to
 * @throws IOException
 * @throws DBException
 * @throws ModelException
 * @throws Schema2BeansException
 * @throws SQLException
 * @throws GeneratorException
 * @throws ConversionException
 */
public SchemaElement generateMapping(DeploymentContext ctx, String inputFilesPath, String generatedXmlsPath, File classout, boolean ignoreSunDeploymentDescriptors) throws IOException, DBException, ModelException, Schema2BeansException, SQLException, GeneratorException, ConversionException {
    SchemaElement schema = null;
    if (ctx == null)
        isVerifyFlag = true;
    File cmpMappingFile = getSunCmpMappingFile(inputFilesPath);
    boolean mappedBeans = !ignoreSunDeploymentDescriptors && cmpMappingFile.exists();
    ResourceReferenceDescriptor cmpResource = checkOrCreateCMPResource(mappedBeans);
    // Remember whether or not this mapping was created by Java2DB.
    isJavaToDatabaseFlag = DeploymentHelper.isJavaToDatabase(cmpResource.getSchemaGeneratorProperties());
    // We *must* get a vendor name if either the beans are not mapped, or
    // they are mapped and the javaToDatabase flag is set.
    boolean mustHaveDBVendorName = !mappedBeans || (mappedBeans && isJavaToDatabaseFlag);
    // Read deployment settings from the deployment descriptor
    // and CLI options.
    Results deploymentArguments = getDeploymentArguments(ctx, cmpResource, mustHaveDBVendorName);
    dbVendorName = deploymentArguments.getDatabaseVendorName();
    if (mappedBeans) {
        // If it is from verify, skip deployment arguments check.
        if (!isVerifyFlag) {
            // Warning for user, if required.
            String warning = null;
            if (isJavaToDatabaseFlag) {
                // as per the mapping.
                if (deploymentArguments.hasUniqueTableNames()) {
                    warning = I18NHelper.getMessage(messages, // NOI18N
                    "EXC_DisallowJava2DBUniqueTableNames", bundle.getApplication().getRegistrationName(), JDOCodeGeneratorHelper.getModuleName(bundle));
                    logger.warning(warning);
                }
            } else if (deploymentArguments.hasJavaToDatabaseArgs()) {
                // If beans are already mapped but the user gave any Java2DB
                // command line arguments, warn the user that these args
                // should not be used when module is already mapped.
                warning = I18NHelper.getMessage(messages, // NOI18N
                "EXC_DisallowJava2DBCLIOverrides", bundle.getApplication().getRegistrationName(), JDOCodeGeneratorHelper.getModuleName(bundle));
                logger.warning(warning);
            }
            if (warning != null) {
                ActionReport subActionReport = ctx.getActionReport().addSubActionsReport();
                // Propagte warning to client side so that the deployer can see the warning.
                Java2DBProcessorHelper.warnUser(subActionReport, warning);
            }
        }
        // Sun-cmp-mapping.xml exists, use normal MappingClass loading
        SunCmpMappings sunCmpMappings = getSunCmpMappings(cmpMappingFile);
        // Ensure that there is a dbschema for each element of
        // sunCmpMappings.
        ensureDBSchemaExistence(cmpResource, sunCmpMappings, inputFilesPath, classout);
        // load real mapping model and jdo model in memory
        Map mappingClasses = loadMappingClasses(sunCmpMappings, getClassLoader());
        // Get schema from one of the mapping classes.
        // The mapping class element may be null if there is inconsistency
        // in sun-cmp-mappings.xml and ejb-jar.xml. For example,
        // the bean has mapping information in sun-cmp-mappings.xml but
        // no definition in the ejb-jar.xml.
        // So iterate over the mappings until the 1st non-null is found.
        MappingClassElement mc = null;
        Iterator iter = mappingClasses.values().iterator();
        while (iter.hasNext()) {
            mc = (MappingClassElement) iter.next();
            if (mc != null) {
                schema = SchemaElement.forName(mc.getDatabaseRoot());
                break;
            }
        }
        if (logger.isLoggable(Logger.FINE)) {
            logger.fine(// NOI18N
            "Loaded mapped beans for " + cmpResource.getJndiName() + ", isJavaToDatabase=" + // NOI18N
            isJavaToDatabaseFlag);
        }
    } else {
        // Generate mapping file and dbschema, since either
        // sun-cmp-mappings.xml does not exist (e.g. user didn't yet map)
        // or DeploymentContext is null (e.g. running under auspices of AVK).
        DatabaseGenerator.Results results = generateMappingClasses(dbVendorName, deploymentArguments.getUseUniqueTableNames(), deploymentArguments.getUserPolicy(), inputFilesPath);
        // java2db from verifier should not save anything to disk
        if (!isVerifyFlag) {
            // save SunCmpMapping to sun-cmp-mappings.xml
            // in generated XML dir
            writeSunCmpMappingFile(results.getMappingClasses(), getSunCmpMappingFile(generatedXmlsPath));
            schema = results.getSchema();
            // save schema to dbschema file in generated XML dir
            writeSchemaFile(schema, classout);
            setJavaToDatabase(cmpResource, true);
        }
    }
    return schema;
}
Also used : MappingClassElement(com.sun.jdo.api.persistence.model.mapping.MappingClassElement) ActionReport(org.glassfish.api.ActionReport) DatabaseGenerator(com.sun.jdo.spi.persistence.generator.database.DatabaseGenerator) Iterator(java.util.Iterator) SchemaElement(org.netbeans.modules.dbschema.SchemaElement) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) MappingFile(com.sun.jdo.api.persistence.mapping.ejb.MappingFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) SunCmpMappings(com.sun.jdo.api.persistence.mapping.ejb.beans.SunCmpMappings)

Example 9 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class CMPProcessor method process.

/**
 * Create and execute the files.
 */
public void process() {
    EjbBundleDescriptorImpl bundle = ctx.getModuleMetaData(EjbBundleDescriptorImpl.class);
    ResourceReferenceDescriptor cmpResource = bundle.getCMPResourceReference();
    // If this bundle's beans are not created by Java2DB, there is nothing to do.
    if (!DeploymentHelper.isJavaToDatabase(cmpResource.getSchemaGeneratorProperties())) {
        return;
    }
    helper = new Java2DBProcessorHelper(ctx);
    helper.init();
    String resourceName = cmpResource.getJndiName();
    // NOI18N
    helper.setProcessorType("CMP", bundle.getName());
    helper.setJndiName(resourceName, bundle.getName());
    // If CLI options are not set, use value from the create-tables-at-deploy
    // or drop-tables-at-undeploy elements of the sun-ejb-jar.xml
    boolean userCreateTables = cmpResource.isCreateTablesAtDeploy();
    boolean createTables = helper.getCreateTables(userCreateTables);
    boolean userDropTables = cmpResource.isDropTablesAtUndeploy();
    if (logger.isLoggable(logger.FINE)) {
        // NOI18N
        logger.fine(// NOI18N
        "ejb.CMPProcessor.createanddroptables", new Object[] { new Boolean(createTables), new Boolean(userDropTables) });
    }
    if (!createTables && !userDropTables) {
        // Nothing to do.
        return;
    }
    helper.setCreateTablesValue(userCreateTables, bundle.getName());
    helper.setDropTablesValue(userDropTables, bundle.getName());
    constructJdbcFileNames(bundle);
    if (logger.isLoggable(logger.FINE)) {
        logger.fine("ejb.CMPProcessor.createanddropfilenames", helper.getCreateJdbcFileName(bundle.getName()), helper.getDropJdbcFileName(bundle.getName()));
    }
    if (createTables) {
        // NOI18N
        helper.createOrDropTablesInDB(true, "CMP");
    }
}
Also used : Java2DBProcessorHelper(org.glassfish.persistence.common.Java2DBProcessorHelper) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 10 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class ConnectionManagerImpl method allocateConnection.

public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo cxRequestInfo, String jndiNameToUse, Object conn) throws ResourceException {
    validateResourceAndPool();
    PoolManager poolmgr = ConnectorRuntime.getRuntime().getPoolManager();
    boolean resourceShareable = true;
    ResourceReferenceDescriptor ref = poolmgr.getResourceReference(jndiNameToUse, logicalName);
    if (ref != null) {
        String shareableStr = ref.getSharingScope();
        if (shareableStr.equals(ref.RESOURCE_UNSHAREABLE)) {
            resourceShareable = false;
        }
    }
    // TODO V3 refactor all the 3 cases viz, no res-ref, app-auth, cont-auth.
    if (ref == null) {
        if (getLogger().isLoggable(Level.FINE)) {
            getLogger().log(Level.FINE, "poolmgr.no_resource_reference", jndiNameToUse);
        }
        return internalGetConnection(mcf, defaultPrin, cxRequestInfo, resourceShareable, jndiNameToUse, conn, true);
    }
    String auth = ref.getAuthorization();
    if (auth.equals(ResourceReferenceDescriptor.APPLICATION_AUTHORIZATION)) {
        if (cxRequestInfo == null) {
            String msg = getLocalStrings().getString("con_mgr.null_userpass");
            throw new ResourceException(msg);
        }
        ConnectorRuntime.getRuntime().switchOnMatching(rarName, poolInfo);
        return internalGetConnection(mcf, null, cxRequestInfo, resourceShareable, jndiNameToUse, conn, false);
    } else {
        ResourcePrincipal prin = null;
        Set principalSet = null;
        Principal callerPrincipal = null;
        SecurityContext securityContext = null;
        ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
        // TODO V3 is SecurityContext.getCurrent() the right way ? Does it need to be injected ?
        if (connectorRuntime.isServer() && (securityContext = SecurityContext.getCurrent()) != null && (callerPrincipal = securityContext.getCallerPrincipal()) != null && (principalSet = securityContext.getPrincipalSet()) != null) {
            AuthenticationService authService = connectorRuntime.getAuthenticationService(rarName, poolInfo);
            if (authService != null) {
                prin = (ResourcePrincipal) authService.mapPrincipal(callerPrincipal, principalSet);
            }
        }
        if (prin == null) {
            prin = ref.getResourcePrincipal();
            if (prin == null) {
                if (getLogger().isLoggable(Level.FINE)) {
                    getLogger().log(Level.FINE, "default-resource-principal not" + "specified for " + jndiNameToUse + ". Defaulting to" + " user/password specified in the pool");
                }
                prin = defaultPrin;
            } else if (!prin.equals(defaultPrin)) {
                ConnectorRuntime.getRuntime().switchOnMatching(rarName, poolInfo);
            }
        }
        return internalGetConnection(mcf, prin, cxRequestInfo, resourceShareable, jndiNameToUse, conn, false);
    }
}
Also used : Set(java.util.Set) SecurityContext(com.sun.enterprise.security.SecurityContext) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) ResourceException(javax.resource.ResourceException) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) PoolManager(com.sun.enterprise.resource.pool.PoolManager) AuthenticationService(com.sun.enterprise.connectors.authentication.AuthenticationService) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Principal(java.security.Principal)

Aggregations

ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)24 Iterator (java.util.Iterator)11 Set (java.util.Set)8 Result (com.sun.enterprise.tools.verifier.Result)6 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)6 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)5 EjbReference (com.sun.enterprise.deployment.types.EjbReference)4 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)3 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)2 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 MessageDestinationRuntimeNode (com.sun.enterprise.deployment.node.runtime.MessageDestinationRuntimeNode)2 RuntimeDescriptorNode (com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode)2 WebServiceRuntimeNode (com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode)2 MessageDestinationReferencer (com.sun.enterprise.deployment.types.MessageDestinationReferencer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)2 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)2