c3p0.properties .vs. c3p0-config.xml_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > c3p0.properties .vs. c3p0-config.xml

c3p0.properties .vs. c3p0-config.xml

 2013/11/28 0:29:25  seavers  程序员俱乐部  我要评论(0)
  • 摘要:摘自c3p0.jar,方便查看//c3p0.properties##Thisfileisdetritusfromvarioustestingattempts#thevaluesbelowmaychange,andoftendonotrepresent#reasonablevaluesfortheparameters.##c3p0.testConnectionOnCheckout=true#c3p0.testConnectionOnCheckin=true#c3p0
  • 标签:XML

?

摘自c3p0.jar,方便查看

//c3p0.properties

#
#Thisfileisdetritusfromvarioustestingattempts
#thevaluesbelowmaychange
,andoftendonotrepresent
#reasonablevaluesfortheparameters.
#

#c3p0.testConnectionOnCheckout
=true
#c3p0.testConnectionOnCheckin
=true
#c3p0.minPoolSize
=3
#c3p0.maxPoolSize
=20
#c3p0.checkoutTimeout
=2000
#c3p0.idleConnectionTestPeriod
=5
#c3p0.maxConnectionAge
=10
#c3p0.maxIdleTime
=2
#c3p0.maxIdleTimeExcessConnections
=1
#c3p0.propertyCycle
=1
#c3p0.numHelperThreads
=10
#c3p0.unreturnedConnectionTimeout
=15
#c3p0.debugUnreturnedConnectionStackTraces
=true
#c3p0.maxStatements
=30
#c3p0.maxStatementsPerConnection
=5
#c3p0.maxAdministrativeTaskTime
=3
#c3p0.preferredTestQuery
=SELECT1
#c3p0.preferredTestQuery
=SELECTaFROMemptyyukyukWHEREa=5
#c3p0.preferredTestQuery
=SELECTaFROMtestpbdsWHEREa=5
#c3p0.usesTraditionalReflectiveProxies
=true
#c3p0.automaticTestTable
=PoopyTestTable
#c3p0.acquireIncrement
=4
#c3p0.acquireRetryDelay
=1000
#c3p0.acquireRetryAttempts
=60
#c3p0.connectionTesterClassName
=com.mchange.v2.c3p0.test.AlwaysFailConnectionTester
#c3p0.initialPoolSize
=10

c3p0.jdbcUrl
=jdbc:postgresql://localhost/c3p0-test
c3p0.driverClass
=org.postgresql.Driver
c3p0.user
=swaldman
c3p0.password
=test
#c3p0.user
=poop
#c3p0.password
=scoop

#com.mchange.v2.log.MLog
=com.mchange.v2.log.log4j.Log4jMLog
#com.mchange.v2.log.MLog
=com.mchange.v2.log.jdk14logging.Jdk14MLog
#com.mchange.v2.log.MLog
=com.mchange.v2.log.FallbackMLog
#com.mchange.v2.log.NameTransformer
=com.mchange.v2.log.PackageNames
#com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL
=ALL


#com.mchange.v2.c3p0.VMID
=poop

?

?

//c3p0-config.xml

<c3p0-config>
<default-config>
<!--<propertyname="automaticTestTable">con_test</property>-->
<!--<propertyname="checkoutTimeout">30000</property>-->
<!--<propertyname="idleConnectionTestPeriod">30</property>-->
<!--<propertyname="initialPoolSize">10</property>-->
<!--<propertyname="maxIdleTime">30</property>-->
<!--<propertyname="maxIdleTimeExcessConnections">10</property>-->
<!--<propertyname="maxConnectionAge">60</property>-->
<!--<propertyname="propertyCycle">1</property>-->
<!--<propertyname="maxPoolSize">25</property>-->
<!--<propertyname="minPoolSize">5</property>-->
<!--<propertyname="maxStatements">0</property>-->
<!--<propertyname="maxStatementsPerConnection">5</property>-->
<!--<propertyname="maxAdministrativeTaskTime">4</property>-->
<!--<propertyname="connectionCustomizerClassName">com.mchange.v2.c3p0.test.TestConnectionCustomizer</property>-->
<!--<propertyname="unreturnedConnectionTimeout">15</property>-->
<!--<propertyname="debugUnreturnedConnectionStackTraces">true</property>-->

