com.registryKit.importTool.importDAO.java Source code

Java tutorial

Introduction

Here is the source code for com.registryKit.importTool.importDAO.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.registryKit.importTool;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author chadmccue
 */
@Repository
public class importDAO {

    @Autowired
    private SessionFactory sessionFactory;

    /**
     * The 'getUploadTypes' function will return a list of upload types set up for the program.
     * 
     * @return The function will return a list of upload types in the system
     */
    public List<programImportTypes> getImportTypes(Integer programId) throws Exception {

        String sqlQuery = "select a.id, a.programId, a.name, a.dateCreated, a.status, a.useMCI, count(b.id) as totalFields from programUploadTypes a inner join programUploadType_formFields b on a.id = b.programUploadTypeId where "
                + "a.programId = " + programId + " and a.status = 1 group by b.programUploadTypeId";

        Query query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery)
                .setResultTransformer(Transformers.aliasToBean(programImportTypes.class));

        return query.list();
    }

    /**
     * The 'getImportTypeById' function will return the details for the clicked import type.
     * 
     * @param importTypeId The id of the selected import type.
     * @return
     * @throws Exception 
     */
    public programImportTypes getImportTypeById(Integer importTypeId) throws Exception {
        return (programImportTypes) sessionFactory.getCurrentSession().get(programImportTypes.class, importTypeId);
    }

    /**
     * The 'getImportTypeFields' function will return the fields associated the passed in upload type.
     * 
     * @param uploadTypeId  The id of the clicked upload type
     * @return
     * @throws Exception 
     */
    public List<programImportTypeFields> getImportTypeFields(Integer importTypeId) throws Exception {
        Query query = sessionFactory.getCurrentSession().createQuery(
                "from programImportTypeFields where programUploadTypeId = :importTypeId order by dspPos asc");
        query.setParameter("importTypeId", importTypeId);

        return query.list();
    }

    /**
     * The 'programImport' function will submit the new import.
     * 
     * @param programImport The object containing the new import.
     * @return This function will return the latest Id assigned to the import.
     * @throws Exception 
     */
    public Integer submitImport(programImports programImport) throws Exception {
        Integer lastId = null;

        lastId = (Integer) sessionFactory.getCurrentSession().save(programImport);

        return lastId;
    }

    /**
     * The 'submitImportRecords' function will submit the new import records.
     * 
     * @param records The object containing the new import records.
     * @throws Exception 
     */
    public void submitImportRecords(programImportRecords records) throws Exception {
        sessionFactory.getCurrentSession().save(records);
    }

    /**
     * The 'getImportDetails' function will get the details of the import.
     * 
     * @param importId The id of the import to pass in.
     * @return 
     */
    public programImports getImportDetails(Integer importId) {
        return (programImports) sessionFactory.getCurrentSession().get(programImports.class, importId);
    }

    /**
     * The 'getImportRecords' function will return the records for the passed in importId.
     * 
     * @param importId  The id of the import
     * 
     * @return This function will return a list of records
     */
    public List getImportRecords(Integer importId) {

        Query query = sessionFactory.getCurrentSession().createSQLQuery(
                "SELECT f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31,"
                        + "f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62, f63, f64,"
                        + "f65, f66, f67, f68, f69, f70, f71, f72, f73, f74, f75, f76, f77, f78, f79, f80, f81, f82, f83, f84, f85, f86, f87, f88, f89, f90, f91, f92, f93, f94, f95, f96, f97, f98,"
                        + "f99, f100, f101, f102, f103, f104, f105, f106, f107, f108, f109, f110, f111, f112, f113, f114, f115, f116, f117, f118, f119, f120, f121, f122, f123, f124, f125, f126, f127, f128, f129,"
                        + "f130, f131, f132, f133, f134, f135, f136, f137, f138, f139, f140, f141, f142, f143, f144, f145, f146, f147, f148, f149, f150, f151, f152, f153, f154, f155, f156, f157, f158, f159,"
                        + "f160, f161, f162, f163, f164, f165, f166, f167, f168, f169, f170, f171, f172, f173, f174, f175, f176, f177, f178, f179, f180, f181, f182, f183, f184, f185, f186, f187, f188, f189,"
                        + "f190, f191, f192, f193, f194, f195, f196, f197, f198, f199, f200, f201, f202, f203, f204, f205, f206, f207, f208, f209, f210, f211, f212, f213, f214, f215, f216, f217, f218, f219,"
                        + "f220, f221, f222, f223, f224, f225, f226, f227, f228, f229, f230, f231, f232, f233, f234, f235, f236, f237, f238, f239, f240, f241, f242, f243, f244, f245, f246, f247, f248, f249,"
                        + "f250, f251, f252, f253, f254, f255, F256,F257,F258,F259,F260,F261,F262,F263,F264,F265,F266,F267,F268,F269,F270,F271,F272,F273,F274,F275,F276,F277,F278,F279,F280,F281,F282,F283,F284,F285,F286,F287,F288,F289,"
                        + "F290,F291,F292,F293,F294,F295,F296,F297,F298,F299,F300,F301,F302,F303,F304,F305,F306,F307,F308,F309,F310,F311,F312,F313,F314,F315,F316,F317,F318,F319,F320,F321,F322,F323,F324,F325,F326,F327,F328,F329,F330,"
                        + "F331,F332,F333,F334,F335,F336,F337,F338,F339,F340,F341,F342,F343,F344,F345,F346,F347,F348,F349,F350,F351,F352,F353,F354,F355,F356,F357,F358,F359,F360,F361,F362,F363,F364,F365,F366,F367,F368,F369,F370,F371,"
                        + "F372,F373,F374,F375,F376,F377,F378,F379,F380,F381,F382,F383,F384,F385,F386,F387,F388,F389,F390,F391,F392,F393,F394,F395,F396,F397,F398,F399,F400,F401,F402,F403,F404,F405,F406,F407,F408,F409,F410,F411,F412,"
                        + "F413,F414,F415,F416,F417,F418,F419,F420,F421,F422,F423,F424,F425,F426,F427,F428,F429,F430,F431,F432,F433,F434,F435,F436,F437,F438,F439,F440,F441,F442,F443,F444,F445,F446,F447,F448,F449,F450,F451,F452,F453,"
                        + "F454,F455,F456,F457,F458,F459,F460,F461,F462,F463,F464,F465,F466,F467,F468,F469,F470,F471,F472,F473,F474,F475,F476,F477,F478,F479,F480,F481,F482,F483,F484,F485,F486,F487,F488,F489,F490,F491,F492,F493,F494,"
                        + "F495,F496,F497,F498,F499,F500 "
                        + "FROM programUploadRecords where programUploadId = :importId");

        query.setParameter("importId", importId);

        return query.list();

    }

}