001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }