我正在尝试添加一个将成为外键的新列.我已经能够使用两个单独的ALTER TABLE命令添加列和外键约束:
ALTER TABLE one
ADD two_id integer;
ALTER TABLE one
ADD FOREIGN KEY (two_id) REFERENCES two(id);
Run Code Online (Sandbox Code Playgroud)
有没有办法用一个ALTER TABLE命令而不是两个?我无法想出任何有效的东西.
我有一个这样的课:
public class Person {
private String name;
public String getName(){
return name;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用像这样配置的ObjectMapper:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Run Code Online (Sandbox Code Playgroud)
我有一个str包含它的字符串{ "address" : "something" }.请注意,json中没有"name"字段.如果我做这样的事情:
mapper.readValue(str, Person.class);
Run Code Online (Sandbox Code Playgroud)
然后我实际上得到一个名字设置为null的Person对象.有没有办法配置映射器来抛出异常,或者返回空引用而不是Person?我希望杰克逊认为缺少字段失败,并且不希望对结果对象的字段进行显式空值检查.
在Akka中,不是在使用?创建的未来响应中使用onComplete,而是尝试使用pipeTo,因为这应该是首选模式.但是,当未来超时时,我似乎没有收到任何Throwables或Failures.如果在使用pipeTo时发生超时,我应该在演员中收到什么?什么时候抛出不同的异常?示例代码:
class Simple(otherActor : ActorRef) extends Actor{
def receive = {
case "some_msg" => {
val implicit timeout = Timeout(1 seconds)
val response = otherActor ? "hello"
response pipeTo self
}
// case ??? // How do I handle timeouts?
}
}
Run Code Online (Sandbox Code Playgroud)
如果超时发生时没有自动发送消息,我应该如何使用pipeTo处理超时?
有没有办法生成库而不是使用可执行文件idris?如果我尝试编译没有a main,我得到这样的错误:
main:0:0:When elaborating an application of function run__IO:
No such variable Main.main
Run Code Online (Sandbox Code Playgroud)
如果我可以生成一个库,那么有没有办法从C代码调用它?我已经查看了生成的C代码,但它看起来并不打算在外部调用.
我正在使用sbt版本0.13.2与纯java项目.
我build.sbt的内容如下:
libraryDependencies ++= Seq("com.novocode" % "junit-interface" % "0.10" % "test")
Run Code Online (Sandbox Code Playgroud)
我的测试看起来像这样:
import org.junit.Test;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.Assert.*;
@RunWith(JUnit4.class)
public class ExampleTest{
@Test
public void firstTest(){
org.junit.Assert.assertEquals("2.5 + 7.5 = 10.0", 2.5 + 7.5, 10.0, .1);
}
}
Run Code Online (Sandbox Code Playgroud)
当我sbt test从命令行执行操作时,测试已成功编译,但测试未运行.它说
Compiling 1 Java source to [my path]/target/scala-2.10/test-classes...
...
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[success] Total time: 1 s, completed May 31, 2014 5:56:22 PM
Run Code Online (Sandbox Code Playgroud)
知道如何执行测试吗?
我发现自己经常使用vars与akka演员来维持状态.例如,如果我的演员需要维护一个项目列表,我可能会这样做:
class ListActor extends Actor{
var xs : List[Int] = List()
def receive = {
case x : Int => xs = x :: xs
}
}
Run Code Online (Sandbox Code Playgroud)
使用可变变量似乎违背了Scala的精神.或者我用过这个:
class ListActor2 extends Actor{
import context._
def collect_ints(accu : List[Int]) : Receive = {
case x : Int => become(collect_ints(x :: accu))
}
def receive = collect_ints(Nil)
}
Run Code Online (Sandbox Code Playgroud)
我喜欢这看起来更多,但我是否要担心堆栈溢出?
我知道FSM特性并且之前也使用过它,但在某些情况下它似乎太多了.
维持简单状态的推荐方法是什么?还有其他我不知道的替代方案吗?
另外,如果我发现自己经常需要可变变量,这通常是一个不好的迹象吗?我没有正确使用演员模型吗?
我正在使用猫Scala库,IntelliJ IDE似乎正在努力使用implicits:
这是一个简单的例子:
import cats.std.all._
import cats.Traverse.ops._
def useSequence[A](ls : List[Option[A]]) : Option[List[A]] = {
ls.sequence
}
Run Code Online (Sandbox Code Playgroud)
在IntelliJ中,此代码以红色突出显示.但是我可以使用Make Project或命令行构建得很好.
现在错误是:
类型Nothing [List [Nothing]]的表达式不符合预期类型选项[List [A]]
其他时候错误是这样的:
值序列不是List [Option [A]]的成员
这是IntelliJ中的错误还是我错过了一些配置?
我使用的是IntelliJ 15.0.2和Scala插件的2.0.4版.
使用capybara,有没有办法获得元素的所有css类?查看文档,我看不到任何简单的方法.
另外,给定一个元素,elem和一个css类,someclass,应该elem.has_css?('.someclass')等同于jquery $(elem).hasClass('someclass')?
这个特殊的测试是使用Selenium,因为它涉及javascript.
我克隆了一个github存储库并在本地进行了几次提交.当我打算为我的更改创建一个单独的分支时,我不小心在主分支上进行了这些提交.有没有办法将这些更改转换为新的分支并在将更改推送到远程之前恢复原始主分支?
是否可以在clojurescript项目中使用任意node.js模块?如果是的话,我该怎么做呢?如果没有,为什么不呢?