forked from Datomic/datomic-java-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.java
More file actions
41 lines (35 loc) · 1.13 KB
/
IO.java
File metadata and controls
41 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package datomic.samples;
import datomic.Connection;
import datomic.Util;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutionException;
public class IO {
public static void transactAll(Connection conn, Reader reader) {
List<List> txes = Util.readAll(reader);
for (java.util.Iterator<List> it = txes.iterator(); it.hasNext(); ) {
List tx = it.next();
try {
conn.transact(tx).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
public static URL resource(String name) {
return Thread.currentThread().getContextClassLoader().getResource(name);
}
public static void transactAllFromResource(Connection conn, String resource) {
URL url = resource(resource);
try {
transactAll(conn, new InputStreamReader(url.openStream()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}