Search in sources :

Example 1 with Java2DBProcessorHelper

use of org.glassfish.persistence.common.Java2DBProcessorHelper in project Payara by payara.

the class JPADeployer method cleanArtifacts.

protected void cleanArtifacts(DeploymentContext dc) throws DeploymentException {
    // Drop tables if needed on undeploy.
    OpsParams params = dc.getCommandParameters(OpsParams.class);
    if (params.origin.isUndeploy() && isDas()) {
        boolean hasScopedResource = false;
        String appName = params.name();
        ApplicationInfo appInfo = applicationRegistry.get(appName);
        Application application = appInfo.getMetaData(Application.class);
        Set<BundleDescriptor> bundles = application.getBundleDescriptors();
        // Iterate through all the bundles of the app and collect pu references in referencedPus
        for (BundleDescriptor bundle : bundles) {
            Collection<? extends PersistenceUnitDescriptor> pusReferencedFromBundle = bundle.findReferencedPUs();
            for (PersistenceUnitDescriptor pud : pusReferencedFromBundle) {
                hasScopedResource = hasScopedResource(pud);
                if (hasScopedResource) {
                    break;
                }
            }
        }
        // delete tables.
        if (hasScopedResource) {
            connectorRuntime.registerDataSourceDefinitions(application);
        }
        Java2DBProcessorHelper helper = new Java2DBProcessorHelper(dc);
        helper.init();
        // NOI18N
        helper.createOrDropTablesInDB(false, "JPA");
        // if there are scoped resources, undeploy them.
        if (hasScopedResource) {
            connectorRuntime.unRegisterDataSourceDefinitions(application);
        }
    }
}
Also used : Java2DBProcessorHelper(org.glassfish.persistence.common.Java2DBProcessorHelper) OpsParams(org.glassfish.api.deployment.OpsParams) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo)

Example 2 with Java2DBProcessorHelper

use of org.glassfish.persistence.common.Java2DBProcessorHelper in project Payara by payara.

the class PersistentEJBTimerService method isUpgrade.

private static boolean isUpgrade(String resource, EjbTimerService _ejbt, File root) {
    boolean upgrade = false;
    Property prop = null;
    if (_ejbt != null) {
        List<Property> properties = _ejbt.getProperty();
        if (properties != null) {
            for (Property p : properties) {
                if (p.getName().equals(EjbContainerUtil.TIMER_SERVICE_UPGRADED)) {
                    String value = p.getValue();
                    if (value != null && "false".equals(value)) {
                        upgrade = true;
                        prop = p;
                        break;
                    }
                }
            }
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("===> Upgrade? <==");
    }
    if (upgrade) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("===> Upgrade! <==");
        }
        boolean success = false;
        try {
            File dir = new File(root, "lib/install/databases/upgrade");
            if (!dir.exists()) {
                logger.log(Level.WARNING, "Cannot upgrade EJBTimerService: " + "required directory is not available");
            } else {
                Java2DBProcessorHelper h = new Java2DBProcessorHelper(TIMER_SERVICE_APP_NAME);
                success = h.executeDDLStatement(dir.getCanonicalPath() + "/ejbtimer_upgrade_", resource);
                ConfigSupport.apply(new SingleConfigCode<Property>() {

                    public Object run(Property p) throws PropertyVetoException, TransactionFailure {
                        p.setValue("true");
                        return null;
                    }
                }, prop);
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "", e);
        }
        if (!success) {
            logger.log(Level.SEVERE, "Failed to upgrade EJBTimerService: see log for details");
        }
    }
    return upgrade;
}
Also used : Java2DBProcessorHelper(org.glassfish.persistence.common.Java2DBProcessorHelper) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Property(org.jvnet.hk2.config.types.Property) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) CreateException(javax.ejb.CreateException)

Example 3 with Java2DBProcessorHelper

use of org.glassfish.persistence.common.Java2DBProcessorHelper 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[] { createTables, 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 4 with Java2DBProcessorHelper

use of org.glassfish.persistence.common.Java2DBProcessorHelper in project Payara by payara.

the class CMPProcessor method clean.

/**
 * Drop files on undeploy
 */
public void clean() {
    helper = new Java2DBProcessorHelper(ctx);
    helper.init();
    // NOI18N
    helper.createOrDropTablesInDB(false, "CMP");
}
Also used : Java2DBProcessorHelper(org.glassfish.persistence.common.Java2DBProcessorHelper)

Aggregations

Java2DBProcessorHelper (org.glassfish.persistence.common.Java2DBProcessorHelper)4 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 PropertyVetoException (java.beans.PropertyVetoException)1 File (java.io.File)1 CreateException (javax.ejb.CreateException)1 EJBException (javax.ejb.EJBException)1 FinderException (javax.ejb.FinderException)1 OpsParams (org.glassfish.api.deployment.OpsParams)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1 Property (org.jvnet.hk2.config.types.Property)1