001package gu.sql2java;
002
003import java.util.concurrent.TimeUnit;
004
005/**
006 * constant declare
007 * @author guyadong
008 */
009public interface Constant {    
010    public static final int STATE_BIT_NUM = 32;
011    public static final int STATE_BIT_SHIFT = 5;
012    public static final int STATE_BIT_MASK = 0x1f;
013
014    public static final String SQL_LIKE_WILDCARD = "%";
015    /** set =QUERY for loadUsingTemplate */
016    public static final int SEARCH_EXACT = 0;
017    /** set %QUERY% for loadLikeTemplate */
018    public static final int SEARCH_LIKE = 1;
019    /** set %QUERY for loadLikeTemplate */
020    public static final int SEARCH_STARTING_LIKE = 2;
021    /** set QUERY% for loadLikeTemplate */
022    public static final int SEARCH_ENDING_LIKE = 3;
023
024    /** JDBC property name definition */
025    public static enum JdbcProperty{
026        /** debug status */DEBUG("isDebug"),
027        /** JDBC driver class name */JDBC_DRIVER("jdbc.driver"),
028        /** JDBC connection url */JDBC_URL("jdbc.url"),
029        /** JDBC user name */JDBC_USERNAME("jdbc.username"),
030        /** JDBC password */JDBC_PASSWORD("jdbc.password"),
031        /** Retrieval type of auto generated key:auto,before,after */GENERATEDKEY_RETRIEVE("generatedkey.retrieve"),
032        /** Retrieval statement of auto generated key */GENERATEDKEY_STATEMENT("generatedkey.statement"),
033        /** data source type, c3p0 supported only now */DATASOURCE("datasource"),
034        /** c3p0 property */C3P0_MINPOOLSIZE("c3p0.minPoolSize"),
035        /** c3p0 property */C3P0_MAXPOOLSIZE("c3p0.maxPoolSize"),
036        /** c3p0 property */C3P0_MAXIDLETIME("c3p0.maxIdleTime"),
037        /** c3p0 property */C3P0_IDLECONNECTIONTESTPERIOD("c3p0.idleConnectionTestPeriod");
038        /** JDBC property name */
039        public final String key;
040        
041        JdbcProperty(String key){
042            this.key = key;
043        }
044        /** return {@link #key} with {@code prefix} */
045        public String withPrefix(String prefix){
046            return new StringBuffer().append(prefix).append(key).toString();
047        }
048        /** 
049         * cast {@code key} to {@link JdbcProperty} instance if {@link #key} field equal the argument {@code key},
050         * otherwise return {@code null} 
051         * @param key JDBC property name
052         */
053        public static final JdbcProperty fromKey(String key){
054            for(JdbcProperty p: values()){
055                if(p.key.equals(key)){
056                    return p;
057                }
058            }
059            return null;
060        }
061
062    }
063
064        /** 
065         * Update strategy for cache
066         */
067        enum UpdateStrategy{        
068            /** update no matter whether key exists */
069            always,
070            /** update only if key exists */
071            replace,
072            /** remove key  */
073            remove,
074            /** reload data form database if key exists,and update  */
075            refresh
076        }
077        /** 默认缓存更新策略 */
078        UpdateStrategy DEFAULT_STRATEGY = UpdateStrategy.always;
079        /** 默认缓存最大缓存容量 */
080        long DEFAULT_CACHE_MAXIMUMSIZE = 10000;
081        /** 默认缓存失败时间 */
082        long DEFAULT_DURATION = 10;
083        /** 默认缓存失败时间单位 */
084        TimeUnit DEFAULT_TIME_UNIT = TimeUnit.MINUTES;
085        public static final String RETRIEVE_SUFFIX = "generatedkey.retrieve";
086        public static final String STATEMENT_SUFFIX = "generatedkey.statement";
087}