锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 綾誨瀷鍚嶇О 鏈灝忓?32768錛?215錛夛紝鏈澶у?2767錛?15-1錛?/p>
-263~(263-1) 1.4E-45~3.4028235E38
]]>
byte
data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte
data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int
where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation. short
data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte
, the same guidelines apply: you can use a short
to save memory in large arrays, in situations where the memory savings actually matters. int
data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long
instead. long
data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int
. float
data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in section 4.2.3 of the Java Language Specification. As with the recommendations for byte
and short
, use a float
(instead of double
) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal
and other useful classes provided by the Java platform. double
data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in section 4.2.3 of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency. boolean
data type has only two possible values: true
and false
. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined. char
data type is a single 16-bit Unicode character. It has a minimum value of '\u0000'
(or 0) and a maximum value of '\uffff'
(or 65,535 inclusive).
綾誨瀷瀹氫箟
綾誨瀷鍙栧?/strong>
boolean
甯冨皵鍊?/td>
true, false
byte
8浣?strong>鏈夌鍙鋒暣鏁?/strong>
鏈灝忓?128錛屾渶澶у?27
short
16浣?strong>鏈夌鍙鋒暣鏁?/strong>
int
32浣?strong>鏈夌鍙鋒暣鏁?/strong>
鏈灝忓?2147483648錛?231錛夛紝鏈澶у?147483647錛?31-1錛?/td>
long
64浣?strong>鏈夌鍙鋒暣鏁?/strong>
float
32浣嶆誕鐐規(guī)暟
double
64浣嶆誕鐐規(guī)暟
4.9E-324~1.7976931348623157E308
char
16浣峌nicode瀛楃
]]>
Note that thanks to the Session, which is also a transaction-scoped cache, Hibernate provides repeatable reads for lookup by identifier and entity queries (not reporting queries that return scalar values).
Hibernate 娌℃湁鎻愪緵鍦ㄥ唴瀛樹腑瀵瑰璞″姞閿佺殑鍔熻兘錛屽洜姝ゅ簲鐢ㄧ殑浜嬪姟闅旂綰у埆鏄畬鍏ㄧ敱鏁版嵁搴撴潵鎻愪緵鐨勩?/strong>
鍊熷姪浜巗ession錛孒ibernate 鎻愪緵浜嗗彲閲嶅璇葷殑浜嬪姟闅旂綰у埆錛屼絾鏄墠鎻愭槸鍙湁浣跨敤identifier and entity queries鐨勫彲浠ワ紝浣跨敤鏍囬噺鏌ヨ鍒欎笉鍙互錛屽叾鍘熷洜鏄痟ibernate鐨刢ache鐨勫璞¢渶瑕佹槸鑳藉琚敮涓璇嗗埆鐨勫疄浣撳璞★紝鏍囬噺鏌ヨ榪斿洖鐨勭粨鏋滄槸鏁扮粍錛屼笉婊¤凍璇ヨ姹傦紝鏃犳硶鍦╯ession綰у埆榪涜浜嬪姟鐨刢ache
鍦ㄤ簨鍔″拰騫跺彂鎬ф柟闈紝hibernate涓嶄粎鎻愪緵浜嗗熀浜庣増鏈殑鎺у埗鐨勮嚜鍔ㄤ箰瑙傞攣鏈哄埗錛屽悓鏃惰繕鎻愪緵浜咥PI鏉ュ疄鐜版?zhèn)茶閿佹満鍒跺Q堥氳繃SELECT FOR UPDATE 璇硶錛?/strong>
A SessionFactory is an expensive-to-create, threadsafe object intended to be shared by all application threads. It is created once, usually on application startup, from a Configuration instance.
A Session is an inexpensive, non-threadsafe object that should be used once, for a single request, a conversation, single unit of work, and then discarded. A Session will not obtain a JDBC Connection (or a Datasource) unless it is needed, hence consume no resources until used.
Database transactions are never optional, all communication with a database has to occur inside a transaction, no matter if you read or write data.
浜嬪姟騫朵笉鏄彲鏈夊彲鏃犵殑錛屾墍鏈夌殑鏁版嵁搴撴搷浣滈兘鏄湪浜嬪姟鐜涓嬪彂鐢熺殑錛?strong>涓嶇鏄痳ead 鎿嶄綔榪樻槸write鎿嶄綔銆傝繖鐐逛竴瀹氳鍚嶆槑紜紝浠ュ墠鏇劇粡璇В銆?
As explained, auto-commit behavior for reading data should be avoided, as many small transactions are unlikely to perform better than one clearly defined unit of work. The latter is also much more maintainable and extensible.
鏈濂藉叧闂嚜鍔ㄦ彁浜ゅ姛鑳斤紝鍥犱負(fù)浣跨敤澶ч噺鐨勭煭鏁版嵁搴撲簨鍔″湪鎬ц兘涓婃湭蹇呮瘮涓涓竻鏅板畾涔夌殑unit work寮猴紝鍚庤呮洿鍔犳槗浜庣淮鎶ゅ拰鎵╁睍銆傦紙浠ュ墠鏇劇粡璇В錛?
Hibernate checks instance versions at flush time, throwing an exception if concurrent modification is detected.It's up to the developer to catch and handle this exception (common options are the opportunity for the user to merge changes or to restart the business conversation with non-stale data).
鍦╢lush鐨勬椂鍊欐鏌ersion錛屽鏋滃彂鐜版洿鏀逛細(xì)鎶涘嚭寮傚父錛屽紑鍙戜漢鍛樺彲浠ユ崟鎹夎寮傚父錛屽茍鍐沖畾濡備綍澶勭悊錛堣涔堝悎騫朵慨鏀癸紝瑕佷箞鏀懼純淇敼錛?
鎮(zhèn)茶閿佸熀鏈笂鏄潬鏁版嵁搴撴湰韜彁渚涚殑鏈哄埗鏉ュ疄鐜幫紝閫氬父鍙涓簀dbc connection鎸囧畾浜嬪姟闅旂鐨勭駭鍒嵆鍙俆he LockMode class defines the different lock levels that may be acquired by Hibernate.
鎮(zhèn)茶閿佷細(xì)鍦ㄨ鍙栨暟鎹箣鍓嶈幏鍙栵紝鍥犳鑳藉淇濊瘉褰撳墠浜嬪姟鐨勬暟鎹氨鏄渶鏂版暟鎹?
1銆佹爣閲忔煡璇紙Scalar queries錛夛細(xì)榪斿洖鐨勮褰曟暟緇勭殑闆嗗悎
鏍囬噺鏄笌鏁扮粍鐩稿鐨勬蹇碉紝鏄竴縐嶇敱鍗曚竴鐨勫兼潵琛ㄥ緛鐨勯噺銆傛墍璋撴爣閲忔煡璇紝灝辨槸鐩存帴浣跨敤鍘熺敓sql璇彞鐨勬煡璇紝涔熷嵆榪斿洖鐨勬槸瑁告暟鎹紙鍙笉榪噃ibernate浣跨敤 姣斿 List list = session.createSQLQuery("select * from t_area_person").list(); for (Object object : list) { 2銆佸疄浣撴煡璇?Entity queries)錛氳繑鍥炵殑鏄疄浣撳璞$殑闆嗗悎 3銆丩oad鏂規(guī)硶錛歭ookup by identifier 錛岃繑鍥炵殑鏄identifier 瀵瑰簲鐨勫璞?/strong> 鍙栧弽錛?/strong>~x 涓庢搷浣滐細(xì)AND x & y 鎴栨搷浣滐細(xì)OR 寮傛垨鎿嶄綔錛歑OR 宸︾Щ鎿嶄綔錛歋hift left 灝唜宸︾Щy浣嶏紝縐誨姩榪囩▼涓紝楂樹綅浼?xì)涓㈠? 鏈夌鍙鋒暟鍙崇Щ鎿嶄綔錛歋hift Right - Signed 鏃犵鍙鋒暟鍙崇Щ錛歋hift Right - Unsigned 涓嬮潰鐨勪緥瀛愭樉紺哄浣曞皢涓涓猧nt鏁扮粍閫氳繃縐諱綅鎿嶄綔鍘嬬緝鍒頒竴涓猧nt鍐呬繚瀛橈紝鍏跺師鐞嗘槸鍦╦ava璇█涓紝int綾誨瀷浣跨敤4 bytes鏉ヤ繚瀛橈紝鍥犳瀵逛簬闇瑕佸帇緙╃殑int鏁扮粍錛屽叾涓殑姣忎竴涓猧nt鍊肩殑澶у皬涓嶈兘瓚呰繃255錛?鐨?嬈℃柟-1錛夛紝鍥犳榪欏彧鏄竴涓疄渚嬶細(xì) int [] aRGB = {0x56, 0x78, 0x9A, 0xBC}; // 鏄敤16榪涘埗淇濆瓨鐨?縐嶉鑹插?br> int color_val = aRGB[3]; 鎿嶄綔瀹岀殑緇撴灉鏄?6 78 9A BC 濡傛灉瑕佷粠colorVal 榪樺師涓篿nt鏁扮粍錛屾垨鑰呭緱鍒版暟緇勪腑鐨勬煇涓鹼紝鍙渶瑕佸colorVal 榪涜鐩稿簲鐨勫彸縐繪搷浣滃嵆鍙細(xì) int alpha_val = (colorVal >>> 24) & 0xFF; 鍙傝冭祫鏂欙細(xì) 浜嬪姟綰у埆錛? 1>.READ UNCOMMITTED 鏁堢巼楂?浣嗗彲鑳戒細(xì)鏈夎剰鏁版嵁(淇敼鏁版嵁鏃朵笉鎺掍粬璇?; 2>.READ COMMITTED 閬垮厤浜嗚剰鏁版嵁(淇敼鏁版嵁鏃舵帓浠栬); 3>. REPEATABLE READ 瀵規(guī)弧瓚蟲潯浠剁殑鏁版嵁琛岄泦榪涜閿佸畾錛屼笉鍏佽鍏朵粬浜嬪姟淇敼鍜屽垹闄? 4>.SERIALABLE READ 鏈楂樼駭鍒?紱佹瀵?鏁版嵁琛岄泦鐢氳嚦鏁翠釜鏁版嵁琛級鎻掑叆錛屽洜姝よ兘澶熼槻姝㈠夠褰辮鐨勫彂鐢? 甯哥敤鐨勪簨鍔″睘鎬э細(xì) 1>.Required 蹇呴』榪愯鍦ㄤ簨鍔′腑,娌℃湁鐜版垚鐨勫氨鏂板緩涓涓? 2>.RequiresNew 鎸囨槑姣忔榪愯閮藉繀欏繪柊寤轟竴涓簨鍔? 3>.Supports 濡傜洰鍓嶆澶勪簬浜嬪姟涓殑璇濆氨鍔犲叆鍒頒簨鍔′腑鍘?娌℃湁灝辯畻浜? 4>.Mandatory 蹇呴』鏈変竴涓簨鍔℃鍦ㄨ繍琛岃鍏跺姞鍏?鍚﹀垯鎶涘嚭寮傚父; 5>.NotSupported 涓嶉渶瑕佽繍琛屼簬浠諱綍浜嬪姟涓? 6>.Never 涓嶄絾涓嶄細(xì)榪愯浜庝換浣曚簨鍔′腑,濡傛灉鍙戠幇榪愯鍦ㄤ簨鍔′腑浼?xì)鎶涘嚭寮傚父銆?/p> 浠婂ぉ鐪嬪埌Jakarta Commons Lang錛屽彂鐜版彁渚涗簡寰堝鏈夌敤鐨勫姛鑳?璁板綍涓嬫潵錛岀暀寰呬互鍚庢煡闃?/p> The Commons Lang library provides much needed additions to the standard JDK's java.lang package. Very generic, very reusable components for everyday use. StringEscapeUtils contains methods to escape and unescape Java, JavaScript, HTML, XML and SQL. RandomStringUtils speaks for itself. It's provides ways in which to generate pieces of text, such as might be used for default passwords. CharUtils exists for this purpose, while CharSetUtils exists for set-manipulation of Strings.Be careful, although CharSetUtils takes an argument of type String, it is only as a set of characters. For example, SystemUtils is a simple little class which makes it easy to find out information about which platform you are on銆?/p> The CharEncoding class is also used to interact with the Java environment and may be used to see which character encodings are supported in a particular environment. ClassUtils is largely a set of helper methods for reflection. Of special note are the comparators hidden away in ClassUtils, useful for sorting Class and Package objects by name銆?/p> ArrayUtils. This is a big one with many methods and many overloads of these methods so it is probably worth an in depth look here. Before we begin, assume that every method mentioned is overloaded for all the primitives and for Object. Also, the short-hand 'xxx' implies a generic primitive type, but usually also includes Object. On reaching the end of our package, we are left with a couple of classes that haven't fit any of the topics so far. The BitField class provides a wrapper class around the classic bitmask integer, whilst the Validate class may be used for assertions HashCodeBuilder will save your day. It, and its buddies (EqualsBuilder, CompareToBuilder, ToStringBuilder), take care of the nasty bits while you focus on the important bits, like which fields will go into making up the hashcode. 甯姪鎻愪緵equals銆乧ompare銆乼oString鏂規(guī)硶 These include classes to represent ranges of numbers, a Fraction class, various utilities for random numbers, and the flagship class, NumberUtils which contains a handful of classic number functions. mutable package provides mutable wrappers for primitive values (such as int, long, etc.) and Object. These wrappers are simiar to the wrappers provided by the Java API, but allow the wrapped value to be changed without needing to create a separate wrapper object. It provides, amongst other classes, a replacement for StringBuffer named These include a StopWatch for simple performance measurements and an optimised FastDateFormat class.ResultSetMetaData灝唕esultset涓殑姣忎竴鏉¤褰曟斁鍒頒竴涓暟緇凮bject[]涓?/code>錛夈?/p>
Object[] ob = (Object[]) object;
for (int i = 0; i < ob.length; i++)
System.out.print(" " +ob[i]);
System.out.println();
}
]]>java 浣嶆搷浣滅錛?/strong>
- flips each bit to the opposite value.
- AND operation between the corresponding bits in x and y.
x | y
- OR operation between the corresponding bits in x and y.
x ^ y
- XOR operation between the corresponding bits in x and y.
x << y
- shifts x to the left by y bits. The high order bits are lost while zeros fill the right bits.
x >> y
- shifts x to the right by y bits. The low order bits are lost while the sign bit value (0 for positive numbers, 1 for negative) fills in the left bits.
x >>> y
- shifts x to the right by y bits. The low order bits are lost while zeros fill in the left bits regardless of the sign. 渚嬪瓙錛?/strong>
color_val = color_val | (aRGB[2] << 8); // 涓轟簡鍘嬬緝錛岄渶瑕佹斁緗埌color_val鍊肩殑絎簩涓瓧鑺備綅緗笂錛氬皢aRGB[2] 宸︾Щ鍒扮浜屼釜byte錛屽悓鏃朵笌color_val榪涜鎴栨搷浣滐紝涓嬮潰鍚岀悊
color_val = color_val | (aRGB[1] << 16);
color_val = color_val | (aRBG[0] << 24);
int red_val = (colorVal >>> 16) & 0xFF;
int green_val = (colorVal >>> 8) & 0xFF;
int blue_val = colorVal & 0xFF;
]]>lang.*
String manipulation -StringUtils, StringEscapeUtils, RandomStringUtils, Tokenizer, WordUtils
Character handling - CharSetUtils, CharSet, CharRange, CharUtils
CharSetUtils.delete("testtest", "tr")
will remove all t's and all r's from the String, not just the String "tr".JVM interaction - SystemUtils, CharEncoding
Serialization - SerializationUtils, SerializationException
Assorted functions - ObjectUtils, ClassUtils, ArrayUtils, BooleanUtils
Flotsam - BitField, Validate
lang.builder.*
lang.enums.* (formerly lang.enum)
lang.exception.*
lang.math.*
lang.mutable.*
lang.text.*
StrBuilder
, a class for substituting variables within a String named StrSubstitutor
and a replacement for StringTokenizer named StrTokenizer
. While somewhat ungainly, the Str
prefix has been used to ensure we don't clash with any current or future standard Java classes.lang.time.*
]]>