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

📄 managedatabase.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                // format paths...                String  originDataJahiaFilesPath       =  JahiaTools.convertContexted( properties.getProperty("jahiaFilesBigTextDiskPath").trim(), context );                String  originTemplatesJahiaFilesPath  =  JahiaTools.convertContexted( properties.getProperty("jahiaFilesTemplatesDiskPath").trim(), context );                String  originTemplatesJSPPath         =  JahiaTools.convertContexted( "$context/"+properties.getProperty("jahiaTemplatesDiskPath").trim(), context );                String  backupJahiaFilesPath           =  JahiaTools.convertContexted( properties.getProperty("jahiaVarDiskPath").trim() + File.separator + "backup", context );                String  thisBackupJahiaFilesPath       =  backupJahiaFilesPath + File.separator + jahiaBackupEpoch;                String  backupDataJahiaFilesPath       =  thisBackupJahiaFilesPath + File.separator + "data";                String  backupTemplatesJahiaFilesPath  =  thisBackupJahiaFilesPath + File.separator + "templates" + File.separator + "xml";                String  backupTemplatesJSPPath         =  thisBackupJahiaFilesPath + File.separator + "templates" + File.separator + "jsp";                // restore jahiafiles (data and templates folders)...                JahiaTools.deleteFile( new File( originDataJahiaFilesPath ) );                JahiaTools.deleteFile( new File( originTemplatesJahiaFilesPath ) );                JahiaTools.deleteFile( new File( originTemplatesJSPPath ) );                JahiaTools.copyFolderContent( backupDataJahiaFilesPath,       originDataJahiaFilesPath );                JahiaTools.copyFolderContent( backupTemplatesJahiaFilesPath,  originTemplatesJahiaFilesPath );                JahiaTools.copyFolderContent( backupTemplatesJSPPath,         originTemplatesJSPPath );                // execute backup sql runtime text...                Enumeration allGrabbedData =  JahiaTools.string2Enumeration( thisBackupJahiaFilesPath + File.separator + "sqldata.backup", true );                insertDatabaseData( allGrabbedData, properties.getProperty("db_driver"), properties.getProperty("db_url"), properties.getProperty("db_username"), properties.getProperty("db_password") );                // Check to restore patch or not                String  patchPath  =  JahiaTools.convertContexted( properties.getProperty("jahiaVarDiskPath").trim() + File.separator + "patch", context );                File f = new File(patchPath);                File[] files = f.listFiles();                for (int i=0 ;i<files.length ; i++){                    if ( files[i].getName().endsWith(".property") ){                        JahiaConsole.println("ManageDatabase.processRestore","Find patch file " + files[i].getName());                        PropertiesManager patch =  new PropertiesManager( files[i].getAbsolutePath() );                        try {                            if ( Integer.parseInt(patch.getProperty("build").trim())>Integer.parseInt(backupBuild) ){                                patch = null;                                JahiaConsole.println("ManageDatabase.processRestore","Delete patch file " + files[i].getName());                                files[i].delete();                            }                        }catch(Throwable t){                            JahiaConsole.println("ManageDatabase.processRestore","Exception " + t.getMessage());                            t.printStackTrace();                            // not a valid patch info file                        }                    }                }                // NK, we do not free the lock.                // Doing so, we force the admin to restart the server ! ugly isn't ?                freeLock = false;                // display final...                request.setAttribute( "processMessage",  "Your database restore has completed successfully.<br>Please restart Jahia for the changes to take effect." );                session.setAttribute( CLASS_NAME + "jahiaDisplayMessage",  Jahia.COPYRIGHT );                JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "finish.jsp" );            } catch ( Throwable t ){                t.printStackTrace();                session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Error occured");                JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" );                return;            } finally {                if ( freeLock ){                    Jahia.releaseLock(jahiaLock);                }            }        }    } // end processRestore    /**     * Process the delete / flush of a database backup.     * @author  Alexandre Kraft     *     * @param   request       Servlet request.     * @param   response      Servlet response.     * @param   session       Servlet session for the current user.     */    private void processFlush( HttpServletRequest   request,                               HttpServletResponse  response,                               HttpSession          session )    throws IOException, ServletException    {        synchronized ( mLock ){            boolean processError     = true;            // get url epoch values...            String  jahiaFlushEpoch  = (String) request.getParameter("epoch").trim();            // format paths...            String  backupJahiaFilesPath     =  JahiaTools.convertContexted( properties.getProperty("jahiaVarDiskPath").trim() + File.separator + "backup", context );            String  thisBackupJahiaFilesPath =  backupJahiaFilesPath + File.separator + jahiaFlushEpoch;            // flush jahiafiles...            File f= new File( backupJahiaFilesPath + File.separator + "backup_" + jahiaFlushEpoch + ".info" );            f.delete();            JahiaConsole.println("ManageBackup.flush","Delete file " + f.getAbsolutePath() );            JahiaTools.deleteFile( new File( backupJahiaFilesPath + File.separator + "backup_" + jahiaFlushEpoch + ".info" ) );            JahiaTools.deleteFile( new File( thisBackupJahiaFilesPath ) );            // display final...            request.setAttribute( "processMessage",  "Selected backup flushed." );            session.setAttribute( CLASS_NAME + "jahiaDisplayMessage",  Jahia.COPYRIGHT );            displayRestore( request, response, session );       }    } // end processFlush    /**     * Process and check validity of inputs from the database settings page.     * This method is used for change settings and transfer settings. The     * difference between these two cases is just some internal actions.     * @author  Alexandre Kraft     *     * @param   request       Servlet request.     * @param   response      Servlet response.     * @param   session       Servlet session for the current user.     * @param   transfer      <code>true</code> if the user has requested a transfer.     *                        <code>false</code> if the user want just to change     *                        in the database settings.     */    private void processSettings( HttpServletRequest   request,                                  HttpServletResponse  response,                                  HttpSession          session,                                  boolean              transfer )    throws IOException, ServletException    {        synchronized ( mLock ){            boolean processError                = true;            String  runtimeTestSQL              = "";            int     jahiaDBMinConnectionsInt    = 0;            int     jahiaDBMaxConnectionsInt    = 0;            // get form values...            String  jahiaDBScript          = (String) request.getParameter("dbtype").trim();            String  jahiaDBDriver          = (String) request.getParameter("dbdriver").trim();            String  jahiaDBUrl             = (String) request.getParameter("dburl").trim();            String  jahiaDBUsername        = (String) request.getParameter("dbusername").trim();            String  jahiaDBPassword        = (String) request.getParameter("dbpassword").trim();            String  jahiaDBMinConnections  = (String) request.getParameter("dbminconnect");            String  jahiaDBMaxConnections  = (String) request.getParameter("dbmaxconnect");            String  jahiaDBWaitIfBusy      = (String) request.getParameter("dbwait");            String  jahiaDBVerbose         = (String) request.getParameter("dbverbose");            // check special settings validity (if required)...            if(!transfer) {                try {                    jahiaDBMinConnectionsInt = Integer.parseInt(jahiaDBMinConnections.trim());                } catch (NumberFormatException nfe) {                    jahiaDBMinConnectionsInt = 0;                }                try {                    jahiaDBMaxConnectionsInt = Integer.parseInt(jahiaDBMaxConnections.trim());                } catch (NumberFormatException nfe) {                    jahiaDBMaxConnectionsInt = 0;                }            }            // check form validity...            if(jahiaDBDriver.length() == 0) {                session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Database driver must be set.");            } else if(jahiaDBUrl.length() == 0) {                session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Database URL must be set.");            } else {                if(!transfer) {                    if(jahiaDBMinConnections.length() == 0) {                        session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Minimum connections must be set.");                    } else if(jahiaDBMinConnectionsInt < 1) {                        session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Minimum connections must be higher than zero.");                    } else if(jahiaDBMaxConnections.length() == 0) {                        session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Maximum connections must be set.");                    } else if(jahiaDBMaxConnectionsInt < 1) {                        session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Maximum connections must be higher than zero.");                    } else if(jahiaDBMaxConnectionsInt <= jahiaDBMinConnectionsInt) {                        session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Maximum connections must be higher than minimum connections.");                    } else {                        processError = false;                    }                } else {                    processError = false;                }            }            // get script runtime...            StringBuffer constructDBScript =  new StringBuffer();            constructDBScript.append( Jahia.jahiaDatabaseScriptsPath );            constructDBScript.append( File.separator );            constructDBScript.append( jahiaDBScript );            // get the script runtime...            try {                File        scriptsFileObject  =  new File( constructDBScript.toString() );                Enumeration scriptsListRuntime =  scriptsManager.getDatabaseScriptsRuntime( scriptsFileObject );                runtimeTestSQL                 =  (String) scriptsListRuntime.nextElement();            } catch (FileNotFoundException fnfe) {                session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "Cannot open your database script.");                processError =  true;            }            // test the connection...            if(!processError) {                HashMap testDatabaseConnectionHashMap  =  dbConnect.databaseTest( jahiaDBScript, jahiaDBDriver, jahiaDBUrl, jahiaDBUsername, jahiaDBPassword, runtimeTestSQL, false );                Boolean testDatabaseConnectionError    =  (Boolean) testDatabaseConnectionHashMap.get("testDatabaseConnectionError");                String  testDatabaseConnectionMessage  =  (String)  testDatabaseConnectionHashMap.get("testDatabaseConnectionMessage");                if(testDatabaseConnectionError.booleanValue()) {                    JahiaConsole.println("JahiaAdministration",  "Database test failed.\n");                    session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  testDatabaseConnectionMessage);                    processError = true;                } else {                    JahiaConsole.println("JahiaAdministration",  "Database test passed successfully!\n");                }            }            // set new values...            session.setAttribute(CLASS_NAME + "jahiaDBScript",    jahiaDBScript);            session.setAttribute(CLASS_NAME + "jahiaDBDriver",    jahiaDBDriver);            session.setAttribute(CLASS_NAME + "jahiaDBUrl",       jahiaDBUrl);            session.setAttribute(CLASS_NAME + "jahiaDBUsername",  jahiaDBUsername);            session.setAttribute(CLASS_NAME + "jahiaDBPassword",  jahiaDBPassword);            if(!transfer) {                session.setAttribute(CLASS_NAME + "jahiaDBMinConnections",  jahiaDBMinConnections);                session.setAttribute(CLASS_NAME + "jahiaDBMaxConnections",  jahiaDBMaxConnections);                session.setAttribute(CLASS_NAME + "jahiaDBWaitIfBusy",      jahiaDBWaitIfBusy);                session.setAttribute(CLASS_NAME + "jahiaDBVerbose",         jahiaDBVerbose);            }            if(processError) {                displaySettings( request, response, session );            } else {                                                    // no error(s) detected, continue...                if(!transfer) {                    storeSettings( request, response, session, transfer );                } else {                    if(!checkSameDatabase( jahiaDBUrl )) {                        String      sqlGrab         = grabDatabaseData( properties.getProperty("db_driver"), properties.getProperty("db_url"), properties.getProperty("db_username"), properties.getProperty("db_password") );                        Enumeration allGrabbedData  = JahiaTools.string2Enumeration( sqlGrab, false );                        insertDatabaseTables( jahiaDBScript, jahiaDBDriver, jahiaDBUrl, jahiaDBUsername, jahiaDBPassword );                        insertDatabaseData( allGrabbedData, jahiaDBDriver, jahiaDBUrl, jahiaDBUsername, jahiaDBPassword );                        storeSettings( request, response, session, transfer );                    } else {                        session.setAttribute(CLASS_NAME + "jahiaDisplayMessage",  "You've tried to use the current database.");                        displaySettings( request, response, session );                    }                }            }        }    } // end processSettings    /**     * Store new settings for the server page and redirect to the final page.     * @author  Alexandre Kraft

⌨️ 快捷键说明

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