001package org.apache.commons.jcs.auxiliary.disk.jdbc.mysql;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes;
023
024/**
025 * This has additional attributes that are particular to the MySQL disk cache.
026 * <p>
027 * @author Aaron Smuts
028 */
029public class MySQLDiskCacheAttributes
030    extends JDBCDiskCacheAttributes
031{
032    /** Don't change. */
033    private static final long serialVersionUID = -6535808344813320061L;
034
035    /**
036     * For now this is a simple comma delimited list of HH:MM:SS times to optimize
037     * the table. If none is supplied, then no optimizations will be performed.
038     * <p>
039     * In the future we can add a chron like scheduling system. This is to meet
040     * a pressing current need.
041     * <p>
042     * 03:01,15:00 will cause the optimizer to run at 3 am and at 3 pm.
043     */
044    private String optimizationSchedule = null;
045
046    /**
047     * If true, we will balk, that is return null during optimization rather than block.
048     */
049    public static final boolean DEFAULT_BALK_DURING_OPTIMIZATION = true;
050
051    /**
052     * If true, we will balk, that is return null during optimization rather than block.
053     * <p>
054     * <a href="http://en.wikipedia.org/wiki/Balking_pattern">Balking</a>
055     */
056    private boolean balkDuringOptimization = DEFAULT_BALK_DURING_OPTIMIZATION;
057
058    /**
059     * @param optimizationSchedule The optimizationSchedule to set.
060     */
061    public void setOptimizationSchedule( String optimizationSchedule )
062    {
063        this.optimizationSchedule = optimizationSchedule;
064    }
065
066    /**
067     * @return Returns the optimizationSchedule.
068     */
069    public String getOptimizationSchedule()
070    {
071        return optimizationSchedule;
072    }
073
074    /**
075     * @param balkDuringOptimization The balkDuringOptimization to set.
076     */
077    public void setBalkDuringOptimization( boolean balkDuringOptimization )
078    {
079        this.balkDuringOptimization = balkDuringOptimization;
080    }
081
082    /**
083     * Should we return null while optimizing the table.
084     * <p>
085     * @return Returns the balkDuringOptimization.
086     */
087    public boolean isBalkDuringOptimization()
088    {
089        return balkDuringOptimization;
090    }
091
092    /**
093     * For debugging.
094     * <p>
095     * @return debug string
096     */
097    @Override
098    public String toString()
099    {
100        StringBuilder buf = new StringBuilder();
101        buf.append( "\nMySQLDiskCacheAttributes" );
102        buf.append( "\n OptimizationSchedule [" + getOptimizationSchedule() + "]" );
103        buf.append( "\n BalkDuringOptimization [" + isBalkDuringOptimization() + "]" );
104        buf.append( super.toString() );
105        return buf.toString();
106    }
107}