001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.dao.db;
016    
017    import java.io.IOException;
018    
019    import java.sql.Connection;
020    import java.sql.SQLException;
021    
022    import javax.naming.NamingException;
023    
024    /**
025     * @author Hugo Huijser
026     * @author Brian Wing Shun Chan
027     */
028    public abstract class BaseDBProcess implements DBProcess {
029    
030            public BaseDBProcess() {
031            }
032    
033            @Override
034            public void runSQL(Connection connection, String template)
035                    throws IOException, SQLException {
036    
037                    DB db = DBFactoryUtil.getDB();
038    
039                    db.runSQL(connection, template);
040            }
041    
042            @Override
043            public void runSQL(String template) throws IOException, SQLException {
044                    DB db = DBFactoryUtil.getDB();
045    
046                    if (connection == null) {
047                            db.runSQL(template);
048                    }
049                    else {
050                            db.runSQL(connection, template);
051                    }
052            }
053    
054            @Override
055            public void runSQL(String[] templates) throws IOException, SQLException {
056                    DB db = DBFactoryUtil.getDB();
057    
058                    if (connection == null) {
059                            db.runSQL(templates);
060                    }
061                    else {
062                            db.runSQL(connection, templates);
063                    }
064            }
065    
066            @Override
067            public void runSQLTemplate(String path)
068                    throws IOException, NamingException, SQLException {
069    
070                    DB db = DBFactoryUtil.getDB();
071    
072                    db.runSQLTemplate(path);
073            }
074    
075            @Override
076            public void runSQLTemplate(String path, boolean failOnError)
077                    throws IOException, NamingException, SQLException {
078    
079                    DB db = DBFactoryUtil.getDB();
080    
081                    db.runSQLTemplate(path, failOnError);
082            }
083    
084            @Override
085            public void runSQLTemplateString(
086                            String template, boolean evaluate, boolean failOnError)
087                    throws IOException, NamingException, SQLException {
088    
089                    DB db = DBFactoryUtil.getDB();
090    
091                    if (connection == null) {
092                            db.runSQLTemplateString(template, evaluate, failOnError);
093                    }
094                    else {
095                            db.runSQLTemplateString(
096                                    connection, template, evaluate, failOnError);
097                    }
098            }
099    
100            protected Connection connection;
101    
102    }