001    /**
002     * Copyright (c) 2000-2013 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.service.impl;
016    
017    import com.liferay.portal.kernel.dao.db.DB;
018    import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
019    import com.liferay.portal.kernel.dao.jdbc.DataAccess;
020    import com.liferay.portal.kernel.exception.SystemException;
021    import com.liferay.portal.kernel.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    import com.liferay.portal.service.base.QuartzLocalServiceBaseImpl;
024    
025    import java.sql.Connection;
026    import java.sql.PreparedStatement;
027    import java.sql.ResultSet;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     */
032    public class QuartzLocalServiceImpl extends QuartzLocalServiceBaseImpl {
033    
034            @Override
035            public void checkQuartzTables() throws SystemException {
036                    Connection con = null;
037                    PreparedStatement ps = null;
038                    ResultSet rs = null;
039    
040                    try {
041                            con = DataAccess.getConnection();
042    
043                            ps = con.prepareStatement(
044                                    "select count(*) from QUARTZ_JOB_DETAILS");
045    
046                            rs = ps.executeQuery();
047    
048                            if (rs.next()) {
049                                    return;
050                            }
051                    }
052                    catch (Exception e) {
053                            if (_log.isWarnEnabled()) {
054                                    _log.warn(e, e);
055                            }
056                    }
057                    finally {
058                            DataAccess.cleanUp(con, ps, rs);
059                    }
060    
061                    DB db = DBFactoryUtil.getDB();
062    
063                    try {
064                            db.runSQLTemplate("quartz-tables.sql", false);
065                    }
066                    catch (Exception e) {
067                            throw new SystemException(e);
068                    }
069            }
070    
071            private static Log _log = LogFactoryUtil.getLog(
072                    QuartzLocalServiceImpl.class);
073    
074    }