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

📄 offlineconnection.java

📁 一个java方面的消息订阅发送的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            System.err.println("Failed to get message count for " + topic +
                " b/c " + exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return count;
    }

    // implementation of AbstractAdminConnection.getQueueMessageCount
    public int getQueueMessageCount(String queue) {
        int count = -1;
        Connection connection = null;

        try {
            connection = DatabaseService.getConnection();

            count = DatabaseService.getAdapter().getQueueMessageCount(
                connection, queue);
            connection.commit();
        } catch (PersistenceException exception) {
            System.err.println("Failed to get message count for " + queue +
                " b/c " + exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return count;
    }

    // implementation of AbstractAdminConnection.durableConsumerExists
    public boolean durableConsumerExists(String name) {
        boolean result = false;
        Connection connection = null;

        try {
            connection = DatabaseService.getConnection();

            result = DatabaseService.getAdapter().durableConsumerExists(
                connection, name);
            connection.commit();
        } catch (PersistenceException exception) {
            System.err.println("Failed on consumer exists for " + name +
                " b/c " + exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return result;
    }

    // implementation of AbstractAdminConnection.getDurableConsumers
    public Enumeration getDurableConsumers(String topic) {
        Enumeration result = null;
        Connection connection = null;

        try {
            connection = DatabaseService.getConnection();

            result = DatabaseService.getAdapter().getDurableConsumers(
                connection, topic);
            connection.commit();
        } catch (PersistenceException exception) {
            System.err.println("Failed on getDurableConsumers for " + topic +
                " b/c " + exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return result;
    }

    // implementation of AbstractAdminConnection.removeDestination
    public boolean removeDestination(String destination) {
        boolean result = false;
        Connection connection = null;

        try {
            connection = DatabaseService.getConnection();

            DatabaseService.getAdapter().removeDestination(connection,
                destination);
            if (_context == null) {
                // connect to the JNDI server and get a reference to
                // root context
                Hashtable props = new Hashtable();
                props.put(Context.INITIAL_CONTEXT_FACTORY,
                    "org.exolab.jms.jndi.intravm.IntravmJndiServer");
                _context = new InitialContext(props);
            }
            _context.unbind(destination);
            connection.commit();
            result = true;
        } catch (PersistenceException exception) {
            System.err.println("Failed on getDurableConsumers for " +
                destination + " b/c " + exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (javax.naming.NamingException err) {
            System.err.println("Failed to removeDestination " + destination +
                " b/c" + err.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return result;
    }

    // implementation of AbstractAdminConnection.purgeMessages
    public int purgeMessages() {
        return DatabaseService.getAdapter().purgeMessages();
    }

    // implementation of AbstractAdminConnection.stopServer
    public void stopServer() {
        JOptionPane.showMessageDialog
            (_parent, "Not available in offline mode",
                "Shutdown Error", JOptionPane.ERROR_MESSAGE);
    }

    // implementation of AbstractAdminConnection.addUser
    public boolean addUser(String username, String password) {
        Connection connection = null;
        boolean success = false;

        try {
            connection = DatabaseService.getConnection();

            DatabaseService.getAdapter().addUser(connection,
                new User(username, password));
            connection.commit();
            success = true;
        } catch (PersistenceException exception) {
            System.err.println("Failed to add user " + username +
                exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return success;
    }

    // implementation of AbstractAdminConnection.changePassord
    public boolean changePassword(String username, String password) {
        Connection connection = null;
        boolean success = false;

        try {
            connection = DatabaseService.getConnection();

            DatabaseService.getAdapter().updateUser(connection,
                new User(username, password));
            connection.commit();
            success = true;
        } catch (PersistenceException exception) {
            System.err.println("Failed to add user " + username +
                exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return success;
    }

    // implementation of AbstractAdminConnection.removeUser
    public boolean removeUser(String username) {
        boolean result = false;
        Connection connection = null;

        try {
            connection = DatabaseService.getConnection();

            DatabaseService.getAdapter().removeUser(connection,
                new User(username, null));
            connection.commit();
            result = true;
        } catch (PersistenceException exception) {
            System.err.println("Failed on remove user for " +
                username + exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return result;
    }

    // implementation of AbstractAdminConnection.getAllUsers
    public Enumeration getAllUsers() {
        Enumeration result = null;
        Connection connection = null;

        try {
            connection = DatabaseService.getConnection();

            result = DatabaseService.getAdapter().getAllUsers(
                connection);
            connection.commit();
        } catch (PersistenceException exception) {
            System.err.println("Failed on getAllUsers "
                + exception.toString());
            try {
                connection.rollback();
            } catch (Exception nested) {
                // ignore
            }
        } catch (Exception exception) {
            // ignore for the moment
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception nested) {
                    // ignore
                }
            }
        }

        return result;
    }
} //-- OfflineConnection

⌨️ 快捷键说明

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