当前位置: 首页>>代码示例>>Java>>正文


Java Session.setDefaultReadOnly方法代码示例

本文整理汇总了Java中org.hibernate.Session.setDefaultReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Java Session.setDefaultReadOnly方法的具体用法?Java Session.setDefaultReadOnly怎么用?Java Session.setDefaultReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.Session的用法示例。


在下文中一共展示了Session.setDefaultReadOnly方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateDownloadsFromMarket

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public void updateDownloadsFromMarket() {
    Session session = sessions.openSession();
    try {
        session.setDefaultReadOnly(false);
        long allDownloads = 0;
        List<Market> markets = marketDao.list();
        Map<String, Market> marketMap = new HashMap<String, Market>(4, 1);
        for (Market market : markets) {
            long downloads = marketAppDao.countDownloads(session, market.getMarketName());
            // 设置市场的总下载量
            // market.setDownloads(downloads);
            marketDao.update(session, market);
            allDownloads += downloads;
            marketMap.put(market.getMarketName(), market);
        }
        logger.debug("allDownloads: {}", allDownloads);
        session.flush();
        session.clear();
        logger.info("Update market downloads!");
    } finally {
        session.close();
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:25,代码来源:DownloadsUpdateServiceImpl.java

示例2: batchIn1TransactionToApp

import org.hibernate.Session; //导入方法依赖的package包/类
private Transaction batchIn1TransactionToApp(Session session, List<MarketApp> marketApps) {
    Transaction tx = null;
    try {
        session.setDefaultReadOnly(false);
        tx = session.beginTransaction();
        long start = System.currentTimeMillis();
        mergePaginationToApp(session, marketApps);
        session.flush();
        session.clear();
        logger.info("mergePaginationToApp耗时:{}", (System.currentTimeMillis() - start) + " ms!");
        tx.commit();
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        logger.error("Exception", e);
    }
    return tx;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:20,代码来源:MergeServiceImpl.java

示例3: handlePagination

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int handlePagination(UpdateDownloadCallback cb) {
    int effects = 0;
    Session session = sessions.openSession();
    try {
        session.setDefaultReadOnly(false);
        long count = appDao.count(session);
        final int pageSize = AppConfig.BATCH_SIZE_OF_TRANC;
        int totalPage = (int) (count / pageSize + 1);
        int currentPage = 1;
        int index = 0;
        for (; currentPage <= totalPage; currentPage++) {
            List<App> apps = appDao.listForDownloads(session, currentPage, pageSize);
            if (apps == null || apps.isEmpty()) {
                break;
            }
            for (App a : apps) {
                try {
                    effects += cb.doIn(session, a, appDao);
                    if (++index % AppConfig.BATCH_SIZE == 0) {
                        session.flush();
                        session.clear();
                    }
                } catch (Exception e) {
                    session.clear();
                    logger.error("Exception", e);
                }
            }
        }
        session.flush();
        session.clear();
    } finally {
        session.close();
    }
    return effects;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:37,代码来源:DownloadsUpdateServiceImpl.java

示例4: importIncrement

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public void importIncrement() {
    logger.info("{}. ImportIncrement begins...", this.getMarketName());
    Session session = null;
    Transaction tx = null;
    boolean successed = false;
    Date now = new Date();
    do {
        session = sessions.openSession();
        session.setDefaultReadOnly(false);
        try {
            Market market = null;
            try {
                market = getMarket(session);
            } finally {
                session.close();
            }
            int currentPage = 0, totalPage = 0;
            oneIncrement: do {
                PaginationMarketApp increment = getMarketAppForIncrement(market);
                if (increment != null) {
                    currentPage = increment.getCurrentPage();
                    totalPage = increment.getTotalPages();
                    List<MarketApp> marketApps = increment.getData();
                    List<MarketApp> offMarketApps = new ArrayList<MarketApp>();
                    if (marketApps != null && !marketApps.isEmpty()) {
                        // open again
                        if (!session.isOpen()) {
                            session = sessions.openSession();
                        }
                        tx = session.beginTransaction();
                        savePaginationMarketApp(session, market, marketApps, offMarketApps);
                        market.setIncrementLastReqCurrentPage(currentPage);
                        market.setIncrementTotalPages(totalPage);
                        session.merge(market);
                        tx.commit();
                        tx = null;
                        session.close();
                        deleteMarketAppsTransaction(offMarketApps);
                        logger.info(
                                "{}. Increment totalPage: {}\t currentPage: {}\t size: {}\t offMarketApps size: {}",
                                this.getMarketName(), totalPage, currentPage, marketApps.size(),
                                offMarketApps.size());
                        marketApps.clear();
                        offMarketApps.clear();
                    }
                    if (currentPage >= totalPage) {
                        successed = true;
                    }
                } else {
                    successed = false;
                    break oneIncrement;
                }
            } while (totalPage > 0 && currentPage < totalPage);
            if (successed) {
                resetMarketForIncrement(now);
            } else {
                sleepForTry();
            }
        } catch (Exception e) {
            successed = false;
            if (tx != null) {
                tx.rollback();
            }
            logger.error("Exception", e);
            sleepForTry();
        } finally {
            if (session.isOpen()) {
                session.close();
            }
        }
    } while (!successed);
    logger.info("{}. ImportIncrement done!", this.getMarketName());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:75,代码来源:ApiImporterMarketServiceImpl.java

示例5: savePaginationForFull

import org.hibernate.Session; //导入方法依赖的package包/类
private PaginationMarketApp savePaginationForFull() throws Exception {
    // saveOrUpdate to table MarketApp
    PaginationMarketApp marketPagination = null;
    Session session = sessions.openSession();
    session.setDefaultReadOnly(false);
    Transaction tx = null;
    try {
        Market market = getMarket(session);
        marketPagination = getMarketAppForFull(market);
        if (marketPagination != null && marketPagination.getTotalPages() >= marketPagination.getCurrentPage()) {
            List<MarketApp> marketApps = marketPagination.getData();
            List<MarketApp> offMarketApps = new ArrayList<MarketApp>();
            if (marketApps != null && !marketApps.isEmpty()) {
                Object[] infos = new Object[] { market.getMarketName(), marketPagination.getTotalPages(),
                        marketPagination.getCurrentPage(), marketApps.size() };
                accessMarketDao.getMarketlogger().info(
                        "Begin to import {} on one page. totalPages: {} currentPage : {} , size: {}", infos);
                tx = session.beginTransaction();
                savePaginationMarketApp(session, market, marketApps, offMarketApps);
                market.setFullLastReqCurrentPage(marketPagination.getCurrentPage());
                market.setFullTotalPages(marketPagination.getTotalPages());
                market.setFullLastTime(new Date());
                session.merge(market);
                tx.commit();
                tx = null;
                session.clear();
                session.close();
                deleteMarketAppsTransaction(offMarketApps);
                marketApps.clear();
                offMarketApps.clear();
            }
        }
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        logger.error("Exception", e);
        throw e;
    } finally {
        if (session.isOpen()) {
            session.close();
        }
    }
    return marketPagination;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:46,代码来源:ApiImporterMarketServiceImpl.java

示例6: updateAppFromMarketApp

import org.hibernate.Session; //导入方法依赖的package包/类
/**
 * 特殊逻辑处理,处理合作市场
 * 
 * @param forceMerge
 * @param mApp
 * @param session
 * @param now
 * @param updateApp
 */
private void updateAppFromMarketApp(boolean forceMerge, MarketApp mApp, Session session, Date now, App updateApp) {
    // channel apk!!!
    // if (!mApp.getMarketName().equals(updateApp.getMarketName())) {
    // switch (EnumMarket.valueOf(updateApp.getMarketName().toUpperCase()))
    // {
    // case SHOUJIKONG_CHANNEL: {
    // // update appfetchtime
    // mApp.setAppFetchTime(now);
    // marketAppDao.update(session, mApp);
    // return;
    // }
    // default: {
    // break;
    // }
    // }
    // }

    if (appConfig.isUpdateAudit()) {
        if (updateApp.isAudit() && !updateApp.isAutoCover()) {
            // update appfetchtime
            mApp.setAppFetchTime(now);
            marketAppDao.update(session, mApp);
            return;
        }
    }

    Session sessionForSelect = sessions.openSession();
    // marketapp 所属的market
    // 需要更新的app 所属的market
    Market market = null, appWithSignatureOwnerMarket;
    try {
        sessionForSelect.setDefaultReadOnly(true);
        market = marketDao.getByName(sessionForSelect, mApp.getMarketName());
        appWithSignatureOwnerMarket = updateApp.getMarketName().equals(mApp.getMarketName()) ? market : marketDao
                .getByName(sessionForSelect, updateApp.getMarketName());
    } finally {
        sessionForSelect.close();
    }

    // channel apk!!!
    // switch (EnumMarket.valueOf(mApp.getMarketName().toUpperCase())) {
    // case SHOUJIKONG_CHANNEL: {
    // // update appfetchtime
    // forceMerge = true;
    // break;
    // }
    // default: {
    // break;
    // }
    // }

    // 有签名
    if (forceMerge || mergeAppComparator.compare(mApp, updateApp, market, appWithSignatureOwnerMarket) > 0
            || StringUtils.isBlank(updateApp.getSignatureSha1())) {
        updateAppIfNeedUpdate(mApp, market, session, now, updateApp);
    }
    // finally set fetchTime
    // update appfetchtime
    mApp.setAppFetchTime(now);
    marketAppDao.update(session, mApp);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:71,代码来源:MergeServiceImpl.java


注:本文中的org.hibernate.Session.setDefaultReadOnly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。