Package org.apache.roller.util

Examples of org.apache.roller.util.SQLScriptRunner


                //Connection conn = DriverManager.getConnection(
                    //"jdbc:derby:rollerdb;create=true","APP", "APP");

                // create roller tables

                SQLScriptRunner runner1 = new SQLScriptRunner(
                        databaseScriptsDir
                        + File.separator + "droptables.sql");
                runner1.runScript(conn, false);

                SQLScriptRunner runner = new SQLScriptRunner(
                        databaseScriptsDir
                        + File.separator + "derby"
                        + File.separator + "createdb.sql");
                try {
                    runner.runScript(conn, true);
                } catch (Exception ignored) {
                    for (String message : runner.getMessages()) {
                        System.out.println(message);
                    }
                    ignored.printStackTrace();
                }              
View Full Code Here


                //Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
                //Connection conn = DriverManager.getConnection(
                    //"jdbc:derby:rollerdb;create=true","APP", "APP");

                // drop Roller tables
                SQLScriptRunner runner = new SQLScriptRunner(
                        databaseScriptsDir
                        + File.separator + "droptables.sql");
                runner.runScript(conn, false);

                System.out.println("==============");
                System.out.println("Stopping Derby");
                System.out.println("==============");
               
View Full Code Here

    public void createDatabase() throws StartupException {
       
        log.info("Creating Roller Weblogger database tables.");
       
        Connection con = null;
        SQLScriptRunner create = null;
        try {
            con = db.getConnection();
            String handle = getDatabaseHandle(con);
            create = new SQLScriptRunner(scripts.getDatabaseScript(handle + "/createdb.sql"));
            create.runScript(con, true);
            messages.addAll(create.getMessages());
           
            setDatabaseVersion(con, version);
           
        } catch (SQLException sqle) {
            log.error("ERROR running SQL in database creation script", sqle);
            if (create != null) messages.addAll(create.getMessages());
            errorMessage("ERROR running SQL in database creation script");
            throw new StartupException("Error running sql script", sqle);
           
        } catch (Exception ioe) {
            log.error("ERROR running database creation script", ioe);
            if (create != null) messages.addAll(create.getMessages());
            errorMessage("ERROR reading/parsing database creation script");
            throw new StartupException("Error running SQL script", ioe);

        } finally {
            try { if (con != null) con.close(); } catch (Exception ignored) {}
View Full Code Here

   
    /**
     * Upgrade database for Roller 1.3.0
     */
    private void upgradeTo130(Connection con, boolean runScripts) throws StartupException {
        SQLScriptRunner runner = null;
        try {
            if (runScripts) {
                String handle = getDatabaseHandle(con);
                String scriptPath = handle + "/120-to-130-migration.sql";
                successMessage("Running database upgrade script: "+scriptPath);               
                runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
                runner.runScript(con, true);
                messages.addAll(runner.getMessages());
            }
           
            /*
             * The new theme management code is going into place and it uses
             * the old website.themeEditor attribute to store a users theme.
             *
             * In pre-1.3 Roller *all* websites are considered to be using a
             * custom theme, so we need to make sure this is properly defined
             * by setting the theme on all websites to custom.
             *
             * NOTE: If we don't do this then nothing would break, but some users
             * would be suprised that their template customizations are no longer
             * in effect because they are using a shared theme instead.
             */
           
            successMessage("Doing upgrade to 130 ...");
            successMessage("Ensuring that all website themes are set to custom");
           
            PreparedStatement setCustomThemeStmt = con.prepareStatement(
                    "update website set editortheme = ?");
           
            setCustomThemeStmt.setString(1, org.apache.roller.weblogger.pojos.WeblogTheme.CUSTOM);
            setCustomThemeStmt.executeUpdate();
           
            if (!con.getAutoCommit()) con.commit();
           
            successMessage("Upgrade to 130 complete.");
           
        } catch (Exception e) {
            log.error("ERROR running 310 database upgrade script", e);
            if (runner != null) messages.addAll(runner.getMessages());
           
            errorMessage("Problem upgrading database to version 130", e)
            throw new StartupException("Problem upgrading database to version 130", e);
        }
       
View Full Code Here

   
    /**
     * Upgrade database for Roller 2.0.0
     */
    private void upgradeTo200(Connection con, boolean runScripts) throws StartupException {
        SQLScriptRunner runner = null;
        try {
            if (runScripts) {
                String handle = getDatabaseHandle(con);
                String scriptPath = handle + "/130-to-200-migration.sql";
                successMessage("Running database upgrade script: "+scriptPath);               
                runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
                runner.runScript(con, true);
                messages.addAll(runner.getMessages());
            }
           
            successMessage("Doing upgrade to 200 ...");
            successMessage("Populating roller_user_permissions table");
           
            PreparedStatement websitesQuery = con.prepareStatement(
                    "select w.id as wid, u.id as uid, u.username as uname from "
                    + "website as w, rolleruser as u where u.id=w.userid");
            PreparedStatement websiteUpdate = con.prepareStatement(
                    "update website set handle=? where id=?");
            PreparedStatement entryUpdate = con.prepareStatement(
                    "update weblogentry set userid=?, status=?, "
                    + "pubtime=pubtime, updatetime=updatetime "
                    + "where publishentry=? and websiteid=?");
            PreparedStatement permsInsert = con.prepareStatement(
                    "insert into roller_permissions "
                    + "(id, username, actions, objectid, objecttype, pending, datecreated) "
                    + "values (?,?,?,?,?,?,?)");
           
            // loop through websites, each has a user
            java.sql.Date now = new java.sql.Date(new Date().getTime());
            ResultSet websiteSet = websitesQuery.executeQuery();
            while (websiteSet.next()) {
                String websiteid = websiteSet.getString("wid");
                String userid = websiteSet.getString("uid");
                String username = websiteSet.getString("uname");
                successMessage("Processing website: " + username);
               
                // use website user's username as website handle
                websiteUpdate.clearParameters();
                websiteUpdate.setString(1, username);
                websiteUpdate.setString(2, websiteid);
                websiteUpdate.executeUpdate();
               
                // update all of pubished entries to include userid and status
                entryUpdate.clearParameters();
                entryUpdate.setString( 1, userid);
                entryUpdate.setString( 2, "PUBLISHED");
                entryUpdate.setBoolean(3, true);
                entryUpdate.setString( 4, websiteid);
                entryUpdate.executeUpdate();
               
                // update all of draft entries to include userid and status
                entryUpdate.clearParameters();
                entryUpdate.setString( 1, userid);
                entryUpdate.setString( 2, "DRAFT");
                entryUpdate.setBoolean(3, false);
                entryUpdate.setString( 4, websiteid);
                entryUpdate.executeUpdate();
               
                // add  permission for user in website
                permsInsert.clearParameters();
                permsInsert.setString( 1, websiteid+"p");
                permsInsert.setString( 2, username);
                permsInsert.setString( 3, WeblogPermission.ADMIN);
                permsInsert.setString( 4, websiteid);
                permsInsert.setString( 5, "Weblog");
                permsInsert.setBoolean(6, false);
                permsInsert.setDate(   7, now);
                permsInsert.setBoolean(5, false);
                permsInsert.executeUpdate();
            }
           
            if (!con.getAutoCommit()) con.commit();
           
            successMessage("Upgrade to 200 complete.");
           
        } catch (Exception e) {
            log.error("ERROR running 310 database upgrade script", e);
            if (runner != null) messages.addAll(runner.getMessages());
           
            errorMessage("Problem upgrading database to version 200", e);
            throw new StartupException("Problem upgrading database to version 200", e);
        }
       
View Full Code Here

   
    /**
     * Upgrade database for Roller 2.1.0
     */
    private void upgradeTo210(Connection con, boolean runScripts) throws StartupException {
        SQLScriptRunner runner = null;
        try {
            if (runScripts) {
                String handle = getDatabaseHandle(con);
                String scriptPath = handle + "/200-to-210-migration.sql";
                successMessage("Running database upgrade script: "+scriptPath);               
                runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
                runner.runScript(con, true);
                messages.addAll(runner.getMessages());
            }
           
            /*
             * For Roller 2.1.0 we are going to standardize some of the
             * weblog templates and make them less editable.  To do this
             * we need to do a little surgery.
             *
             * The goal for this upgrade is to ensure that ALL weblogs now have
             * the required "Weblog" template as their default template.
             */
           
            successMessage("Doing upgrade to 210 ...");
            successMessage("Ensuring that all weblogs use the 'Weblog' template as their default page");
           
            // this query will give us all websites that have modified their
            // default page to link to something other than "Weblog"
            PreparedStatement selectUpdateWeblogs = con.prepareStatement(
                    "select website.id,template,website.handle from website,webpage "+
                    "where webpage.id = website.defaultpageid "+
                    "and webpage.link != 'Weblog'");
           
            PreparedStatement selectWeblogTemplate = con.prepareStatement(
                    "select id from webpage where websiteid = ? and link = 'Weblog'");
           
            PreparedStatement updateWeblogTemplate = con.prepareStatement(
                    "update webpage set template = ? where id = ?");
           
            // insert a new template for a website
            PreparedStatement insertWeblogTemplate = con.prepareStatement(
                    "insert into webpage"+
                    "(id, name, description, link, websiteid, template, updatetime) "+
                    "values(?,?,?,?,?,?,?)");
           
            // update the default page for a website
            PreparedStatement updateDefaultPage = con.prepareStatement(
                    "update website set defaultpageid = ? "+
                    "where id = ?");
           
            String description = "This template is used to render the main "+
                    "page of your weblog.";
            ResultSet websiteSet = selectUpdateWeblogs.executeQuery();
            Date now = new Date();
            while (websiteSet.next()) {
                String websiteid = websiteSet.getString(1);
                String template = websiteSet.getString(2);
                String handle = websiteSet.getString(3);
                successMessage("Processing website: " + handle);
               
                String defaultpageid = null;
               
                // it's possible that this weblog has a "Weblog" template, but just
                // isn't using it as their default.  if so we need to fix that.
                selectWeblogTemplate.clearParameters();
                selectWeblogTemplate.setString(1, websiteid);
                ResultSet weblogPageSet = selectWeblogTemplate.executeQuery();
                if(weblogPageSet.next()) {
                    // this person already has a "Weblog" template, so update it
                    String id = weblogPageSet.getString(1);
                   
                    updateWeblogTemplate.clearParameters();
                    updateWeblogTemplate.setString(1, template);
                    updateWeblogTemplate.setString(2, id);
                    updateWeblogTemplate.executeUpdate();
                   
                    // make sure and adjust what default page id we want to use
                    defaultpageid = id;
                } else {
                    // no "Weblog" template, so insert a new one
                    insertWeblogTemplate.clearParameters();
                    insertWeblogTemplate.setString( 1, websiteid+"q");
                    insertWeblogTemplate.setString( 2, "Weblog");
                    insertWeblogTemplate.setString( 3, description);
                    insertWeblogTemplate.setString( 4, "Weblog");
                    insertWeblogTemplate.setString( 5, websiteid);
                    insertWeblogTemplate.setString( 6, template);
                    insertWeblogTemplate.setDate(   7, new java.sql.Date(now.getTime()));
                    insertWeblogTemplate.executeUpdate();
                   
                    // set the new default page id
                    defaultpageid = websiteid+"q";
                }
               
                // update defaultpageid value
                updateDefaultPage.clearParameters();
                updateDefaultPage.setString( 1, defaultpageid);
                updateDefaultPage.setString( 2, websiteid);
                updateDefaultPage.executeUpdate();
            }
           
           
            if (!con.getAutoCommit()) con.commit();
           
            successMessage("Upgrade to 210 complete.");
           
        } catch (Exception e) {
            log.error("ERROR running 310 database upgrade script", e);
            if (runner != null) messages.addAll(runner.getMessages());
           
            log.error("Problem upgrading database to version 210", e);
            throw new StartupException("Problem upgrading database to version 210", e);
        }
       
View Full Code Here

   
    /**
     * Upgrade database for Roller 2.3.0
     */
    private void upgradeTo230(Connection con, boolean runScripts) throws StartupException {
        SQLScriptRunner runner = null;
        try {
            if (runScripts) {
                String handle = getDatabaseHandle(con);
                String scriptPath = handle + "/210-to-230-migration.sql";
                successMessage("Running database upgrade script: "+scriptPath);               
                runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
                runner.runScript(con, true);
                messages.addAll(runner.getMessages());
            }
        } catch (Exception e) {
            log.error("ERROR running 310 database upgrade script", e);
            if (runner != null) messages.addAll(runner.getMessages());
           
            errorMessage("Problem upgrading database to version 230", e);
            throw new StartupException("Problem upgrading database to version 230", e);
        }
       
View Full Code Here

   
    /**
     * Upgrade database for Roller 2.4.0
     */
    private void upgradeTo240(Connection con, boolean runScripts) throws StartupException {
        SQLScriptRunner runner = null;
        try {
            if (runScripts) {
                String handle = getDatabaseHandle(con);
                String scriptPath = handle + "/230-to-240-migration.sql";
                successMessage("Running database upgrade script: "+scriptPath);               
                runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
                runner.runScript(con, true);
                messages.addAll(runner.getMessages());
            }
        } catch (Exception e) {
            log.error("ERROR running 310 database upgrade script", e);
            if (runner != null) messages.addAll(runner.getMessages());
           
            errorMessage("Problem upgrading database to version 240", e);
            throw new StartupException("Problem upgrading database to version 240", e);
        }
       
View Full Code Here

   
    /**
     * Upgrade database for Roller 3.0.0
     */
    private void upgradeTo300(Connection con, boolean runScripts) throws StartupException {
        SQLScriptRunner runner = null;
        try {
            if (runScripts) {
                String handle = getDatabaseHandle(con);
                String scriptPath = handle + "/240-to-300-migration.sql";
                successMessage("Running database upgrade script: "+scriptPath);               
                runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
                runner.runScript(con, true);
                messages.addAll(runner.getMessages());
            }
           
            /*
             * For Roller 3.0.0 we are allowing each weblogentry to track a
             * locale now so that we can support multi-lingual blogs.  As part
             * of the upgrade process we want to do 2 things ..
             *
             * 1. make sure all weblogs have a locale
             * 2. set the locale on all entries to the locale for the weblog
             */
           
            successMessage("Doing upgrade to 300 ...");
           
            // get system default language
            String locale = java.util.Locale.getDefault().getLanguage();
           
            successMessage("Setting website locale to "+locale+" for websites with no locale");
           
            // update all weblogs where locale is "null"
            PreparedStatement updateNullWeblogLocale = con.prepareStatement(
                    "update website set locale = ? where locale is NULL");
            // update all weblogs where locale is empty string ""
            PreparedStatement updateEmptyWeblogLocale = con.prepareStatement(
                    "update website set locale = ? where locale = ''");
            updateNullWeblogLocale.setString( 1, locale);
            updateEmptyWeblogLocale.setString( 1, locale);
            updateNullWeblogLocale.executeUpdate();
            updateEmptyWeblogLocale.executeUpdate();

           
            successMessage("Setting weblogentry locales to website locale");
           
            // get all entries and the locale of its website
            PreparedStatement selectWeblogsLocale = con.prepareStatement(
                    "select weblogentry.id,website.locale "+
                    "from weblogentry,website "+
                    "where weblogentry.websiteid = website.id");
           
            // set the locale for an entry
            PreparedStatement updateWeblogLocale = con.prepareStatement(
                    "update weblogentry set locale = ? where id = ?");
           
            ResultSet websiteSet = selectWeblogsLocale.executeQuery();
            while (websiteSet.next()) {
                String entryid = websiteSet.getString(1);
                String entrylocale = websiteSet.getString(2);
               
                // update entry locale
                updateWeblogLocale.clearParameters();
                updateWeblogLocale.setString( 1, entrylocale);
                updateWeblogLocale.setString( 2, entryid);
                updateWeblogLocale.executeUpdate();
            }
           
           
            if (!con.getAutoCommit()) con.commit();
           
            successMessage("Upgrade to 300 complete.");
           
        } catch (Exception e) {
            log.error("ERROR running 310 database upgrade script", e);
            if (runner != null) messages.addAll(runner.getMessages());
           
            errorMessage("Problem upgrading database to version 300", e);
            throw new StartupException("Problem upgrading database to version 300", e);
        }
       
View Full Code Here

   
    /**
     * Upgrade database for Roller 3.1.0
     */
    private void upgradeTo310(Connection con, boolean runScripts) throws StartupException {
        SQLScriptRunner runner = null;
        try {
            if (runScripts) {
                String handle = getDatabaseHandle(con);
                String scriptPath = handle + "/300-to-310-migration.sql";
                successMessage("Running database upgrade script: "+scriptPath);               
                runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
                runner.runScript(con, true);
                messages.addAll(runner.getMessages());
            }
        } catch (Exception e) {
            log.error("ERROR running 310 database upgrade script", e);
            if (runner != null) messages.addAll(runner.getMessages());
           
            errorMessage("Problem upgrading database to version 310", e);
            throw new StartupException("Problem upgrading database to version 310", e);
        }
       
View Full Code Here

TOP

Related Classes of org.apache.roller.util.SQLScriptRunner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.