001    /**
002     * Copyright (c) 2000-2010 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            public void checkQuartzTables() throws SystemException {
035                    Connection con = null;
036                    PreparedStatement ps = null;
037                    ResultSet rs = null;
038    
039                    try {
040                            con = DataAccess.getConnection();
041    
042                            ps = con.prepareStatement(
043                                    "select count(*) from QUARTZ_JOB_DETAILS");
044    
045                            rs = ps.executeQuery();
046    
047                            if (rs.next()) {
048                                    return;
049                            }
050                    }
051                    catch (Exception e) {
052                            if (_log.isWarnEnabled()) {
053                                    _log.warn(e.getMessage());
054                            }
055                    }
056                    finally {
057                            DataAccess.cleanUp(con, ps, rs);
058                    }
059    
060                    DB db = DBFactoryUtil.getDB();
061    
062                    try {
063                            db.runSQLTemplate("quartz-tables.sql", false);
064                    }
065                    catch (Exception e) {
066                            throw new SystemException(e);
067                    }
068            }
069    
070            private static Log _log = LogFactoryUtil.getLog(
071                    QuartzLocalServiceImpl.class);
072    
073    }