⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicregionadapter.java

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public void ensureRegionRootExists() {              if (regionRoot == null || !regionRoot.isValid())          establishRegionRootNode();              // Fix up the resident flag       if (regionRoot != null && regionRoot.isValid() && !regionRoot.isResident())          regionRoot.setResident(true);    }    public void destroy() throws CacheException {        try {            // NOTE : this is being used from the process of shutting down a            // SessionFactory. Specific things to consider:            // (1) this clearing of the region should not propagate to            // other nodes on the cluster (if any); this is the            // cache-mode-local option bit...            // (2) really just trying a best effort to cleanup after            // ourselves; lock failures, etc are not critical here;            // this is the fail-silently option bit...            Option option = new Option();            option.setCacheModeLocal(true);            option.setFailSilently(true);            if (optimistic) {                option.setDataVersion(NonLockingDataVersion.INSTANCE);            }            jbcCache.getInvocationContext().setOptionOverrides(option);            jbcCache.removeNode(regionFqn);            deactivateLocalNode();                    } catch (Exception e) {            throw new CacheException(e);        }//        finally {//            if (listener != null)//                jbcCache.removeCacheListener(listener);//        }    }    protected void deactivateLocalNode() {        org.jboss.cache.Region jbcRegion = jbcCache.getRegion(regionFqn, false);        if (jbcRegion != null && jbcRegion.isActive()) {            jbcRegion.deactivate();            jbcRegion.unregisterContextClassLoader();        }    }    public long getSizeInMemory() {        // not supported        return -1;    }    public long getElementCountInMemory() {        try {            Set childrenNames = CacheHelper.getChildrenNames(jbcCache, regionFqn);            return childrenNames.size();        } catch (Exception e) {            throw new CacheException(e);        }    }    public long getElementCountOnDisk() {        return -1;    }    public Map toMap() {        try {            Map result = new HashMap();            Set childrenNames = CacheHelper.getChildrenNames(jbcCache, regionFqn);            for (Object childName : childrenNames) {                result.put(childName, CacheHelper.get(jbcCache,regionFqn, childName));            }            return result;        } catch (CacheException e) {            throw e;        } catch (Exception e) {            throw new CacheException(e);        }    }    public long nextTimestamp() {        return System.currentTimeMillis() / 100;    }    public int getTimeout() {        return 600; // 60 seconds    }    /**     * Performs a JBoss Cache <code>get(Fqn, Object)</code> after first     * {@link #suspend suspending any ongoing transaction}. Wraps any exception     * in a {@link CacheException}. Ensures any ongoing transaction is resumed.     *      * @param key The key of the item to get     * @param opt any option to add to the get invocation. May be <code>null</code>     * @param suppressTimeout should any TimeoutException be suppressed?     * @return The retrieved object	 * @throws CacheException issue managing transaction or talking to cache     */    protected Object suspendAndGet(Object key, Option opt, boolean suppressTimeout) throws CacheException {        Transaction tx = suspend();        try {            CacheHelper.setInvocationOption(getCacheInstance(), opt);            if (suppressTimeout)                return CacheHelper.getAllowingTimeout(getCacheInstance(), getRegionFqn(), key);            else                return CacheHelper.get(getCacheInstance(), getRegionFqn(), key);        } finally {            resume(tx);        }    }    /**     * Tell the TransactionManager to suspend any ongoing transaction.     *      * @return the transaction that was suspended, or <code>null</code> if     *         there wasn't one     */    protected Transaction suspend() {        Transaction tx = null;        try {            if (transactionManager != null) {                tx = transactionManager.suspend();            }        } catch (SystemException se) {            throw new CacheException("Could not suspend transaction", se);        }        return tx;    }    /**     * Tell the TransactionManager to resume the given transaction     *      * @param tx     *            the transaction to suspend. May be <code>null</code>.     */    protected void resume(Transaction tx) {        try {            if (tx != null)                transactionManager.resume(tx);        } catch (Exception e) {            throw new CacheException("Could not resume transaction", e);        }    }    /**     * Get an Option with a {@link Option#getDataVersion() data version}     * of {@link NonLockingDataVersion}.  The data version will not be      * set if the cache is not configured for optimistic locking.     *      * @param allowNullReturn If <code>true</code>, return <code>null</code>     *                        if the cache is not using optimistic locking.     *                        If <code>false</code>, return a default     *                        {@link Option}.     *                             * @return the Option, or <code>null</code>.     */    protected Option getNonLockingDataVersionOption(boolean allowNullReturn) {        return optimistic ? NonLockingDataVersion.getInvocationOption()                           : (allowNullReturn) ? null : new Option();    }    public static Fqn<String> getTypeFirstRegionFqn(String regionName, String regionPrefix, String regionType) {        Fqn<String> base = Fqn.fromString(regionType);        Fqn<String> added = Fqn.fromString(escapeRegionName(regionName, regionPrefix));        return new Fqn<String>(base, added);    }    public static Fqn<String> getTypeLastRegionFqn(String regionName, String regionPrefix, String regionType) {        Fqn<String> base = Fqn.fromString(escapeRegionName(regionName, regionPrefix));        return new Fqn<String>(base, regionType);    }    public static String escapeRegionName(String regionName, String regionPrefix) {        String escaped = null;        int idx = -1;        if (regionPrefix != null) {            idx = regionName.indexOf(regionPrefix);        }        if (idx > -1) {            int regionEnd = idx + regionPrefix.length();            String prefix = regionName.substring(0, regionEnd);            String suffix = regionName.substring(regionEnd);            suffix = suffix.replace('.', '/');            escaped = prefix + suffix;        } else {            escaped = regionName.replace('.', '/');            if (regionPrefix != null && regionPrefix.length() > 0) {                escaped = regionPrefix + "/" + escaped;            }        }        return escaped;    }    //    @CacheListener//    public class RegionRootListener {//        //        @NodeCreated//        public void nodeCreated(NodeCreatedEvent event) {//            if (!event.isPre() && event.getFqn().equals(getRegionFqn())) {//                log.debug("Node created for " + getRegionFqn());//                Node regionRoot = jbcCache.getRoot().getChild(getRegionFqn());//                regionRoot.setResident(true);//            }//        }//        //    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -