Package net.easymodo.asagi.exception

Examples of net.easymodo.asagi.exception.BoardInitException


                conn.commit();
                throw e;
            }
            tableChkStmt.close();
        } catch(SQLException e) {
            throw new BoardInitException(e);
        }
    }
View Full Code Here


            if(!res.isBeforeFirst()) {
                // Query to create tables common to all boards
                try {
                    commonSql = Resources.toString(Resources.getResource(commonSqlRes), Charsets.UTF_8);
                } catch(IOException e) {
                    throw new BoardInitException(e);
                } catch(IllegalArgumentException e) {
                    throw new BoardInitException(e);
                }
            }
        } finally {
            res.close();
        }
        conn.commit();

        // Check if the tables for this board have already been created too
        // Bail out if yes
        tableChkStmt.setString(1, this.table);
        res = tableChkStmt.executeQuery();
        try {
            if(res.isBeforeFirst()) {
                conn.commit();
                return;
            }
        } finally {
            res.close();
        }
        conn.commit();

        // Query to create all tables for this board
        String boardSql;
        try {
            boardSql = Resources.toString(Resources.getResource(boardSqlRes), Charsets.UTF_8);
            boardSql = boardSql.replaceAll("%%BOARD%%", table);
            boardSql = boardSql.replaceAll("%%CHARSET%%", charset);
        } catch(IOException e) {
            throw new BoardInitException(e);
        } catch(IllegalArgumentException e) {
            throw new BoardInitException(e);
        }

        // Query to create or replace triggers and procedures for this board
        String triggersSql;
        try {
            triggersSql = Resources.toString(Resources.getResource(triggersSqlRes), Charsets.UTF_8);
            triggersSql = triggersSql.replaceAll("%%BOARD%%", table);
            triggersSql = triggersSql.replaceAll("%%CHARSET%%", charset);
        } catch(IOException e) {
            throw new BoardInitException(e);
        } catch(IllegalArgumentException e) {
            throw new BoardInitException(e);
        }

        Statement st = conn.createStatement();
        try {
            if(commonSql != null)
View Full Code Here

        Board sourceBoard;
        try {
            Class<?> sourceBoardClass = Class.forName("net.easymodo.asagi." + sourceEngine);
            sourceBoard = (Board) sourceBoardClass.getConstructor(String.class, BoardSettings.class).newInstance(boardName, bSet);
        } catch(ClassNotFoundException e) {
            throw new BoardInitException("Error initializing board engine " + sourceEngine + ", no such engine?");
        } catch(Exception e) {
            throw new BoardInitException("Error initializing board engine " + sourceEngine);
        }

        // Same for DB engine
        String boardEngine = bSet.getEngine() == null ? "Mysql" : bSet.getEngine();
        bSet.setEngine(boardEngine);

        Class<?> sqlBoardClass;
        Constructor<?> boardCnst;

        // Init two DB objects: one for topic insertion and another
        // for media insertion
        Object topicDbObj;
        Object mediaDbObj;

        try {
            sqlBoardClass = Class.forName("net.easymodo.asagi." + boardEngine);
            boardCnst = sqlBoardClass.getConstructor(String.class, BoardSettings.class);

            // For topics
            topicDbObj = boardCnst.newInstance(bSet.getPath(), bSet);

            // For media
            mediaDbObj = boardCnst.newInstance(bSet.getPath(), bSet);
        } catch(ClassNotFoundException e) {
            throw new BoardInitException("Could not find board engine for " + boardEngine);
        } catch(NoSuchMethodException e) {
            throw new BoardInitException("Error initializing board engine " + boardEngine);
        } catch(InstantiationException e) {
            throw new BoardInitException("Error initializing board engine " + boardEngine);
        } catch(IllegalAccessException e) {
            throw new BoardInitException("Error initializing board engine " + boardEngine);
        } catch(InvocationTargetException e) {
            if(e.getCause() instanceof BoardInitException)
                throw (BoardInitException)e.getCause();
            else if(e.getCause() instanceof RuntimeException)
                throw (RuntimeException)e.getCause();
            throw new BoardInitException("Error initializing board engine " + boardEngine);
        }

        // Making sure we got valid DB engines for post and media insertion
        DB topicDb = null;
        DB mediaDb = null;

        if(topicDbObj instanceof DB && mediaDbObj instanceof DB) {
            topicDb = (DB) topicDbObj;
            mediaDb = (DB) mediaDbObj;
        }

        if(topicDb == null) {
            throw new BoardInitException("Wrong engine specified for " + boardEngine);
        }

        Local topicLocalBoard = new Local(bSet.getPath(), bSet, topicDb);
        Local mediaLocalBoard = new Local(bSet.getPath(), bSet, mediaDb);

        // And the dumper, le sigh.
        AbstractDumper dumper;
        try {
            Class<?> dumperClass = Class.forName("net.easymodo.asagi." + dumperEngine);
            dumper = (AbstractDumper) dumperClass.getConstructor(String.class, Local.class, Local.class, Board.class, boolean.class, boolean.class, int.class)
                    .newInstance(boardName, topicLocalBoard, mediaLocalBoard, sourceBoard, fullThumb, fullMedia, pageLimbo);
        } catch(ClassNotFoundException e) {
            throw new BoardInitException("Error initializing dumper engine " + dumperEngine + ", no such engine?");
        } catch(Exception e) {
            throw new BoardInitException("Error initializing dumper engine " + dumperEngine);
        }
        dumper.initDumper(bSet);
    }
View Full Code Here

TOP

Related Classes of net.easymodo.asagi.exception.BoardInitException

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.