本文整理汇总了Java中org.mapdb.DB.close方法的典型用法代码示例。如果您正苦于以下问题:Java DB.close方法的具体用法?Java DB.close怎么用?Java DB.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mapdb.DB
的用法示例。
在下文中一共展示了DB.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setConnectionToDB
import org.mapdb.DB; //导入方法依赖的package包/类
public void setConnectionToDB(DockerConnection dc, File configFile, File certFile) throws IOException {
File database = new File("./connections.db");
DB db = DBMaker
.fileDB(database)
.transactionEnable()
.closeOnJvmShutdown()
.fileChannelEnable()
.make();
ConcurrentMap mapa = db.hashMap("map").createOrOpen();
dc.getWithTls().setDockerCertPath(Paths.get("server/certs/").relativize(certFile.toPath()).toString());
dc.getWithTls().setDockerConfig(Paths.get("server/certs/").relativize(configFile.toPath()).toString());
mapa.put(dc.getName(), dc);
db.commit();
db.close();
}
示例2: getConnectionFromDB
import org.mapdb.DB; //导入方法依赖的package包/类
public Map<UUID, DockerConnection> getConnectionFromDB() throws IOException {
Map<UUID, DockerConnection> listOfConnections = new HashMap<>();
File database = new File("./connections.db");
DB db = DBMaker
.fileDB(database)
.transactionEnable()
.closeOnJvmShutdown()
.fileChannelEnable()
.make();
ConcurrentMap mapa = db.hashMap("map").createOrOpen();
mapa.forEach((uuid, connection) -> {
listOfConnections.put((UUID) uuid, (DockerConnection) connection);
});
db.close();
return listOfConnections;
}
示例3: visit
import org.mapdb.DB; //导入方法依赖的package包/类
public synchronized boolean visit(CustomParamVisitor visitor) throws Exception {
AssertionUtils.assertNotNull(new IllegalArgumentException("visitor"), visitor);
final DB db = getReadOnlyDB();
final Iterator<String> internalIterator = getSet(db).iterator();
Iterable<String> iterable = new Iterable<String>(
) {
@Override
public Iterator<String> iterator() {
return internalIterator;
}
};
boolean next = false;
for(String param : iterable) {
next = visitor.visit(param);
if(!next) {
break;
}
}
db.close();
return next;
}
示例4: createUser
import org.mapdb.DB; //导入方法依赖的package包/类
@Override
public void createUser(String username, String password, UserProfile profile) throws UserExists, TException {
final UserStorage storage = UsersPlugin.getInstance().getStorage();
final DB db = storage.getTxMaker().makeTx();
try {
BTreeMap<String, User> userMap = storage.getUserMap(db);
if (userMap.containsKey(username)) {
throw new UserExists();
}
final String hashed = UserStorage.getPasswordService().encryptPassword(password);
final User user = User.builder()
.username(username)
.hashedPassword(hashed)
.realName(profile.realName)
.isAdmin(profile.admin)
.build();
userMap.put(username, user);
db.commit();
} finally {
db.close();
}
}
示例5: updateProfile
import org.mapdb.DB; //导入方法依赖的package包/类
@Override
public void updateProfile(String username, UserProfile profile) throws UserNotFound, TException {
final UserStorage storage = UsersPlugin.getInstance().getStorage();
final DB db = storage.getTxMaker().makeTx();
try {
final BTreeMap<String, User> userMap = storage.getUserMap(db);
final User oldUser = userMap.get(username);
if (oldUser == null) {
throw new UserNotFound();
}
final User newUser = User.builder(oldUser)
.realName(profile.realName)
.isAdmin(profile.admin)
.build();
userMap.put(username, newUser);
db.commit();
} finally {
db.close();
}
}
示例6: updatePassword
import org.mapdb.DB; //导入方法依赖的package包/类
@Override
public void updatePassword(String username, String password) throws UserNotFound, TException {
final UserStorage storage = UsersPlugin.getInstance().getStorage();
final DB db = storage.getTxMaker().makeTx();
try {
final BTreeMap<String, User> userMap = storage.getUserMap(db);
final User oldUser = userMap.get(username);
if (oldUser == null) {
throw new UserNotFound();
}
final String hashed = UserStorage.getPasswordService().encryptPassword(password);
final User newUser = User.builder(oldUser).hashedPassword(hashed).build();
userMap.put(username, newUser);
db.commit();
} finally {
db.close();
}
}
示例7: doGetAuthenticationInfo
import org.mapdb.DB; //导入方法依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
if (token instanceof UsernamePasswordToken) {
final UsernamePasswordToken upToken = (UsernamePasswordToken)token;
final String username = upToken.getUsername();
final UserStorage storage = UsersPlugin.getInstance().getStorage();
final DB db = storage.getTxMaker().makeTx();
try {
final User user = storage.getUserMap(db).get(username);
if (user == null) {
return null;
}
Hash hash = new Shiro1CryptFormat().parse(user.getHashedPassword());
return new UserInfo(user.getUsername(), hash);
} finally {
db.close();
}
}
return null;
}
示例8: testUseExistingRootIfPossible
import org.mapdb.DB; //导入方法依赖的package包/类
@Test
public void testUseExistingRootIfPossible() throws Exception {
// Given a non-empty root in the manifest
File dbFile = createTempFile();
DB db = MapDbUtils.createFileDb(dbFile);
manifest = new MapDbManifest(db);
TreeItem item = new TreeItem(Entry.Type.BLOB, "foo", "foo.txt", 0);
Tree root = new Tree(MapDbManifest.ROOT_KEY, Collections.singletonList(item));
manifest.put(root);
// When you reopen the db
db.commit();
db.close();
db = MapDbUtils.createFileDb(dbFile);
manifest = new MapDbManifest(db);
// Then the root contains the saved items
List<TreeItem> items = manifest.getRoot().getItems();
assertEquals(1, items.size());
assertEquals(item, items.get(0));
}
示例9: compile
import org.mapdb.DB; //导入方法依赖的package包/类
static void compile(String file, String database){
DB db = DBMaker.newFileDB(new File(database)).compressionEnable().closeOnJvmShutdown().make();
NavigableSet<Tuple2<String, Tuple2<String,Double>>> multiset = db.getTreeSet("SW");
multiset.clear();
try {
BufferedReader swFile = new BufferedReader(new InputStreamReader(new BZip2InputStream(new FileInputStream(new File(file)), false), "UTF-8"));
int entry = 0;
for(String line=swFile.readLine();line != null;line = swFile.readLine()){
String key = line.trim();
String[] values = swFile.readLine().trim().split(" ");
for(int i = 1;i < values.length;i += 2){
multiset.add(Fun.t2(key, Fun.t2(values[i-1], Double.parseDouble(values[i]))));
}
if(entry++ > 100){
db.commit();
entry = 0;
}
}
swFile.close();
} catch (IOException e) {
e.printStackTrace();
}
db.commit();
db.close();
}
示例10: testAddSetValue
import org.mapdb.DB; //导入方法依赖的package包/类
@Test
public void testAddSetValue() throws Exception {
File file = File.createTempFile("foo", "db");
file.deleteOnExit();
DB db = DBMaker.newFileDB(file).closeOnJvmShutdown().make();
MapDBCollectionPersistenceContext ctx = new MapDBCollectionPersistenceContext(db);
ctx.addSetValue("set1", "val1");
ctx.addSetValue("set1", "val2");
ctx.commit();
db.close();
db = DBMaker.newFileDB(file).closeOnJvmShutdown().make();
ctx = new MapDBCollectionPersistenceContext(db);
Set<Object> set = ctx.getSet("set1");
assertNotNull(set);
assertEquals(2, set.size());
assertTrue(set.contains("val1"));
assertTrue(set.contains("val2"));
}
示例11: main
import org.mapdb.DB; //导入方法依赖的package包/类
public static void main(String[] args) {
if (args.length != 2){
logger.error(usage);
System.exit(1);
}
RecordReader<WikipediaLabelToFreebaseRecord> reader = new RecordReader<WikipediaLabelToFreebaseRecord>(
args[0], new WikipediaLabelToFreebaseRecord.Parser());
File f = new File(args[1]);
if (!f.exists()) {
f.mkdirs();
}
File dbfile = new File(f, "freebase.db");
DB db = DBMaker.fileDB(dbfile).fileMmapEnable().closeOnJvmShutdown().make();
ProgressLogger pl = new ProgressLogger("indexed {} records", 100000);
HTreeMap<String, String> map = db.hashMap("index", Serializer.STRING, Serializer.STRING).createOrOpen();
HTreeMap<String, String> labels = db.hashMap("label", Serializer.STRING, Serializer.STRING).createOrOpen();
for (WikipediaLabelToFreebaseRecord record : reader) {
map.put(record.getCleanWikipediaLabel(), record.getFreebaseId());
labels.put(record.getFreebaseId(), record.getLabel());
pl.up();
}
db.commit();
db.close();
logger.info("file indexed, index in {}", args[1]);
}
示例12: close
import org.mapdb.DB; //导入方法依赖的package包/类
/**
* close the database.
*
* @throws SQLException
* if an error occurs.
*/
@Override
public void close() {
synchronized (this) {
if (closed) {
return;
}
closed = true;
}
LOG.debug("STARTED shutdown");
DB.close();
LOG.debug("SUCCESS shutdown");
}
示例13: getProperty
import org.mapdb.DB; //导入方法依赖的package包/类
public synchronized String getProperty(String property, String defaultValue) {
AssertionUtils.assertNotNull(new IllegalArgumentException("property"), property);
AssertionUtils.assertNotNull(new IllegalArgumentException("defaultValue"), defaultValue);
DB db = getReadOnlyDB();
String value;
try {
value = getMap(db).get(property);
if(value == null) {
return defaultValue;
}
return value;
} finally {
db.close();
}
}
示例14: setProperty
import org.mapdb.DB; //导入方法依赖的package包/类
public synchronized void setProperty(String property, String value) {
AssertionUtils.assertNotNull(new IllegalArgumentException("property"), property);
AssertionUtils.assertNotNull(new IllegalArgumentException("value"), value);
DB db = getDB(false);
try {
getMap(db).put(property, value);
db.commit();
} finally {
db.close();
}
}
示例15: add
import org.mapdb.DB; //导入方法依赖的package包/类
public synchronized void add(String value) {
AssertionUtils.assertNotNull(new IllegalArgumentException("value"), value);
DB db = getDB(false);
try {
getSet(db).add(value);
db.commit();
} finally {
db.close();
}
}