对db4o的再包装

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

/**
 *
 */
@Typed
package org.lucifer.db4o

import org.lucifer.util.MyLogger

import com.db4o.Db4oEmbedded
import com.db4o.EmbeddedObjectContainer
import com.db4o.ObjectContainer
import com.db4o.ObjectServer
import com.db4o.config.EmbeddedConfiguration
import com.db4o.config.QueryEvaluationMode
import com.db4o.cs.Db4oClientServer
import com.db4o.cs.config.ClientConfiguration
import com.db4o.cs.config.ServerConfiguration
/**
 * @author Lucifer
 *
 */
final class Db4oUtil {
	static final MyLogger logger = new MyLogger(Db4oUtil.class)
	public static final QueryEvaluationMode IMMEDIATE = QueryEvaluationMode.IMMEDIATE,
	SNAPSHOT = QueryEvaluationMode.SNAPSHOT, LAZY = QueryEvaluationMode.LAZY;

	private Db4oUtil() {
	}

	static EmbeddedObjectContainer openEmbeddedDatabase(String dbname,
	EmbeddedConfiguration config = Db4oUtil.getEmbeddedConfiguration()) {
		def container = null
		try {
			try {
				container = Db4oEmbedded.openFile(config, dbname)
			} finally {
				container?.close()
			}
		} catch(Exception ex) {
			logger.throwing("openEmbeddedDatabase", ex)
		}
		return container
	}

	static ObjectServer openEmbeddedServer(String dbname,
	ServerConfiguration config = Db4oUtil.getServerConfiguration()) {
		return Db4oClientServer.openServer(config, dbname, 0)
	}

	static ObjectContainer opeEmbeddedClient(ObjectServer server) {
		return server.openClient()
	}

	static ObjectServer openNetworkServer(String dbname, int port, String user, String passwd,
	ServerConfiguration config = Db4oUtil.getServerConfiguration()) {
		def server = Db4oClientServer.openServer(config, dbname, port)
		server.grantAccess(user, passwd)
		return server
	}

	static ObjectContainer openNetworkClient(String ip, int port, String user, String passwd,
	ClientConfiguration config = Db4oUtil.getClientConfiguration()) {
		return Db4oClientServer.openClient(config, ip, port, user, passwd)
	}

	static EmbeddedConfiguration getEmbeddedConfiguration() {
		return Db4oEmbedded.newConfiguration()
	}

	static ServerConfiguration getServerConfiguration() {
		return Db4oClientServer.newServerConfiguration()
	}

	static ClientConfiguration getClientConfiguration() {
		return Db4oClientServer.newClientConfiguration()
	}
}