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是不可以被继承的,也不可以继承自别人,只是能实现接口而已,何谈多态 ...
随机推荐
- sigmod2017.org
http://sigmod2017.org/sigmod-program/#ssession20
- 用 CSS 实现三角形与平行四边形
最近在逛某个技术网站的时候,感觉文章关键词上的样式好酷炫啊.于是我将那种写法照搬到了我的博客中,也许最近逛过我博客的小伙伴已经发现了它出现在哪儿了——分页的样式.来张截图: 你在首页的底部也可以看到这 ...
- ASP.NET MVC中实现属性和属性值的组合,即笛卡尔乘积02, 在界面实现
在"ASP.NET MVC中实现属性和属性值的组合,即笛卡尔乘积01, 在控制台实现"中,在控制台应用程序中实现了属性值的笛卡尔乘积.本篇在界面中实现.需要实现的大致如下: 在界面 ...
- 让DELPHI自带的richedit控件显示图片
让DELPHI自带的richedit控件显示图片 unit RichEx; { 2005-03-04 LiChengbin Added: Insert bitmap or gif into RichE ...
- WordPress基础:常用分类列表wp_list_categories
函数:wp_list_categories($args) 作用:列出某个分类下的分类项目 用法: <ul> <?php $args= array( 'depth'=>1, 'o ...
- SpringMVC方法传递集合数组
背景:实体集合作为参数 数据准备: 1.实体类 class A {private int id; private String name; } 2.集合json字符串 [{"id&quo ...
- python测试开发django-29.发送html格式邮件
前言 上一篇已经通过send_mail()函数发送纯文本的邮件,发送成功了,如果我们想发送一个html格式的邮件,如何实现呢? 发送html格式的邮件实际上还是调用send_mail()函数 ,只需多 ...
- [Web 前端] 使用yarn代替npm作为node.js的模块管理器
cp from : https://www.jianshu.com/p/bfe96f89da0e Fast, reliable, and secure dependency managemen ...
- 开启VIM的Python支持
开启VIM的Python支持 2015年01月03日 02:57:58 forlong401 阅读数:16294更多 个人分类: VIPython http://www.tuicool.com/a ...
- information_schema系列六(索引,表空间,权限,约束相关表)
information_schema系列六(索引,表空间,权限,约束相关表) 1: STATISTICS 这个表提供的是关于表的索引信息: INFORMATION_SCHEMA Name SHOW ...