<!--
<user-overridesuser="swaldman">
<propertyname="debugUnreturnedConnectionStackTraces">true</property>
</user-overrides>
-->

</default-config>

<!--
<named-configname="dumbTestConfig">
<propertyname="maxStatements">200</property>
<propertyname="jdbcUrl">jdbc:test</property>
<user-overridesuser="poop">
<propertyname="maxStatements">300</property>
</user-overrides>
</named-config>
-->

</c3p0-config>


?

?

//解析properties

?

/**//*
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/



packagecom.mchange.v2.c3p0.cfg;

importjava.io.*;
importjava.lang.reflect.*;
importjava.util.*;
importcom.mchange.v2.cfg.*;
importcom.mchange.v2.log.*;
importcom.mchange.v2.c3p0.impl.*;

publicfinalclassC3P0ConfigUtils
...{
publicfinalstaticStringPROPS_FILE_RSRC_PATH="/c3p0.properties";
publicfinalstaticStringPROPS_FILE_PROP_PFX="c3p0.";
publicfinalstaticintPROPS_FILE_PROP_PFX_LEN=5;

privatefinalstaticString[]MISSPELL_PFXS=...{"/c3pO","/c3po","/C3P0","/C3PO"};

finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigUtils.class);

static
...{
if(logger.isLoggable(MLevel.WARNING)&&C3P0ConfigUtils.class.getResource(PROPS_FILE_RSRC_PATH)==null)
...{
//warnonamisspelling...itsanuglywaytodothis,butsinceresourcesarenotlistable...
for(inti=0;i<MISSPELL_PFXS.length;++i)
...{
Stringtest
=MISSPELL_PFXS[i]+".properties";
if(C3P0ConfigUtils.class.getResource(MISSPELL_PFXS[i]+".properties")!=null)
...{
logger.warning(
"POSSIBLYMISSPELLEDc3p0.propertiesCONFIGRESOURCEFOUND."+
"Pleaseensurethefilenameisc3p0.properties,alllowercase,"+
"withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+
"inthetoplevelofc3p0'seffectiveclasspath.");
break;
}

}

}

}


publicstaticHashMapextractHardcodedC3P0Defaults(booleanstringify)
...{
HashMapout
=newHashMap();

try
...{
Method[]methods
=C3P0Defaults.class.getMethods();
for(inti=0,len=methods.length;i<len;++i)
...{
Methodm
=methods[i];
intmods=m.getModifiers();
if((mods&Modifier.PUBLIC)!=0&&(mods&Modifier.STATIC)!=0&&m.getParameterTypes().length==0)
...{
if(stringify)
...{
Objectval
=m.invoke(null,null);
if(val!=null)
out.put(m.getName(),String.valueOf(val));
}

else
out.put(m.getName(),m.invoke(
null,null));
}

}

}

catch(Exceptione)
...{
logger.log(MLevel.WARNING,
"Failedtoextracthardcodeddefaultconfig!?",e);
}


returnout;
}


publicstaticHashMapextractHardcodedC3P0Defaults()
...{returnextractHardcodedC3P0Defaults(true);}

publicstaticHashMapextractC3P0PropertiesResources()
...{
HashMapout
=newHashMap();

//Propertiesprops=findResourceProperties();
//props.putAll(findAllC3P0Properties());

Propertiesprops
=findAllC3P0Properties();
for(Iteratorii=props.keySet().iterator();ii.hasNext();)
...{
Stringkey
=(String)ii.next();
Stringval
=(String)props.get(key);
if(key.startsWith(PROPS_FILE_PROP_PFX))
out.put(key.substring(PROPS_FILE_PROP_PFX_LEN).trim(),val.trim());
}


returnout;
}


publicstaticC3P0ConfigconfigFromFlatDefaults(HashMapflatDefaults)
...{
NamedScopedefaults
=newNamedScope();
defaults.props.putAll(flatDefaults);

HashMapconfigNamesToNamedScopes
=newHashMap();

returnnewC3P0Config(defaults,configNamesToNamedScopes);
}


publicstaticStringgetPropFileConfigProperty(Stringprop)
...{returnMultiPropertiesConfig.readVmConfig().getProperty(prop);}

privatestaticPropertiesfindResourceProperties()
...{returnMultiPropertiesConfig.readVmConfig().getPropertiesByResourcePath(PROPS_FILE_RSRC_PATH);}

privatestaticPropertiesfindAllC3P0Properties()
...{returnMultiPropertiesConfig.readVmConfig().getPropertiesByPrefix("c3p0");}

staticPropertiesfindAllC3P0SystemProperties()
...{
Propertiesout
=newProperties();

SecurityExceptionsampleExc
=null;
try
...{
for(Iteratorii=C3P0Defaults.getKnownProperties().iterator();ii.hasNext();)
...{
Stringkey
=(String)ii.next();
StringprefixedKey
="c3p0."+key;
Stringvalue
=System.getProperty(prefixedKey);
if(value!=null&&value.trim().length()>0)
out.put(key,value);
}

}

catch(SecurityExceptione)
...{sampleExc=e;}

returnout;
}


privateC3P0ConfigUtils()
...{}
}


?

?

//解析xml

?

/**//*
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/



packagecom.mchange.v2.c3p0.cfg;

importjava.io.*;
importjava.util.*;
importjavax.xml.parsers.*;
importorg.w3c.dom.*;
importcom.mchange.v2.log.*;

importcom.mchange.v1.xml.DomParseUtils;

publicfinalclassC3P0ConfigXmlUtils
...{
publicfinalstaticStringXML_CONFIG_RSRC_PATH="/c3p0-config.xml";

finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigXmlUtils.class);

publicfinalstaticStringLINESEP;

privatefinalstaticString[]MISSPELL_PFXS=...{"/c3p0","/c3pO","/c3po","/C3P0","/C3PO"};
privatefinalstaticchar[]MISSPELL_LINES=...{'-','_'};
privatefinalstaticString[]MISSPELL_CONFIG=...{"config","CONFIG"};
privatefinalstaticString[]MISSPELL_XML=...{"xml","XML"};

//itsanuglywaytodothis,butsinceresourcesarenotlistable...
//
//thisisonlyexecutedonce,anddoesabout40tests(fornow)
//shouldIcareaboutthecostininitializationtime?
//
//shouldonlyberunifwe'vecheckedforthecorrectfile,but
//notfoundit
privatefinalstaticvoidwarnCommonXmlConfigResourceMisspellings()
...{
if(logger.isLoggable(MLevel.WARNING))
...{
for(inta=0,lena=MISSPELL_PFXS.length;a<lena;++a)
...{
StringBuffersb
=newStringBuffer(16);
sb.append(MISSPELL_PFXS[a]);
for(intb=0,lenb=MISSPELL_LINES.length;b<lenb;++b)
...{
sb.append(MISSPELL_LINES[b]);
for(intc=0,lenc=MISSPELL_CONFIG.length;c<lenc;++c)
...{
sb.append(MISSPELL_CONFIG[c]);
sb.append(
'.');
for(intd=0,lend=MISSPELL_XML.length;d<lend;++d)
...{
sb.append(MISSPELL_XML[d]);
Stringtest
=sb.toString();
if(!test.equals(XML_CONFIG_RSRC_PATH))
...{
ObjecthopefullyNull
=C3P0ConfigXmlUtils.class.getResource(test);
if(hopefullyNull!=null)
...{
logger.warning(
"POSSIBLYMISSPELLEDc3p0-conf.xmlRESOURCEFOUND."+
"Pleaseensurethefilenameisc3p0-config.xml,alllowercase,"+
"withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+
"inthetoplevelofc3p0'seffectiveclasspath.");
return;
}

}

}

}


}

}

}

}


static
...{
Stringls;

try
...{ls=System.getProperty("line.separator","");}
catch(Exceptione)
...{ls="";}

LINESEP
=ls;

}


publicstaticC3P0ConfigextractXmlConfigFromDefaultResource()throwsException
...{
InputStreamis
=null;

try
...{
is
=C3P0ConfigUtils.class.getResourceAsStream(XML_CONFIG_RSRC_PATH);
if(is==null)
...{
warnCommonXmlConfigResourceMisspellings();
returnnull;
}

else
returnextractXmlConfigFromInputStream(is);
}

finally
...{
try...{if(is!=null)is.close();}
catch(Exceptione)
...{
if(logger.isLoggable(MLevel.FINE))
logger.log(MLevel.FINE,
"ExceptiononresourceInputStreamclose.",e);
}

}

}


publicstaticC3P0ConfigextractXmlConfigFromInputStream(InputStreamis)throwsException
...{
DocumentBuilderFactoryfact
=DocumentBuilderFactory.newInstance();
DocumentBuilderdb
=fact.newDocumentBuilder();
Documentdoc
=db.parse(is);

returnextractConfigFromXmlDoc(doc);
}


publicstaticC3P0ConfigextractConfigFromXmlDoc(Documentdoc)throwsException
...{
ElementdocElem
=doc.getDocumentElement();
if(docElem.getTagName().equals("c3p0-config"))
...{
NamedScopedefaults;
HashMapconfigNamesToNamedScopes
=newHashMap();

ElementdefaultConfigElem
=DomParseUtils.uniqueChild(docElem,"default-config");
if(defaultConfigElem!=null)
defaults
=extractNamedScopeFromLevel(defaultConfigElem);
else
defaults
=newNamedScope();
NodeListnl
=DomParseUtils.immediateChildElementsByTagName(docElem,"named-config");
for(inti=0,len=nl.getLength();i<len;++i)
...{
ElementnamedConfigElem
=(Element)nl.item(i);
StringconfigName
=namedConfigElem.getAttribute("name");
if(configName!=null&&configName.length()>0)
...{
NamedScopenamedConfig
=extractNamedScopeFromLevel(namedConfigElem);
configNamesToNamedScopes.put(configName,namedConfig);
}

else
logger.warning(
"ConfigurationXMLcontainednamed-configelementwithoutnameattribute:"+namedConfigElem);
}

returnnewC3P0Config(defaults,configNamesToNamedScopes);
}

else
thrownewException("Rootelementofc3p0configxmlshouldbe'c3p0-config',not'"+docElem.getTagName()+"'.");
}


privatestaticNamedScopeextractNamedScopeFromLevel(Elementelem)
...{
HashMapprops
=extractPropertiesFromLevel(elem);
HashMapuserNamesToOverrides
=newHashMap();

NodeListnl
=DomParseUtils.immediateChildElementsByTagName(elem,"user-overrides");
for(inti=0,len=nl.getLength();i<len;++i)
...{
ElementperUserConfigElem
=(Element)nl.item(i);
StringuserName
=perUserConfigElem.getAttribute("user");
if(userName!=null&&userName.length()>0)
...{
HashMapuserProps
=extractPropertiesFromLevel(perUserConfigElem);
userNamesToOverrides.put(userName,userProps);
}

else
logger.warning(
"ConfigurationXMLcontaineduser-overrideselementwithoutuserattribute:"+LINESEP+perUserConfigElem);
}


returnnewNamedScope(props,userNamesToOverrides);
}


privatestaticHashMapextractPropertiesFromLevel(Elementelem)
...{
//System.err.println("extractPropertiesFromLevel()");

HashMapout
=newHashMap();

try
...{
NodeListnl
=DomParseUtils.immediateChildElementsByTagName(elem,"property");
intlen=nl.getLength();
for(inti=0;i<len;++i)
...{
ElementpropertyElem
=(Element)nl.item(i);
StringpropName
=propertyElem.getAttribute("name");
if(propName!=null&&propName.length()>0)
...{
StringpropVal
=DomParseUtils.allTextFromElement(propertyElem,true);
out.put(propName,propVal);
//System.err.println(propName+"->"+propVal);
}

else
logger.warning(
"ConfigurationXMLcontainedpropertyelementwithoutnameattribute:"+LINESEP+propertyElem);
}

}

catch(Exceptione)
...{
logger.log(MLevel.WARNING,
"AnexceptionoccurredwhilereadingconfigXML."+
"Someconfigurationinformationhasprobablybeenignored.",
e);
}


returnout;
}


privateC3P0ConfigXmlUtils()
...{}
}


?

?

/**//*
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/



packagecom.mchange.v1.xml;

importjava.util.*;
importorg.xml.sax.*;
importorg.w3c.dom.*;
importcom.mchange.v1.util.DebugUtils;

publicfinalclassDomParseUtils
...{
finalstaticbooleanDEBUG=true;

/***//**
*
@returnnullifchilddoesn'texist.
*/

publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName)
throwsDOMException
...{returnallTextFromUniqueChild(elem,childTagName,false);}

/***//**
*
@returnnullifchilddoesn'texist.
*/

publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName,booleantrim)
throwsDOMException
...{
ElementuniqueChild
=uniqueChildByTagName(elem,childTagName);
if(uniqueChild==null)
returnnull;
else
returnDomParseUtils.allTextFromElement(uniqueChild,trim);
}


publicstaticElementuniqueChild(Elementelem,StringchildTagName)throwsDOMException
...{returnuniqueChildByTagName(elem,childTagName);}

/***//**
*
@deprecateduseuniqueChild(Elementelem,StringchildTagName)
*/

publicstaticElementuniqueChildByTagName(Elementelem,StringchildTagName)throwsDOMException
...{
NodeListnl
=elem.getElementsByTagName(childTagName);
intlen=nl.getLength();
if(DEBUG)
DebugUtils.myAssert(len
<=1,
"Thereismorethanone("+len+")childwithtagname:"+
childTagName
+"!!!");
return(len==1?(Element)nl.item(0):null);
}


publicstaticStringallText(Elementelem)throwsDOMException
...{returnallTextFromElement(elem);}

publicstaticStringallText(Elementelem,booleantrim)throwsDOMException
...{returnallTextFromElement(elem,trim);}

