我正在查看一些代码并遇到这个方法,它采用HTML Header值(即Content-Disposition = inline; filename = foo.bar)并将其解析为由分号分隔成key = value对的映射.起初它看起来像是使用流进行优化的一个很好的候选者,但是在我实现之后,我无法重用计算的String.indexOf('=')值意味着字符串必须被扫描3次,这是实际上不如原来的最佳.我完全清楚有很多实例,Streams不适合这项工作,但我想知道我是否错过了一些技术,可以让Stream比初始代码更高效/更高效.
/**
* Convert a Header Value String into a Map
*
* @param value The Header Value
* @return The data Map
*/
private static Map<String,String> headerMap (String value) {
int eq;
Map<String,String> map = new HashMap<>();
for(String entry : value.split(";")) {
if((eq = entry.indexOf('=')) != -1) {
map.put(entry.substring(0,eq),entry.substring(eq + 1));
}
}
return map;
return Stream.of(value.split(";")).filter(entry -> entry.indexOf('=') != -1).collect(Collectors.));
} //headerMap
Run Code Online (Sandbox Code Playgroud)
我尝试Streaming it:
/**
* Convert a Header Value …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个酒店预订网站.它是一个J2EE 1.4 Web应用程序,使用JSP和JDBC.
我有一种方法负责预订酒店房间.
booking()
Run Code Online (Sandbox Code Playgroud)
从这个方法我称其他四种方法
bookRooms()
makePayment()
confirmUserByMail()
confirmUserBySMS()
Run Code Online (Sandbox Code Playgroud)
我知道有两个用户可以尝试同时预订同一个房间,而在我目前的系统中,两个用户可能最终会使用同一个房间.
我应该如何处理事务以避免这种并发问题?
这可能是非常常见的情况,但我之前从未处理过这种情况,所以请指导我.
我有一个使用多个连接的Criteria查询,并且生成的SQL不按顺序列出表,以便ON子句引用尚未声明的表.
为了重现这个问题,我创建了一个包含三个表的小型数据模型:Bill,Event和一个联结表BillEvent(我在问题的最后列出了一个带有实体定义的可运行JUnit测试).以下Criteria查询因语法错误而失败,因为event1
它在引用后声明.如何重写此查询以便以正确的顺序声明表?
// Get the most recent BillEvent for a bill
final Criteria criteria = session.createCriteria(BillEvent.class, "be1")
.createCriteria("event", "event1")
.createCriteria("be1.bill")
.add(Restrictions.eq("id", billId))
.createCriteria("billEvents", "be2")
.createCriteria("event", "event2", JoinType.LEFT_OUTER_JOIN,
Restrictions.ltProperty("event1.time", "time"))
.add(Restrictions.isNull("event2.id"));
Run Code Online (Sandbox Code Playgroud)
错误:
Caused by: org.h2.jdbc.JdbcSQLException: Column "EVENT1X1_.TIME" not found; SQL statement:
select
this_.id as id1_1_4_,
this_.billId as billId3_1_4_,
this_.eventId as eventId4_1_4_,
this_.note as note2_1_4_,
hibernatej2_.id as id1_0_0_,
hibernatej2_.label as label2_0_0_,
be2x3_.id as id1_1_1_,
be2x3_.billId as billId3_1_1_,
be2x3_.eventId as eventId4_1_1_,
be2x3_.note as note2_1_1_,
event2x4_.id as id1_2_2_,
event2x4_.time as time2_2_2_, …
Run Code Online (Sandbox Code Playgroud) 决定更新到Hibernate 5以删除现有的Date to LocalDateTime转换.我从Maven安装了hibernate-java8工件.然后我将我的hibernate实体日期时间替换为
@Column (name = "mis_a_jour_au", nullable = false)
@Temporal (TemporalType.TIMESTAMP)
private LocalDateTime misAJourAu;
@Column (name = "envoi_au", nullable = false)
@Temporal (TemporalType.TIMESTAMP)
private LocalDateTime envoiAu;
Run Code Online (Sandbox Code Playgroud)
抛出了这个异常
org.hibernate.AnnotationException:@Temporal只应在java.util.Date或java.util.Calendar属性上设置
如果我删除@Temporal,则异常变为
ClassCastException:java.util.Date无法强制转换为java.time.LocalDateTime
我以为Java 8 + Hibernate 5支持LocalDateTime?请指教.
似乎Rational软件架构师(RSA)和Rational应用程序开发人员(RAD)这两种IBM产品基本上都用作IDE.但两者都有特定的用途.请帮助我了解何时使用RSA和何时使用RAD.这两种IBM产品之间有什么区别和相似之处.
我有一个应该最终生成的程序OutOfMemory
.程序代码是:
public class VeryLargeObject implements Serializable {
public static final int SIZE = 1 << 12;
public String tag;
public int[][] bigOne = new int[SIZE][SIZE];
{
// Initialize bigOne
for(int i = 0; i < SIZE ; ++i) {
for(int j = 0; j < SIZE; ++j) {
bigOne[i][j] = (int) (Math.random() * 100);
}
}
}
public VeryLargeObject(String tag) {
this.tag = tag;
}
public static void main(String args[]) {
VeryLargeObject[] vla = new VeryLargeObject[1 << 12]; …
Run Code Online (Sandbox Code Playgroud) getModifiers()的Java Doc 如下:
int getModifiers()
以整数形式返回此Member表示的成员或构造函数的Java语言修饰符.应使用Modifier类来解码整数中的修饰符.
和Java Docs还提供了不同修饰符及其对应的int值的列表:
public static final int ABSTRACT 1024
public static final int FINAL 16
public static final int INTERFACE 512
public static final int NATIVE 256
public static final int PRIVATE 2
public static final int PROTECTED 4
public static final int PUBLIC 1
public static final int STATIC 8
public static final int STRICT 2048
public static final int SYNCHRONIZED 32
public static final int TRANSIENT 128
public …
我正在使用Eclipse Kepler来开发我的Java项目.我创建了一个vo并在vo中添加了一些属性.为这些属性生成getter和setter方法,我右键单击一个属性然后转到"Source"
然后单击"Generates Getters and Setters"
.它向我展示了属性的可用getter/setter方法.下面是屏幕截图
正如你可以在上面的截图中看到,Eclipse是我提供getter和setter方法的属性SID是
public String getsId() {
return sId;
}
public void setsId(String sId) {
this.sId = sId;
}
Run Code Online (Sandbox Code Playgroud)
get和set之后的第一个字母是小写字母(get s Id和set s Id).
对于属性,Eclipse正在创建所需的getter和setter方法.
我的观察是,任何财产,其第二个字母是大写(对于示例- SID:第一个字母(小号)是在小型和第二信(我)是资本)日食发生在以下格式的getter和setter
get+property name
set+property name
Run Code Online (Sandbox Code Playgroud)
但如果属性的第二个字母是小写字母 eclipse正在以下面的格式生成getter和setter
get+1st letter in capital letter+ rest of the property name
set+1st letter in capital letter+ rest of the property name
Run Code Online (Sandbox Code Playgroud)
即使如果该属性的第一个字母是大写字母,eclipse也会以下面的格式生成getter和setter
get+1st letter (which is already in …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Oracle 12c Identity列功能Hibernate-5.0.0.CR4
.我在Spring引导application.properties中使用了以下属性:
spring.jpa.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect
spring.datasource.driverClassName=oracle.jdbc.OracleDriver
Run Code Online (Sandbox Code Playgroud)
从源代码来看Oracle12cDialect
,它似乎支持标识列.但是在尝试将记录插入到名为的表中时,我收到以下错误user_preferences
:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
@Entity
@Table(name = "user_preferences")
@Data
@JsonIgnoreProperties(value = { "prefId" })
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
public class UserPreference {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "pref_id")
private Long prefId;
@Column(nullable = false)
private String key;
@Column(nullable = false)
private String preference;
@ManyToOne …
Run Code Online (Sandbox Code Playgroud) 我有以下映射:
<id name="id" type="java.lang.Long" column="id">
<generator class="sequence">
<param name="sequence">tracksdata_seq</param>
</generator>
</id>
Run Code Online (Sandbox Code Playgroud)
当我在Hibernate 4.2中使用它时,一切都很顺利.现在我正在迁移到Hibernate 5并面临以下问题:
2015-10-06 19:49:50 DEBUG SQL:92 - select nextval ('hibernate_sequence')
2015-10-06 19:49:50 DEBUG SqlExceptionHelper:122 - could not extract ResultSet [n/a]
org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
PS Hibernate 5.0.2.Final.