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

📄 rdbmportletpreferencesstore.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            try {                final LinkedList prefIds = new LinkedList();                                    selectPrefIdsPstmt = con.prepareStatement(selectPrefIds);                deletePrefValuesPstmt = con.prepareStatement(deletePrefValues);                deletePrefNamesPstmt = con.prepareStatement(deletePrefNames);                insertPrefNamePstmt = con.prepareStatement(insertPrefName);                insertPrefValuePstmt = con.prepareStatement(insertPrefValue);                                //Get a list of all the preference names for this instance of this portlet                log.debug("RDBMPortletPreferencesStore::setEntityPreferences(): " + selectPrefIds);                selectPrefIdsPstmt.setInt(1, userId);                selectPrefIdsPstmt.setInt(2, layoutId);                selectPrefIdsPstmt.setString(3, chanDescId);                ResultSet rs = selectPrefIdsPstmt.executeQuery();                                //Go through and remove all the values. Catalog the removed pref_id's so they can be re-used so                //the counter doesn't have to get hammered as much                try {                    while (rs.next()) {                        int prefId = rs.getInt("PREF_ID");                        prefIds.add(new Integer(prefId));                                                log.debug("RDBMPortletPreferencesStore::setEntityPreferences(PREF_ID=" + prefId + "): " + deletePrefValues);                        deletePrefValuesPstmt.setInt(1, prefId);                        deletePrefValuesPstmt.executeUpdate();                    }                }                finally {                    try { rs.close(); } catch (Exception e) { };                }                                //Delete all the preference names for this instance of this portlet                log.debug("RDBMPortletPreferencesStore::setEntityPreferences(): " + deletePrefNames);                deletePrefNamesPstmt.setInt(1, userId);                deletePrefNamesPstmt.setInt(2, layoutId);                deletePrefNamesPstmt.setString(3, chanDescId);                deletePrefNamesPstmt.executeUpdate();                                //Loop through the prefs, inserting each name then the values                for (Iterator prefItr = prefs.iterator(); prefItr.hasNext();) {                    final Preference pref = (Preference)prefItr.next();                    int prefId = -1;                                        insertPrefNamePstmt.setInt(1, userId);                    insertPrefNamePstmt.setInt(2, layoutId);                    insertPrefNamePstmt.setString(3, chanDescId);                    insertPrefNamePstmt.setString(4, pref.getName());                                        //Use the list of removed ids to re-use IDs before generating new ones                    if (prefIds.size() > 0) {                        prefId = ((Integer)prefIds.removeLast()).intValue();                    }                    else {                        final ICounterStore counterStore = CounterStoreFactory.getCounterStoreImpl();                                                try {                            prefId = counterStore.getIncrementIntegerId(UP_PORTLET_PREFERENCE_VALUE);                        }                        catch (Exception e) {                            counterStore.createCounter(UP_PORTLET_PREFERENCE_VALUE);                            prefId = counterStore.getIncrementIntegerId(UP_PORTLET_PREFERENCE_VALUE);                        }                    }                                        insertPrefNamePstmt.setInt(5, prefId);                                        //Insert the name row                    log.debug("RDBMPortletPreferencesStore::setEntityPreferences(): " + insertPrefName);                    insertPrefNamePstmt.executeUpdate();                                        //For each value a row will be inserted in the values table                    for (final Iterator valueItr = pref.getValues(); valueItr.hasNext();) {                        String value = (String)valueItr.next();                        log.debug("RDBMPortletPreferencesStore::setEntityPreferences(): " + insertPrefValue);                        insertPrefValuePstmt.setInt(1, prefId);                        insertPrefValuePstmt.setString(2, value);                        insertPrefValuePstmt.executeUpdate();                    }                }                if (RDBMServices.supportsTransactions)                    RDBMServices.commit(con);            }            catch (Exception e) {                // Roll back the transaction                if (RDBMServices.supportsTransactions)                    RDBMServices.rollback(con);                throw e;            }            finally {                try { selectPrefIdsPstmt.close(); } catch (Exception e) { }                try { deletePrefValuesPstmt.close(); } catch (Exception e) { }                try { deletePrefNamesPstmt.close(); } catch (Exception e) { }                try { insertPrefNamePstmt.close(); } catch (Exception e) { }                try { insertPrefValuePstmt.close(); } catch (Exception e) { }            }        }        finally {            RDBMServices.releaseConnection(con);        }    }    /**     * @see org.jasig.portal.IPortletPreferencesStore#getEntityPreferences(int, int, java.lang.String)     */    public PreferenceSet getEntityPreferences(final int userId, final int layoutId, final String chanDescId) throws Exception {        final PreferenceSetImpl prefs = new PreferenceSetImpl();        final Connection con = RDBMServices.getConnection();        final String selectPrefs =             "SELECT UPEP.PORTLET_PREF_NAME, UPPV.PORTLET_PREF_VALUE " +            "FROM UP_PORTLET_ENTITY_PREFS UPEP, UP_PORTLET_PREF_VALUES UPPV " +            "WHERE UPEP.PREF_ID=UPPV.PREF_ID AND UPEP.USER_ID=? AND UPEP.LAYOUT_ID=? AND UPEP.CHAN_DESC_ID=?";        log.debug("RDBMPortletPreferencesStore::getEntityPreferences(userId=" + userId + ", layoutId=" + layoutId + ", chanDescId=" + chanDescId + ")");        try {            PreparedStatement selectCurrentPrefsPstmt = null;                        try {                selectCurrentPrefsPstmt = con.prepareStatement(selectPrefs);                                log.debug("RDBMPortletPreferencesStore::getEntityPreferences(): " + selectPrefs);                                selectCurrentPrefsPstmt.setInt(1, userId);                selectCurrentPrefsPstmt.setInt(2, layoutId);                selectCurrentPrefsPstmt.setString(3, chanDescId);                ResultSet rs = selectCurrentPrefsPstmt.executeQuery();                                final Map prefsBuilder = new HashMap();                                try {                    while (rs.next()) {                        final String prefName = rs.getString("PORTLET_PREF_NAME");                        final String prefValue = rs.getString("PORTLET_PREF_VALUE");                                                                        List prefList = (List)prefsBuilder.get(prefName);                                                if (prefList == null)                        {                            prefList = new LinkedList();                            prefsBuilder.put(prefName, prefList);                        }                                                prefList.add(prefValue);                    }                }                finally {                    try { rs.close(); } catch (Exception e) { }                }                                for (final Iterator prefKeyItr = prefsBuilder.keySet().iterator(); prefKeyItr.hasNext();) {                    final String prefName = (String)prefKeyItr.next();                    final List prefValues = (List)prefsBuilder.get(prefName);                                        prefs.add(prefName, prefValues);                }            }            finally {                try { selectCurrentPrefsPstmt.close(); } catch (Exception e) { }            }        }        finally {            RDBMServices.releaseConnection(con);        }                return prefs;    }        /**     * @see org.jasig.portal.IPortletPreferencesStore#deletePortletPreferencesByUser(int)     */    public void deletePortletPreferencesByUser(int userId) throws Exception {        final Connection con = RDBMServices.getConnection();                final String selectPrefIds =             "SELECT PREF_ID " +            "FROM UP_PORTLET_ENTITY_PREFS " +            "WHERE USER_ID=?";                final String deletePrefNames =             "DELETE FROM UP_PORTLET_ENTITY_PREFS " +            "WHERE USER_ID=?";                final String deletePrefValues =             "DELETE FROM UP_PORTLET_PREF_VALUES " +            "WHERE PREF_ID=?";                log.debug("RDBMPortletPreferencesStore::deletePortletPreferencesByUser(userId=" + userId + ")");        try {            // Set autocommit false for the connection            if (RDBMServices.supportsTransactions)                RDBMServices.setAutoCommit(con, false);            PreparedStatement selectPrefIdsPstmt = null;            PreparedStatement deletePrefNamesPstmt = null;            PreparedStatement deletePrefValuesPstmt = null;            try {                selectPrefIdsPstmt = con.prepareStatement(selectPrefIds);                deletePrefNamesPstmt = con.prepareStatement(deletePrefNames);                deletePrefValuesPstmt = con.prepareStatement(deletePrefValues);                log.debug("RDBMPortletPreferencesStore::deletePortletPreferencesByUser(): " + selectPrefIds);                selectPrefIdsPstmt.setInt(1, userId);                ResultSet rs = selectPrefIdsPstmt.executeQuery();                                try {                    while (rs.next()) {                        int prefId = rs.getInt("PREF_ID");                                                log.debug("RDBMPortletPreferencesStore::deletePortletPreferencesByUser(): " + deletePrefValues);                        deletePrefValuesPstmt.setInt(1, prefId);                        deletePrefValuesPstmt.executeUpdate();                    }                }                finally {                    try { rs.close(); } catch (Exception e) { }                }                                deletePrefNamesPstmt.setInt(1, userId);                deletePrefNamesPstmt.executeUpdate();                if (RDBMServices.supportsTransactions)                    RDBMServices.commit(con);            }            catch (Exception e) {                // Roll back the transaction                if (RDBMServices.supportsTransactions)                    RDBMServices.rollback(con);                throw e;            }            finally {                try { selectPrefIdsPstmt.close(); } catch (Exception e) { }                try { deletePrefNamesPstmt.close(); } catch (Exception e) { }                try { deletePrefValuesPstmt.close(); } catch (Exception e) { }            }        }        finally {            RDBMServices.releaseConnection(con);        }    }        /**     * @see org.jasig.portal.IPortletPreferencesStore#deletePortletPreferencesByInstance(int, int, String)     */    public void deletePortletPreferencesByInstance(final int userId, final int layoutId, final String chanDescId) throws Exception {        final Connection con = RDBMServices.getConnection();                        final String selectPrefIds =             "SELECT PREF_ID " +            "FROM UP_PORTLET_ENTITY_PREFS " +            "WHERE USER_ID=? AND LAYOUT_ID=? AND CHAN_DESC_ID=?";                final String deletePrefNames =             "DELETE FROM UP_PORTLET_ENTITY_PREFS " +            "WHERE USER_ID=? AND LAYOUT_ID=? AND CHAN_DESC_ID=?";                final String deletePrefValues =             "DELETE FROM UP_PORTLET_PREF_VALUES " +            "WHERE PREF_ID=?";                log.debug("RDBMPortletPreferencesStore::deletePortletPreferencesByInstance(userId=" + userId + ", layoutId=" + layoutId + ", chanDescId=" + chanDescId + ")");        try {            // Set autocommit false for the connection            if (RDBMServices.supportsTransactions)                RDBMServices.setAutoCommit(con, false);            PreparedStatement selectPrefIdsPstmt = null;            PreparedStatement deletePrefNamesPstmt = null;            PreparedStatement deletePrefValuesPstmt = null;            try {                selectPrefIdsPstmt = con.prepareStatement(selectPrefIds);                deletePrefNamesPstmt = con.prepareStatement(deletePrefNames);                deletePrefValuesPstmt = con.prepareStatement(deletePrefValues);                log.debug("RDBMPortletPreferencesStore::deletePortletPreferencesByInstance(): " + selectPrefIds);                selectPrefIdsPstmt.setInt(1, userId);                selectPrefIdsPstmt.setInt(2, layoutId);                selectPrefIdsPstmt.setString(3, chanDescId);                ResultSet rs = selectPrefIdsPstmt.executeQuery();                                try {                    while (rs.next()) {                        int prefId = rs.getInt("PREF_ID");                                                log.debug("RDBMPortletPreferencesStore::deletePortletPreferencesByInstance(): " + deletePrefValues);                        deletePrefValuesPstmt.setInt(1, prefId);                        deletePrefValuesPstmt.executeUpdate();                    }                }                finally {                    try { rs.close(); } catch (Exception e) { }                }                                deletePrefNamesPstmt.setInt(1, userId);                deletePrefNamesPstmt.setInt(2, layoutId);                deletePrefNamesPstmt.setString(3, chanDescId);                                deletePrefNamesPstmt.executeUpdate();                if (RDBMServices.supportsTransactions)                    RDBMServices.commit(con);            }            catch (Exception e) {                // Roll back the transaction                if (RDBMServices.supportsTransactions)                    RDBMServices.rollback(con);                throw e;            }            finally {                try { selectPrefIdsPstmt.close(); } catch (Exception e) { }                try { deletePrefNamesPstmt.close(); } catch (Exception e) { }                try { deletePrefValuesPstmt.close(); } catch (Exception e) { }            }        }        finally {            RDBMServices.releaseConnection(con);        }    }    }

⌨️ 快捷键说明

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