ForumStartup.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 3k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright (c) JForum Team
  3.  * All rights reserved.
  4.  * Redistribution and use in source and binary forms, 
  5.  * with or without modification, are permitted provided 
  6.  * that the following conditions are met:
  7.  * 1) Redistributions of source code must retain the above 
  8.  * copyright notice, this list of conditions and the 
  9.  * following  disclaimer.
  10.  * 2)  Redistributions in binary form must reproduce the 
  11.  * above copyright notice, this list of conditions and 
  12.  * the following disclaimer in the documentation and/or 
  13.  * other materials provided with the distribution.
  14.  * 3) Neither the name of "Rafael Steil" nor 
  15.  * the names of its contributors may be used to endorse 
  16.  * or promote products derived from this software without 
  17.  * specific prior written permission.
  18.  * 
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
  20.  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
  21.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
  22.  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  23.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  24.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
  25.  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
  26.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  27.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  28.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  29.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  30.  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  31.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
  32.  * IN CONTRACT, STRICT LIABILITY, OR TORT 
  33.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
  34.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  35.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  36.  * 
  37.  * Created on 13/11/2004 01:53:12
  38.  * The JForum Project
  39.  * http://www.jforum.net
  40.  */
  41. package net.jforum;
  42. import java.sql.Connection;
  43. import org.apache.log4j.Logger;
  44. import net.jforum.dao.CategoryDAO;
  45. import net.jforum.dao.ConfigDAO;
  46. import net.jforum.dao.DataAccessDriver;
  47. import net.jforum.dao.ForumDAO;
  48. import net.jforum.exceptions.DatabaseException;
  49. import net.jforum.exceptions.RepositoryStartupException;
  50. import net.jforum.repository.ForumRepository;
  51. /**
  52.  * @author Rafael Steil
  53.  * @version $Id: ForumStartup.java,v 1.16 2006/08/23 02:24:06 rafaelsteil Exp $
  54.  */
  55. public class ForumStartup 
  56. {
  57. private static final Logger log = Logger.getLogger(ForumStartup.class);
  58. /**
  59.  * Starts the database implementation
  60.  * @return <code>true</code> if everthing were ok
  61.  * @throws DatabaseException if something were wrong
  62.  */
  63. public static boolean startDatabase()
  64. {
  65. try {
  66. if (DBConnection.createInstance()) {
  67. DBConnection.getImplementation().init();
  68. // Check if we're in fact up and running
  69. Connection conn = DBConnection.getImplementation().getConnection();
  70. DBConnection.getImplementation().releaseConnection(conn);
  71. }
  72. }
  73. catch (Exception e) {
  74. throw new DatabaseException("Error while trying to start the database: " + e, e);
  75. }
  76. return true;
  77. }
  78. /**
  79.  * Starts the cache control for forums and categories.
  80.  * @throws RepositoryStartupException is something were wrong.
  81.  */
  82. public static void startForumRepository()
  83. {
  84. try {
  85. ForumDAO fm = DataAccessDriver.getInstance().newForumDAO();
  86. CategoryDAO cm = DataAccessDriver.getInstance().newCategoryDAO();
  87. ConfigDAO configModel = DataAccessDriver.getInstance().newConfigDAO();
  88. ForumRepository.start(fm, cm, configModel);
  89. }
  90. catch (Exception e) {
  91. log.error("Unable to bootstrap JForum repository.", e);
  92. throw new RepositoryStartupException("Error while trying to start ForumRepository: " + e, e);
  93. }
  94. }
  95. }