java enum 用法
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.annotations;
import org.hibernate.cache.spi.access.AccessType;
/**
* Cache concurrency strategy.
*
* @author Emmanuel Bernard
*/
public enum CacheConcurrencyStrategy {
/**
* Indicates no concurrency strategy should be applied.
*/
NONE( null ),
/**
* Indicates that read-only strategy should be applied.
*
* @see AccessType#READ_ONLY
*/
READ_ONLY( AccessType.READ_ONLY ),
/**
* Indicates that the non-strict read-write strategy should be applied.
*
* @see AccessType#NONSTRICT_READ_WRITE
*/
NONSTRICT_READ_WRITE( AccessType.NONSTRICT_READ_WRITE ),
/**
* Indicates that the read-write strategy should be applied.
*
* @see AccessType#READ_WRITE
*/
READ_WRITE( AccessType.READ_WRITE ),
/**
* Indicates that the transaction strategy should be applied.
*
* @see AccessType#TRANSACTIONAL
*/
TRANSACTIONAL( AccessType.TRANSACTIONAL );
private final AccessType accessType;
private CacheConcurrencyStrategy(AccessType accessType) {
this.accessType = accessType;
}
/**
* Get the AccessType corresponding to this concurrency strategy.
*
* @return The corresponding concurrency strategy. Note that this will return {@code null} for
* {@link #NONE}
*/
public AccessType toAccessType() {
return accessType;
}
/**
* Conversion from {@link AccessType} to {@link CacheConcurrencyStrategy}.
*
* @param accessType The access type to convert
*
* @return The corresponding enum value. {@link #NONE} is returned by default if unable to
* recognize {@code accessType} or if {@code accessType} is {@code null}.
*/
public static CacheConcurrencyStrategy fromAccessType(AccessType accessType) {
if ( null == accessType ) {
return NONE;
}
switch ( accessType ) {
case READ_ONLY: {
return READ_ONLY;
}
case READ_WRITE: {
return READ_WRITE;
}
case NONSTRICT_READ_WRITE: {
return NONSTRICT_READ_WRITE;
}
case TRANSACTIONAL: {
return TRANSACTIONAL;
}
default: {
return NONE;
}
}
}
/**
* Parse an external representation of a CacheConcurrencyStrategy value.
*
* @param name The external representation
*
* @return The corresponding enum value, or {@code null} if not match was found.
*/
public static CacheConcurrencyStrategy parse(String name) {
if ( READ_ONLY.isMatch( name ) ) {
return READ_ONLY;
}
else if ( READ_WRITE.isMatch( name ) ) {
return READ_WRITE;
}
else if ( NONSTRICT_READ_WRITE.isMatch( name ) ) {
return NONSTRICT_READ_WRITE;
}
else if ( TRANSACTIONAL.isMatch( name ) ) {
return TRANSACTIONAL;
}
else if ( NONE.isMatch( name ) ) {
return NONE;
}
else {
return null;
}
}
private boolean isMatch(String name) {
return ( accessType != null && accessType.getExternalName().equalsIgnoreCase( name ) )
|| name().equalsIgnoreCase( name );
}
}
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cache.spi.access;
/**
* The types of access strategies available.
*
* @author Steve Ebersole
*/
public enum AccessType {
/**
* Read-only access. Data may be added and removed, but not mutated.
*/
READ_ONLY( "read-only" ),
/**
* Read and write access (strict). Data may be added, removed and mutated.
*/
READ_WRITE( "read-write" ),
/**
* Read and write access (non-strict). Data may be added, removed and mutated. The non-strictness comes from
* the fact that locks are not maintained as tightly as in {@link #READ_WRITE}, which leads to better throughput
* but may also lead to inconsistencies.
*/
NONSTRICT_READ_WRITE( "nonstrict-read-write" ),
/**
* A read and write strategy where isolation/locking is maintained in conjunction with a JTA transaction.
*/
TRANSACTIONAL( "transactional" );
private final String externalName;
private AccessType(String externalName) {
this.externalName = externalName;
}
/**
* Get the corresponding externalized name for this value.
*
* @return The corresponding externalized name.
*/
public String getExternalName() {
return externalName;
}
@Override
public String toString() {
return "AccessType[" + externalName + "]";
}
/**
* Resolve an AccessType from its external name.
*
* @param externalName The external representation to resolve
*
* @return The access type.
*
* @throws UnknownAccessTypeException If the externalName was not recognized.
*
* @see #getExternalName()
*/
public static AccessType fromExternalName(String externalName) {
if ( externalName == null ) {
return null;
}
for ( AccessType accessType : AccessType.values() ) {
if ( accessType.getExternalName().equals( externalName ) ) {
return accessType;
}
}
throw new UnknownAccessTypeException( externalName );
}
}
java enum 用法的更多相关文章
- Java Enum用法详解
Java Enum用法详解 用法一:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举 ...
- java enum用法
基本用法 enum Day { SUNDAY, MONDAY, TUESDAY, WENDSDAY, THURSDAY, FRIDAY, SATURDAY; } 枚举是常量,所以应该用大写. 枚举是对 ...
- java Enum 用法示例
public enum MyEnum { Monday, Tuesday, Wednesday, Thursady, Friday, Saturday, Sunday; public static v ...
- Java Enum解析【转】
Enum用法: 1:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多 ...
- MVC图片上传详解 IIS (安装SSL证书后) 实现 HTTP 自动跳转到 HTTPS C#中Enum用法小结 表达式目录树 “村长”教你测试用例 引用provinces.js的三级联动
MVC图片上传详解 MVC图片上传--控制器方法 新建一个控制器命名为File,定义一个Img方法 [HttpPost]public ActionResult Img(HttpPostedFile ...
- 如何使用Java Enum
简单的用法:JavaEnum简单的用法一般用于代表一组常用常量,可用来代表一类相同类型的常量值.如: 性别: public enum SexEnum { male, female; } 颜色: pub ...
- (转)java enum枚举
转载自: 原理:http://singleant.iteye.com/blog/686349 应用:http://www.cnblogs.com/happyPawpaw/archive/2013/04 ...
- 你真的了解java的lambda吗?- java lambda用法与源码分析
你真的了解java的lambda吗?- java lambda用法与源码分析 转载请注明来源:cmlanche.com 用法 示例:最普遍的一个例子,执行一个线程 new Thread(() -> ...
- java enum
小谈Java Enum的多态性 博客分类: Java JavaAppleJDKJVMIDEA Enum+多态,我没说错,不过Enum是不可以被继承的,也不可以继承自别人,只是能实现接口而已,何谈多态 ...
随机推荐
- golang-bcc-bpf-function-tracing
http://www.brendangregg.com/blog/2017-01-31/golang-bcc-bpf-function-tracing.html
- Windows Sysinternals实战指南
http://www.epubit.com.cn/book/details/4786 Mark Russinovich是Microsoft Azure首席技术官,主要负责微软云计算平台的技术战略和架构 ...
- 解决Python交叉编译后,键盘方向键乱码的问题
参考 http://www.alliedjeep.com/38071.htm https://www.zhihu.com/question/21518507 http://professor.blog ...
- 项目从.NET 4.5迁移到.NET 4.0遇到的问题
当把项目从.NET 4.5迁移到.NET 4.0时,遇到的问题和解决如下: 在"属性--应用程序--目标框架"设置成.NET 4.0版本. 重新生成项目,报有关EF的错: 卸载掉项 ...
- SQLServer2008:在查看表记录或者修改存储过程时出现错误。错误消息为: 目录名无效
登陆数据库后,右键打开表提示:目录名无效,执行SQL语句也提示有错误,本来想重装的这个肯定能解决,但是这个方法真的不视为上上策啊,于是在网上找到了这个解决办法,还真是立即见效啊!分享给大家,希望有帮助 ...
- IOS 内存斗争小史之 对象、指针、内存的基本理解
1.指针和对象,都是内存块.一个大,一个小.一个在栈中,一个在堆中. 2.iOS中,我们可以生命一个指针,也可以通过alloc获取一块内存. 3.我们可以直接消灭掉一个指针,将其置为nil.但是我们没 ...
- mysql查询当前系统时间
第一种方法:select current_date: MySQL> select current_date as Systemtime;+------------+| Systemtime |+ ...
- mysql处理特殊字符
修改表 alter table USER convert to charset utf8mb4, character set utf8mb4; 修改列 ALTER TABLE USER DEFAULT ...
- 实用ExtJS教程100例-010:ExtJS Form异步加载和提交数据
ExtJS Form 为我们提供了两个方法:load 和 submit,分别用来加载和提交数据,这两个方法都是异步的. 系列ExtJS教程持续更新中,点击查看>>最新ExtJS教程目录 F ...
- 通过xml文件来设置动画
@android:anim/accelerate_interpolator: 越来越快 @android:anim/decelerate_interpolator:越来越慢 @android:anim ...