/***//**@deprecateduseallText(Elementelem)*/
publicstaticStringallTextFromElement(Elementelem)throwsDOMException
...{returnallTextFromElement(elem,false);}

/***//**@deprecateduseallText(Elementelem,booleantrim)*/
publicstaticStringallTextFromElement(Elementelem,booleantrim)throwsDOMException
...{
StringBuffertextBuf
=newStringBuffer();
NodeListnl
=elem.getChildNodes();
for(intj=0,len=nl.getLength();j<len;++j)
...{
Nodenode
=nl.item(j);
if(nodeinstanceofText)//includesTextandCDATA!
textBuf.append(node.getNodeValue());
}

Stringout
=textBuf.toString();
return(trim?out.trim():out);
}


publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName)
throwsDOMException
...{returnallTextFromImmediateChildElements(parent,tagName,false);}

publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName,booleantrim)
throwsDOMException
...{
NodeListnl
=immediateChildElementsByTagName(parent,tagName);
intlen=nl.getLength();
String[]out
=newString[len];
for(inti=0;i<len;++i)
out[i]
=allText((Element)nl.item(i),trim);
returnout;
}



publicstaticNodeListimmediateChildElementsByTagName(Elementparent,StringtagName)
throwsDOMException
...{returngetImmediateChildElementsByTagName(parent,tagName);}

