Package org.apache.airavata.persistance.registry.jpa.utils

Examples of org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator


    public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY_WORKER);
            generator.setParameter(AbstractResource.GatewayWorkerConstants.GATEWAY_NAME,
                    gatewayResource.getGatewayName());
            generator.setParameter(AbstractResource.UserConstants.USERNAME, userResource.getUserName());
            Query q = generator.deleteQuery(em);
            q.executeUpdate();
            em.getTransaction().commit();
            em.close();
            return true;
        } catch (Exception e) {
View Full Code Here


        List<ConfigurationResource> list = new ArrayList<ConfigurationResource>();
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator = new QueryGenerator(AbstractResource.CONFIGURATION);
            generator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configKey);
            Query q = generator.selectQuery(em);
            List<?> resultList = q.getResultList();
            if (resultList.size() != 0) {
                for (Object result : resultList) {
                    ConfigurationResource configurationResource = createConfigurationResourceObject(result);
                    list.add(configurationResource);
View Full Code Here

    /**
     * @param configkey
     * @param configValue
     */
    public static void removeConfiguration(String configkey, String configValue) throws RegistryException{
        QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_VAL, configValue);
        EntityManager em = null;
        try {
            if(isConfigurationExists(configkey, configValue)){
                em = getEntityManager();
                em.getTransaction().begin();
                Query q = queryGenerator.deleteQuery(em);
                q.executeUpdate();
                em.getTransaction().commit();
                em.close();
            }
        }catch (Exception e){
View Full Code Here

    /**
     * @param configkey
     */
    public static void removeConfiguration(String configkey) throws RegistryException{
        QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
        queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
        EntityManager em = null;
        try {
            if(isConfigurationExist(configkey)){
                em = getEntityManager();
                em.getTransaction().begin();
                Query q = queryGenerator.deleteQuery(em);
                q.executeUpdate();
                em.getTransaction().commit();
                em.close();
            }
        }catch (Exception e){
View Full Code Here

        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            Query q;
            QueryGenerator generator;
            List results;
            switch (type) {
                case TASK_DETAIL:
                    generator = new QueryGenerator(TASK_DETAIL);
                    generator.setParameter(TaskDetailConstants.NODE_INSTANCE_ID, nodeInstanceId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            TaskDetail taskDetail = (TaskDetail) result;
                            TaskDetailResource taskDetailResource =
                                    (TaskDetailResource) Utils.getResource(ResourceType.TASK_DETAIL, taskDetail);
                            resourceList.add(taskDetailResource);
                        }
                    }
                    break;
                case ERROR_DETAIL:
                    generator = new QueryGenerator(ERROR_DETAIL);
                    generator.setParameter(ErrorDetailConstants.NODE_INSTANCE_ID, nodeInstanceId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            ErrorDetail errorDetail = (ErrorDetail) result;
                            ErrorDetailResource errorDetailResource =
                                    (ErrorDetailResource) Utils.getResource(ResourceType.ERROR_DETAIL, errorDetail);
                            resourceList.add(errorDetailResource);
                        }
                    }
                    break;
                case NODE_INPUT:
                    generator = new QueryGenerator(NODE_INPUT);
                    generator.setParameter(NodeInputConstants.NODE_INSTANCE_ID, nodeInstanceId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            NodeInput nodeInput = (NodeInput) result;
                            NodeInputResource nodeInputResource =
                                    (NodeInputResource) Utils.getResource(ResourceType.NODE_INPUT, nodeInput);
                            resourceList.add(nodeInputResource);
                        }
                    }
                    break;
                case NODE_OUTPUT:
                    generator = new QueryGenerator(NODE_OUTPUT);
                    generator.setParameter(NodeOutputConstants.NODE_INSTANCE_ID, nodeInstanceId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            NodeOutput nodeOutput = (NodeOutput) result;
                            NodeOutputResource nodeOutputResource =
                                    (NodeOutputResource) Utils.getResource(ResourceType.NODE_OUTPUT, nodeOutput);
                            resourceList.add(nodeOutputResource);
                        }
                    }
                    break;
                case STATUS:
                    generator = new QueryGenerator(STATUS);
                    generator.setParameter(StatusConstants.NODE_INSTANCE_ID, nodeInstanceId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            Status status = (Status) result;
                            StatusResource statusResource =
View Full Code Here

        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            Query q;
            QueryGenerator generator;
            switch (type) {
                case PROJECT:
                    generator = new QueryGenerator(PROJECT);
                    generator.setParameter(ProjectConstants.PROJECT_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case USER_WORKFLOW:
                    generator = new QueryGenerator(USER_WORKFLOW);
                    generator.setParameter(UserWorkflowConstants.OWNER, getUser());
                    generator.setParameter(UserWorkflowConstants.TEMPLATE_NAME, name);
                    generator.setParameter(UserWorkflowConstants.GATEWAY_NAME, gateway.getGatewayName());
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case EXPERIMENT:
                    generator = new QueryGenerator(EXPERIMENT);
                    generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                default:
                    logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
                    break;
View Full Code Here

        Resource result = null;
        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator;
            Query q;
            switch (type) {
                case PROJECT:
                    generator = new QueryGenerator(PROJECT);
                    generator.setParameter(ProjectConstants.PROJECT_ID, name);
                    q = generator.selectQuery(em);
                    Project project = (Project) q.getSingleResult();
                    result = Utils.getResource(ResourceType.PROJECT, project);
                    break;
                case USER_WORKFLOW:
                    generator = new QueryGenerator(USER_WORKFLOW);
                    generator.setParameter(UserWorkflowConstants.OWNER, getUser());
                    generator.setParameter(UserWorkflowConstants.TEMPLATE_NAME, name);
                    generator.setParameter(UserWorkflowConstants.GATEWAY_NAME, gateway.getGatewayName());
                    q = generator.selectQuery(em);
                    User_Workflow userWorkflow = (User_Workflow) q.getSingleResult();
                    result = Utils.getResource(ResourceType.USER_WORKFLOW, userWorkflow);
                    break;
                case EXPERIMENT:
                    generator = new QueryGenerator(EXPERIMENT);
                    generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
                    q = generator.selectQuery(em);
                    Experiment experiment = (Experiment) q.getSingleResult();
                    result = Utils.getResource(ResourceType.EXPERIMENT, experiment);
                    break;
                default:
                    logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
View Full Code Here

        List<Resource> result = new ArrayList<Resource>();
        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator;
            Query q;
            switch (type) {
                case PROJECT:
                    generator = new QueryGenerator(PROJECT);
                    Users users = em.find(Users.class, getUser());
                    Gateway gatewayModel = em.find(Gateway.class, gateway.getGatewayName());
                    generator.setParameter("users", users);
                    generator.setParameter("gateway", gatewayModel);
//                generator.setParameter(ProjectConstants.USERNAME, getUser());
//                generator.setParameter(ProjectConstants.GATEWAY_NAME, gateway.getGatewayName());
                    q = generator.selectQuery(em);
                    for (Object o : q.getResultList()) {
                        Project project = (Project) o;
                        ProjectResource projectResource = (ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
                        result.add(projectResource);
                    }
                    break;
                case USER_WORKFLOW:
                    generator = new QueryGenerator(USER_WORKFLOW);
                    generator.setParameter(UserWorkflowConstants.OWNER, getUser());
                    q = generator.selectQuery(em);
//              q.setParameter("usr_name", getUser());
                    for (Object o : q.getResultList()) {
                        User_Workflow userWorkflow = (User_Workflow) o;
                        UserWorkflowResource userWorkflowResource = (UserWorkflowResource) Utils.getResource(ResourceType.USER_WORKFLOW, userWorkflow);
                        result.add(userWorkflowResource);
                    }
                    break;
                case EXPERIMENT:
                    generator = new QueryGenerator(EXPERIMENT);
                    generator.setParameter(ExperimentConstants.EXECUTION_USER, getUser());
                    q = generator.selectQuery(em);
                    for (Object o : q.getResultList()) {
                        Experiment experiment = (Experiment) o;
                        ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
                        result.add(experimentResource);
                    }
View Full Code Here

        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            Query q;
            QueryGenerator generator;
            switch (type) {
                case ERROR_DETAIL:
                    generator = new QueryGenerator(ERROR_DETAIL);
                    generator.setParameter(ErrorDetailConstants.TASK_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case APPLICATION_INPUT:
                    generator = new QueryGenerator(APPLICATION_INPUT);
                    generator.setParameter(ApplicationInputConstants.TASK_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case APPLICATION_OUTPUT:
                    generator = new QueryGenerator(APPLICATION_OUTPUT);
                    generator.setParameter(ApplicationOutputConstants.TASK_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case JOB_DETAIL:
                    generator = new QueryGenerator(JOB_DETAIL);
                    generator.setParameter(JobDetailConstants.TASK_ID, taskId);
                    generator.setParameter(JobDetailConstants.JOB_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case DATA_TRANSFER_DETAIL:
                    generator = new QueryGenerator(DATA_TRANSFER_DETAIL);
                    generator.setParameter(DataTransferDetailConstants.TRANSFER_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case STATUS:
                    generator = new QueryGenerator(STATUS);
                    generator.setParameter(StatusConstants.TASK_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case COMPUTATIONAL_RESOURCE_SCHEDULING:
                    generator = new QueryGenerator(COMPUTATIONAL_RESOURCE_SCHEDULING);
                    generator.setParameter(ComputationalResourceSchedulingConstants.TASK_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case ADVANCE_INPUT_DATA_HANDLING:
                    generator = new QueryGenerator(ADVANCE_INPUT_DATA_HANDLING);
                    generator.setParameter(AdvancedInputDataHandlingConstants.TASK_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case ADVANCE_OUTPUT_DATA_HANDLING:
                    generator = new QueryGenerator(ADVANCE_OUTPUT_DATA_HANDLING);
                    generator.setParameter(AdvancedOutputDataHandlingConstants.TASK_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case QOS_PARAM:
                    generator = new QueryGenerator(QOS_PARAMS);
                    generator.setParameter(QosParamsConstants.TASK_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                default:
                    logger.error("Unsupported resource type for task detail resource.", new IllegalArgumentException());
                    break;
View Full Code Here

    public Resource get(ResourceType type, Object name) throws RegistryException{
        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            QueryGenerator generator;
            Query q;
            switch (type) {
                case ERROR_DETAIL:
                    generator = new QueryGenerator(ERROR_DETAIL);
                    generator.setParameter(ErrorDetailConstants.TASK_ID, name);
                    q = generator.selectQuery(em);
                    ErrorDetail errorDetail = (ErrorDetail) q.getSingleResult();
                    ErrorDetailResource errorDetailResource = (ErrorDetailResource) Utils.getResource(ResourceType.ERROR_DETAIL, errorDetail);
                    em.getTransaction().commit();
                    em.close();
                    return errorDetailResource;
                case APPLICATION_INPUT:
                    generator = new QueryGenerator(APPLICATION_INPUT);
                    generator.setParameter(ApplicationInputConstants.TASK_ID, name);
                    q = generator.selectQuery(em);
                    ApplicationInput applicationInput = (ApplicationInput) q.getSingleResult();
                    ApplicationInputResource inputResource = (ApplicationInputResource) Utils.getResource(ResourceType.APPLICATION_INPUT, applicationInput);
                    em.getTransaction().commit();
                    em.close();
                    return inputResource;
                case APPLICATION_OUTPUT:
                    generator = new QueryGenerator(APPLICATION_OUTPUT);
                    generator.setParameter(ApplicationOutputConstants.TASK_ID, name);
                    q = generator.selectQuery(em);
                    ApplicationOutput applicationOutput = (ApplicationOutput) q.getSingleResult();
                    ApplicationOutputResource outputResource = (ApplicationOutputResource) Utils.getResource(ResourceType.APPLICATION_OUTPUT, applicationOutput);
                    em.getTransaction().commit();
                    em.close();
                    return outputResource;
                case JOB_DETAIL:
                    generator = new QueryGenerator(JOB_DETAIL);
                    generator.setParameter(JobDetailConstants.JOB_ID, name);
                    generator.setParameter(JobDetailConstants.TASK_ID, taskId);
                    q = generator.selectQuery(em);
                    JobDetail jobDetail = (JobDetail) q.getSingleResult();
                    JobDetailResource jobDetailResource = (JobDetailResource) Utils.getResource(ResourceType.JOB_DETAIL, jobDetail);
                    em.getTransaction().commit();
                    em.close();
                    return jobDetailResource;
                case DATA_TRANSFER_DETAIL:
                    generator = new QueryGenerator(DATA_TRANSFER_DETAIL);
                    generator.setParameter(DataTransferDetailConstants.TRANSFER_ID, name);
                    q = generator.selectQuery(em);
                    DataTransferDetail transferDetail = (DataTransferDetail) q.getSingleResult();
                    DataTransferDetailResource transferDetailResource = (DataTransferDetailResource) Utils.getResource(ResourceType.DATA_TRANSFER_DETAIL, transferDetail);
                    em.getTransaction().commit();
                    em.close();
                    return transferDetailResource;
                case STATUS:
                    generator = new QueryGenerator(STATUS);
                    generator.setParameter(StatusConstants.TASK_ID, name);
                    q = generator.selectQuery(em);
                    Status status = (Status) q.getSingleResult();
                    StatusResource statusResource = (StatusResource) Utils.getResource(ResourceType.STATUS, status);
                    em.getTransaction().commit();
                    em.close();
                    return statusResource;
                case COMPUTATIONAL_RESOURCE_SCHEDULING:
                    generator = new QueryGenerator(COMPUTATIONAL_RESOURCE_SCHEDULING);
                    generator.setParameter(ComputationalResourceSchedulingConstants.TASK_ID, name);
                    q = generator.selectQuery(em);
                    Computational_Resource_Scheduling resourceScheduling = (Computational_Resource_Scheduling) q.getSingleResult();
                    ComputationSchedulingResource schedulingResource = (ComputationSchedulingResource) Utils.getResource(ResourceType.COMPUTATIONAL_RESOURCE_SCHEDULING, resourceScheduling);
                    em.getTransaction().commit();
                    em.close();
                    return schedulingResource;
                case ADVANCE_INPUT_DATA_HANDLING:
                    generator = new QueryGenerator(ADVANCE_INPUT_DATA_HANDLING);
                    generator.setParameter(AdvancedInputDataHandlingConstants.TASK_ID, name);
                    q = generator.selectQuery(em);
                    AdvancedInputDataHandling dataHandling = (AdvancedInputDataHandling) q.getSingleResult();
                    AdvanceInputDataHandlingResource inputDataHandlingResource = (AdvanceInputDataHandlingResource) Utils.getResource(ResourceType.ADVANCE_INPUT_DATA_HANDLING, dataHandling);
                    em.getTransaction().commit();
                    em.close();
                    return inputDataHandlingResource;
                case ADVANCE_OUTPUT_DATA_HANDLING:
                    generator = new QueryGenerator(ADVANCE_OUTPUT_DATA_HANDLING);
                    generator.setParameter(AdvancedOutputDataHandlingConstants.TASK_ID, name);
                    q = generator.selectQuery(em);
                    AdvancedOutputDataHandling outputDataHandling = (AdvancedOutputDataHandling) q.getSingleResult();
                    AdvancedOutputDataHandlingResource outputDataHandlingResource = (AdvancedOutputDataHandlingResource) Utils.getResource(ResourceType.ADVANCE_OUTPUT_DATA_HANDLING, outputDataHandling);
                    em.getTransaction().commit();
                    em.close();
                    return outputDataHandlingResource;
                case QOS_PARAM:
                    generator = new QueryGenerator(QOS_PARAMS);
                    generator.setParameter(QosParamsConstants.TASK_ID, name);
                    q = generator.selectQuery(em);
                    QosParam qosParam = (QosParam) q.getSingleResult();
                    QosParamResource qosParamResource = (QosParamResource) Utils.getResource(ResourceType.QOS_PARAM, qosParam);
                    em.getTransaction().commit();
                    em.close();
                    return qosParamResource;
View Full Code Here

TOP

Related Classes of org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.