当谈到锁定弹簧jpa时,我真的很不安全.
因此,请将此问题视为一个澄清.我真的希望我理解它是正确的,但我的英语对于理解复杂的博客文章并不是那么好.
所以这就是我认为我从一些文章中得到的:
锁定有两种基本类型:
第一个问题:到目前为止这是正确的吗?当我现在想测试这个knollage时,我可以在这个LockModeType之间做出选择:
为什么现在有这么多子锁,他们做了什么?当"OPTIMISTIC"是我试图理解的顶级乐观锁定时,那么什么是"OPTIMISTIC_FORCE_INCEMENT"?
版本更新与此有何关系?(或@version?)
继续:
Spring jpa中有三种锁的基本用法:
在普通列上,例如:
@Entity
public class PersonEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Lock(LockModeType.PESSIMISTIC_WRITE)
private String name;
}
Run Code Online (Sandbox Code Playgroud)在另一个表的外键上,例如:
@Entity
public class PersonEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Lock(LockModeType.PESSIMISTIC_WRITE)
@OneToOne
private Group group;
}
Run Code Online (Sandbox Code Playgroud)在存储库内的表上,例如:
interface PersonRepository extends Repository<Person, Long> {
@Lock(LockModeType.PESSIMISTIC_WRITE)
Person findOne(Long id);
}
Run Code Online (Sandbox Code Playgroud)直接锁定实体
@Entity …Run Code Online (Sandbox Code Playgroud) 我正在为用户登录使用非常基本的angularJS代码,如下所示:
[...]
this.login = function(email, password) {
promise = $http.post('/login',
{
'email': email,
'password': password
});
promise.then(function(response){
console.log("success");
}).catch(function(response){
console.log("catch");
}).finally(function(response){
console.log("finally");
});
return promise;
};
[...]
Run Code Online (Sandbox Code Playgroud)
当REST API生成代码为200的响应时,客户端控制台将登录success finally并且用户已登录。
服务器生成代码为403或500的响应时,控制台将打印输出catch finally。
但是当响应为401时,angular不会打印任何内容。控制台将保持空白,仅带有POST http://127.0.0.1/login 401 (Unauthorized)提示。但没有success或catch作为输出。也没有finally。
在我的项目中,403将在全局范围内被捕获$rootScope.$on('event:auth-forbidden', function(r) {...});。这就是为什么REST Server仅在找不到内容时抛出404,在用户没有权限和/或未登录时抛出403,仅在登录失败时抛出401的原因。
那么我怎样才能赶上401 $http?
难道不是.then只为回报200而.catch其他的回报!= 200 的承诺?
我正在使用angularJS v1.6.4和angular-http-auth v1.5.0。
我有以下脚本(示例):
#!/bin/bash
while getopts a: opt; do
case "$opt" in
a) val="$OPTARG";;
?) echo "use the flag \"-a\""
exit 2;;
esac
done
echo "a specified with: ${val}"
Run Code Online (Sandbox Code Playgroud)
当我现在调用此脚本时,test.sh -a "here is a string"输出为:a specified with: here但不是我想要的那样a specified with: here is a string。
test.sh -a here\ is\ a\ string我知道我可以用or调用脚本,test.sh -a "here\ is\ a\ string"它会起作用。但就我而言,我无法操纵我想要传递的字符串。
那么我怎样才能改变我的getopts功能以使其正常工作呢?
我也尝试过getopt,但我的工作更糟糕:
commandsShort="a:"
commandsLong="aval:"
TEMP=`getopt \
-o $commandsShort \
-l $commandsLong \ …Run Code Online (Sandbox Code Playgroud) 我有一个scala特征,其公共UUID具有默认值:
trait pet {
var uuid_ : UUID = UUID.randomUUID
}
Run Code Online (Sandbox Code Playgroud)
现在我在scala中创建了多个类:
class dog extends pet {
var foo = 1
}
class cat extends pet {
}
class fish extends pet {
}
Run Code Online (Sandbox Code Playgroud)
之后我在Java中创建了一个方法(两个语言混合的旧项目).
这里剪了我的问题.在变量somePet是一个实例dog,cat或fish.但目前尚不清楚它们究竟是什么:
// printing all variables in the console for human testing
Serializer.printAllFields(somePet);
// The somePet Variable must be a pet
if(!pet.class.isAssignableFrom(somePet.getClass()))
throw new Exception("Not a pet.");
// get the UUID of the pet
UUID uuid_;
try { …Run Code Online (Sandbox Code Playgroud) java ×2
angularjs ×1
bash ×1
hibernate ×1
javascript ×1
jpa ×1
parameters ×1
reflection ×1
rest ×1
scala ×1
shell ×1
space ×1
spring ×1
traits ×1