Example usage for org.apache.ibatis.session SqlSession selectList

List of usage examples for org.apache.ibatis.session SqlSession selectList

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession selectList.

Prototype

<E> List<E> selectList(String statement);

Source Link

Document

Retrieve a list of mapped objects from the statement key and parameter.

Usage

From source file:com.gordcorp.jira2db.persistence.MyBatisDao.java

License:Open Source License

/**
 * Method returns all rows for this object. </br></br> Example: </br> If
 * your DAO object is called CarInfo.java, the corresponding mapper query id
 * should be: &lt;select id="getAllCarInfo" ... </br></br> SQL Executed:
 * select * from [tablename] </br></br> Notes: </br> Consider overdiding
 * this method in order to handle large numbers of objects with multiple
 * references. LAZY LOADING should be enabled in this case, otherwise you
 * might run out of memory (eg. get all UserAccounts if the table has
 * 1,000,000 rows) look into the aggresiveLazyLoading property
 * *///from ww  w  .ja  v a  2s  . c  o  m
@Override
@SuppressWarnings("unchecked")
public List<T> getAll() throws PersistenceException {

    SqlSession session = sf.openSession();
    List<T> list = null;
    try {
        String query = NAMESPACE + "." + PREFIX_SELECT_QUERY + "All" + this.type.getSimpleName();
        list = (List<T>) session.selectList(query);
    } finally {
        session.close();
    }
    return list;
}

From source file:com.inform.project.dao.MyBatisAdminImpl.java

