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

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


        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            Query q;
            QueryGenerator generator;
            List results;
            switch (type) {
                case ERROR_DETAIL:
                    generator = new QueryGenerator(ERROR_DETAIL);
                    generator.setParameter(ErrorDetailConstants.TASK_ID, taskId);
                    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 APPLICATION_INPUT:
                    generator = new QueryGenerator(APPLICATION_INPUT);
                    generator.setParameter(ApplicationInputConstants.TASK_ID, taskId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            ApplicationInput applicationInput = (ApplicationInput) result;
                            ApplicationInputResource inputResource =
                                    (ApplicationInputResource) Utils.getResource(ResourceType.APPLICATION_INPUT, applicationInput);
                            resourceList.add(inputResource);
                        }
                    }
                    break;
                case APPLICATION_OUTPUT:
                    generator = new QueryGenerator(APPLICATION_OUTPUT);
                    generator.setParameter(ApplicationOutputConstants.TASK_ID, taskId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            ApplicationOutput applicationOutput = (ApplicationOutput) result;
                            ApplicationOutputResource outputResource =
                                    (ApplicationOutputResource) Utils.getResource(ResourceType.APPLICATION_OUTPUT, applicationOutput);
                            resourceList.add(outputResource);
                        }
                    }
                    break;
                case JOB_DETAIL:
                    generator = new QueryGenerator(JOB_DETAIL);
                    generator.setParameter(JobDetailConstants.TASK_ID, taskId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            JobDetail jobDetail = (JobDetail) result;
                            JobDetailResource jobDetailResource =
                                    (JobDetailResource) Utils.getResource(ResourceType.JOB_DETAIL, jobDetail);
                            resourceList.add(jobDetailResource);
                        }
                    }
                    break;
                case DATA_TRANSFER_DETAIL:
                    generator = new QueryGenerator(DATA_TRANSFER_DETAIL);
                    generator.setParameter(DataTransferDetailConstants.TASK_ID, taskId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            DataTransferDetail transferDetail = (DataTransferDetail) result;
                            DataTransferDetailResource transferDetailResource =
                                    (DataTransferDetailResource) Utils.getResource(ResourceType.DATA_TRANSFER_DETAIL, transferDetail);
                            resourceList.add(transferDetailResource);
                        }
                    }
                    break;
                case STATUS:
                    generator = new QueryGenerator(STATUS);
                    generator.setParameter(StatusConstants.TASK_ID, taskId);
                    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 {
            if (type == ResourceType.APPLICATION_DESCRIPTOR) {
                em = ResourceUtils.getEntityManager();
                em.getTransaction().begin();
                QueryGenerator queryGenerator = new QueryGenerator(APPLICATION_DESCRIPTOR);
                queryGenerator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
                queryGenerator.setParameter(ApplicationDescriptorConstants.SERVICE_DESC_ID, serviceDescName);
                Query q = queryGenerator.selectQuery(em);
                List results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        Application_Descriptor applicationDescriptor = (Application_Descriptor) result;
                        ApplicationDescriptorResource applicationDescriptorResource = (ApplicationDescriptorResource) Utils.getResource(ResourceType.APPLICATION_DESCRIPTOR, applicationDescriptor);
View Full Code Here

        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            Query q;
            QueryGenerator generator;
            switch (type) {
                case STATUS:
                    generator = new QueryGenerator(STATUS);
                    generator.setParameter(StatusConstants.JOB_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                case ERROR_DETAIL:
                    generator = new QueryGenerator(STATUS);
                    generator.setParameter(ErrorDetailConstants.JOB_ID, name);
                    q = generator.deleteQuery(em);
                    q.executeUpdate();
                    break;
                default:
                    logger.error("Unsupported resource type for job details 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 STATUS:
                    generator = new QueryGenerator(STATUS);
                    generator.setParameter(StatusConstants.JOB_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 ERROR_DETAIL:
                    generator = new QueryGenerator(ERROR_DETAIL);
                    generator.setParameter(ErrorDetailConstants.JOB_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;
View Full Code Here

        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            Query q;
            QueryGenerator generator;
            List results;
            switch (type) {
                case STATUS:
                    generator = new QueryGenerator(STATUS);
                    generator.setParameter(StatusConstants.JOB_ID, jobId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            Status status = (Status) result;
                            StatusResource statusResource =
                                    (StatusResource) Utils.getResource(ResourceType.STATUS, status);
                            resourceList.add(statusResource);
                        }
                    }
                    break;
                case ERROR_DETAIL:
                    generator = new QueryGenerator(ERROR_DETAIL);
                    generator.setParameter(ErrorDetailConstants.JOB_ID, jobId);
                    q = generator.selectQuery(em);
                    results = q.getResultList();
                    if (results.size() != 0) {
                        for (Object result : results) {
                            ErrorDetail errorDetail = (ErrorDetail) result;
                            ErrorDetailResource errorDetailResource =
View Full Code Here

        EntityManager em = null;
        try {
            em = ResourceUtils.getEntityManager();
            em.getTransaction().begin();
            if (type == ResourceType.EXPERIMENT) {
                QueryGenerator generator = new QueryGenerator(EXPERIMENT);
                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
                Query q = generator.deleteQuery(em);
                q.executeUpdate();
            } else if (type == ResourceType.PROJECT_USER) {
                QueryGenerator generator = new QueryGenerator(PROJECT_USER);
                generator.setParameter(ProjectUserConstants.USERNAME, name);
                generator.setParameter(ProjectUserConstants.PROJECT_ID, this.id);
                Query q = generator.deleteQuery(em);
                q.executeUpdate();
            } else {
                logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for project resource.");
            }
View Full Code Here

        EntityManager em = null;
        try {
            if (type == ResourceType.EXPERIMENT) {
                em = ResourceUtils.getEntityManager();
                em.getTransaction().begin();
                QueryGenerator generator = new QueryGenerator(EXPERIMENT);
                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
                Query q = generator.selectQuery(em);
                Experiment experiment = (Experiment) q.getSingleResult();
                ExperimentResource experimentResource = (ExperimentResource)
                        Utils.getResource(ResourceType.EXPERIMENT, experiment);
                em.getTransaction().commit();
                em.close();
                return experimentResource;
            } else if (type == ResourceType.PROJECT_USER) {
                em = ResourceUtils.getEntityManager();
                em.getTransaction().begin();
                QueryGenerator generator = new QueryGenerator(PROJECT_USER);
                generator.setParameter(ProjectUserConstants.USERNAME, name);
                generator.setParameter(ProjectUserConstants.PROJECT_ID, this.id);
                Query q = generator.selectQuery(em);
                ProjectUser prUser = (ProjectUser) q.getSingleResult();
                ExperimentResource experimentResource = (ExperimentResource)
                        Utils.getResource(ResourceType.PROJECT_USER, prUser);
                em.getTransaction().commit();
                em.close();
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.