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 key to {@link JdbcProperty} instance if {@link #key} field equal the argument {@code key}, 050 * otherwise return {@code null} 051 */ 052 public static final JdbcProperty fromKey(String key){ 053 for(JdbcProperty p: values()){ 054 if(p.key.equals(key)){ 055 return p; 056 } 057 } 058 return null; 059 } 060 061 } 062 063 /** 064 * Update strategy for cache 065 */ 066 enum UpdateStrategy{ 067 /** update no matter whether key exists */ 068 always, 069 /** update only if key exists */ 070 replace, 071 /** remove key */ 072 remove, 073 /** reload data form database if key exists,and update */ 074 refresh 075 } 076 077 UpdateStrategy DEFAULT_STRATEGY = UpdateStrategy.always; 078 long DEFAULT_CACHE_MAXIMUMSIZE = 10000; 079 long DEFAULT_DURATION = 10; 080 TimeUnit DEFAULT_TIME_UNIT = TimeUnit.MINUTES; 081 public static final String RETRIEVE_SUFFIX="generatedkey.retrieve"; 082 public static final String STATEMENT_SUFFIX="generatedkey.statement"; 083}