@Override
public List<LoginAuthModel> getList() {
    List<LoginAuthModel> list = null;
    SqlSession session = null;
    try {/*from w  w w  .  j ava2s. c om*/
        session = MyBatisSession.getInst().getSession().openSession();
        list = session.selectList("GetUsersMapper.getList");
    } catch (IOException ex) {
        Logger.getLogger(MyBatisAdminImpl.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return list;
}

From source file:com.inform.project.dao.MyBatisGetCategoryImpl.java

@Override
public List<UserCategoryModel> getListCategory() {
    List<UserCategoryModel> list = null;
    SqlSession session = null;
    try {/*from ww w  . j ava 2s  .co  m*/
        session = MyBatisSession.getInst().getSession().openSession();
        list = session.selectList("GetUsersCategoryMapper.getCategoryList");
    } catch (IOException ex) {
        Logger.getLogger(MyBatisGetEventsImpl.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return list;
}

From source file:com.inform.project.dao.MyBatisGetEventsImpl.java

@Override
public List<UserEventModel> getEvents() {
    List<UserEventModel> list = null;
    SqlSession session = null;
    try {/*from  ww  w. j  av a  2 s.co  m*/
        session = MyBatisSession.getInst().getSession().openSession();
        list = session.selectList("GetEventsMapper.getEventsList");
    } catch (IOException ex) {
        Logger.getLogger(MyBatisGetEventsImpl.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return list;
}

From source file:com.inform.project.dao.MyBatisGetLocationImpl.java

@Override
public List<UserLocationModel> getListLocation() {
    List<UserLocationModel> list = null;
    SqlSession session = null;
    try {/*w ww . j a va  2s  .co m*/
        session = MyBatisSession.getInst().getSession().openSession();
        list = session.selectList("GetUsersLocationMapper.getLocationList");
    } catch (IOException ex) {
        Logger.getLogger(MyBatisGetEventsImpl.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return list;
}

From source file:com.inform.project.dao.MyBatisGetSellsImpl.java

@Override
public List<UserSellsModel> getListSells() {
    List<UserSellsModel> list = null;
    SqlSession session = null;
    try {//  w  w w  .  ja v  a  2 s .  co  m
        session = MyBatisSession.getInst().getSession().openSession();
        list = session.selectList("GetUsersSellsMapper.getSellsList");
    } catch (IOException ex) {
        Logger.getLogger(MyBatisGetEventsImpl.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return list;
}

From source file:com.luxoft.mybatis.splitter.UpdateSplitterPluginTest.java

License:Apache License

public void splitterTest(ExecutorType execType) throws IOException, SQLException {
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
            .build(Resources.getResourceAsStream("configuration.xml"));
    SqlSession sqlSession = sqlSessionFactory.openSession(execType);
    sqlSession.insert("makeTable");
    sqlSession.flushStatements();/*  w  w w .ja v a 2 s  . c om*/
    doInsert(sqlSession);
    Assert.assertEquals(Arrays.asList("first", "second", "third"), sqlSession.selectList("get"));
    sqlSession.insert("dropTable");
    sqlSession.flushStatements();
    sqlSession.close();
}

From source file:com.moma.db.FinalBilling.java

public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
    String resource = "com/moma/db/dbconf.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession sqlSession = sqlSessionFactory.openSession();

    List<ProductMapDO> productMapList = sqlSession.selectList("selectProductMapAll");
    Map<String, ProductMapDO> productMap = new HashMap<>();
    for (ProductMapDO productMapDO : productMapList) {
        productMap.put(productMapDO.getName(), productMapDO);
    }/* w  w w. j  a  v  a2 s .c o m*/

    List<ActualDO> actualList = sqlSession.selectList("selectActualByQuarter", "FY17");
    FinalBillingRow prevFirstRow = null;

    ArrayList<FinalBillingRow> result = new ArrayList<>();
    System.out.println("actual size : " + actualList.size());
    int x = -1;
    for (ActualDO actual : actualList) {
        x++;

        FinalBillingRow row = new FinalBillingRow();

        /* from actual */
        row.setWeek(actual.getWeek());
        row.setQuarter(actual.getQuarter());
        row.setMonth(actual.getMonth());
        row.setSerialNumber(actual.getSn());
        row.setPo(actual.getPo());
        row.setProgram(actual.getProgram());
        row.setLeadSource(actual.getLeadsource());
        row.setPartner(actual.getPartner());
        row.setLeadSourceName(actual.getLeadsourcename());
        row.setFullfillmentChannel(actual.getFullfillmentchannel());
        row.setProgramAPAC(actual.getProgram());

        result.add(row);

        /* from cleardb */
        List<ClearDBDO> clearDB = sqlSession.selectList("selectClearDBBySN", actual.getSn());
        if (clearDB.size() == 0) {
            System.out.println("invalid SN = " + actual.getSn());
            continue;
        }
        System.out.println("cleardb size : " + clearDB.size());

        ClearDBDO cdbo = clearDB.get(0);

        if (prevFirstRow != null) {
            if (!prevFirstRow.getPo().equals(row.getPo())) {
                prevFirstRow = row;
            } else {
                row.copy(prevFirstRow);
                prevFirstRow.setQuantity(prevFirstRow.getQuantity() + cdbo.getNoofseats());
                continue;
            }
        } else {
            prevFirstRow = row;
        }

        row.setCompanyName(cdbo.getEnduseraccountname());
        row.setCity(cdbo.getCity());
        if (cdbo.getLicensemodel().equalsIgnoreCase("TERM"))
            row.setLicenseType("DTS");
        else
            row.setLicenseType(cdbo.getLicensetype());
        if (cdbo.getDeploymenttype().equalsIgnoreCase("Standalone"))
            row.setDeployment("SLM");
        else
            row.setDeployment("NLM");
        row.setQuantity(cdbo.getNoofseats());
        ProductMapDO pd = productMap.get(cdbo.getProductline());
        row.setProduct(pd.getName());
        row.setDivision(pd.getDivision());
        row.setSuite(pd.getSuite());

        /* from sapdb */
        long productTotal = 0;
        long subTotal = 0;

        boolean isTermBndl = false;
        List<SapDBDO> sapDB = sqlSession.selectList("selectSapDBByPO", actual.getPo());
        System.out.println("sapdb size : " + sapDB.size() + ", po = " + actual.getPo());

        for (SapDBDO sapDBDO : sapDB) {
            if (sapDBDO.getMaterialgroup().equalsIgnoreCase("TERM_BNDL"))
                isTermBndl = true;
        }

        for (SapDBDO sapDBDO : sapDB) {
            if (sapDBDO.getMaterialgroup().equalsIgnoreCase("TERM_BNDL")) {
                subTotal += sapDBDO.getItemnetvalue();
            } else if (!isTermBndl && sapDBDO.getMaterialgroup().equalsIgnoreCase("TERM_LIC")) {

            } else if (!isTermBndl && sapDBDO.getMaterialgroup().equalsIgnoreCase("SUBSCRPTN")) {
                subTotal += sapDBDO.getItemnetvalue();
            } else if (sapDBDO.getMaterialgroup().equalsIgnoreCase("LICENSE")) {
                productTotal += sapDBDO.getItemnetvalue();
            }
        }

        row.setProductTotal(productTotal);
        row.setSubTotal(subTotal);
        if (subTotal > 0) {
            row.setSub("Y");
        } else {
            row.setSub("N");
        }

        row.setTotalBilling(row.getProductTotal() + row.getSubTotal());
        row.setLegalization(row.getTotalBilling());

        System.out.println("progress" + x);

    }

    for (FinalBillingRow row : result) {
        System.out.println(row);
    }
}

From source file:com.onnurimotors.wm.service.WmService.java

public Object getAlerts(Model model) {
    SqlSession session = sqlSession();
    ArrayList<ALERT> alerts = new ArrayList<ALERT>();
    ALERT alert;//from w ww .  jav a  2s.  c o m
    VEHICLE_HISTORY vh = new VEHICLE_HISTORY();
    long diff;
    Date date = new Date();
    DateFormat format_datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    ArrayList<VEHICLE_HISTORY> vhs = (ArrayList<VEHICLE_HISTORY>) session
            .selectList("watchman.mybatis.selectRecentHistoryVehicle");

    try {
        for (int i = 0; i < vhs.size(); i++) {
            alert = new ALERT();
            vh = vhs.get(i);
            String datetime_str = vh.getDATE_VISIT() + " " + vh.getTIME_VISIT();
            diff = (date.getTime() - format_datetime.parse(datetime_str).getTime()) / 1000;
            if (diff > 60) {
                diff = diff / 60;
                if (diff > 60) {
                    diff = diff / 60;
                    alert.setTIME_PASSED(diff + " ");
                } else {
                    alert.setTIME_PASSED(diff + " ");
                }
            } else {
                alert.setTIME_PASSED(diff + " ");
            }
            alert.setLICENSE(vh.getLICENSE());
            alerts.add(alert);
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    if (model != null) {
        model.addAttribute("alerts", alerts);
    }

    session.close();

    return alerts;
}

From source file:com.osc.edu.chapter2.Starter.java

License:Open Source License

/**
 * <pre>//from  w  ww.  ja va 2  s . c o  m
 *  ?  samples/commons/db_configuration/build.xml ?? test-db-start, initializeData Task  .
 * </pre>
 * @param args
 */
public static void main(String[] args) {
    SqlSession session = SqlSessionFactoryManager.getSqlSession();

    List<CustomersDto> customersList = null;
    List<EmployeesDto> employeesList = null;

    logger.debug("Invoke query using Mapper XML.");

    // (xml) mapper ?? namespace, id ?  
    customersList = session.selectList("com.osc.edu.commons.customers.mapper.CustomersMapper.getCustomersList");
    employeesList = session.selectList("com.osc.edu.commons.employees.mapper.EmployeesMapper.getEmployeesList");

    logger.debug("customersList's size : {}", customersList.size());
    logger.debug("employeesList's size : {}", employeesList.size());

    // Mapper ?? ?  
    CustomersMapper customersMapper = session.getMapper(CustomersMapper.class);
    EmployeesMapper employeesMapper = session.getMapper(EmployeesMapper.class);

    //  ? ? ?  ?? .
    customersMapper.deleteCustomers(103);
    employeesMapper.deleteEmployees(1002);

    customersList = customersMapper.getCustomersList();
    employeesList = employeesMapper.getEmployeesList();

    logger.debug("customersList's size : {}", customersList.size());
    logger.debug("employeesList's size : {}", employeesList.size());

    session.close();
}