/***//**
*
@deprecateduseimmediateChildrenByTagName(Elementparent,StringtagName)
*/

publicstaticNodeListgetImmediateChildElementsByTagName(Elementparent,StringtagName)
throwsDOMException
...{
finalListnodes=newArrayList();
for(Nodechild=parent.getFirstChild();child!=null;child=child.getNextSibling())
if(childinstanceofElement&&((Element)child).getTagName().equals(tagName))
nodes.add(child);
returnnewNodeList()
...{
publicintgetLength()
...{returnnodes.size();}

publicNodeitem(inti)
...{return(Node)nodes.get(i);}
}
;
}


publicstaticStringallTextFromUniqueImmediateChild(Elementelem,StringchildTagName)
throwsDOMException
...{
ElementuniqueChild
=uniqueImmediateChildByTagName(elem,childTagName);
if(uniqueChild==null)
returnnull;
returnDomParseUtils.allTextFromElement(uniqueChild);
}


publicstaticElementuniqueImmediateChild(Elementelem,StringchildTagName)
throwsDOMException
...{returnuniqueImmediateChildByTagName(elem,childTagName);}

/***//**
*
@deprecateduseuniqueImmediateChild(Elementelem,StringchildTagName)
*/

publicstaticElementuniqueImmediateChildByTagName(Elementelem,StringchildTagName)
throwsDOMException
...{
NodeListnl
=getImmediateChildElementsByTagName(elem,childTagName);
intlen=nl.getLength();
if(DEBUG)
DebugUtils.myAssert(len
<=1,
"Thereismorethanone("+len+")childwithtagname:"+
childTagName
+"!!!");
return(len==1?(Element)nl.item(0):null);
}


/***//**
*
@deprecateduseElement.getAttribute(Stringval)
*/

publicstaticStringattrValFromElement(Elementelement,StringattrName)
throwsDOMException
...{
Attrattr
=element.getAttributeNode(attrName);
return(attr==null?null:attr.getValue());
}


privateDomParseUtils()
...{}
}


?

?

?

?

?

?

发表评论
用户名: 匿名