本文整理汇总了Java中com.cloudant.sync.datastore.DatastoreManager类的典型用法代码示例。如果您正苦于以下问题:Java DatastoreManager类的具体用法?Java DatastoreManager怎么用?Java DatastoreManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatastoreManager类属于com.cloudant.sync.datastore包,在下文中一共展示了DatastoreManager类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDevelopmentDatabase
import com.cloudant.sync.datastore.DatastoreManager; //导入依赖的package包/类
private static void createDevelopmentDatabase() throws Exception {
// some temporary code for development purposes :)
File path = new File(databaseDir);
DatastoreManager manager = DatastoreManager.getInstance(path.getAbsolutePath());
// make sure we have a database for development
Datastore ds = manager.openDatastore("mydb");
// MutableDocumentRevision rev = new MutableDocumentRevision();
// Map<String, Object> json = new HashMap<String, Object>();
// json.put("description", "Buy milk");
// json.put("completed", false);
// json.put("type", "com.cloudant.sync.example.task");
// rev.body = DocumentBodyFactory.create(json);
// ds.createDocumentFromRevision(rev);
ds.close();
}
示例2: onCreate
import com.cloudant.sync.datastore.DatastoreManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// create datastore
File path = getApplicationContext().getDir("datastores", MODE_PRIVATE);
DatastoreManager manager = new DatastoreManager(path.getAbsolutePath());
Datastore ds = manager.openDatastore("mydb");
ds.close();
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
component.getDefaultHost().attachDefault(HttpListener.class);
try {
component.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: HttpListener
import com.cloudant.sync.datastore.DatastoreManager; //导入依赖的package包/类
public HttpListener() {
databaseDir =
getApplication().getContext().getParameters().getFirstValue("databaseDir");
port = new Integer(
getApplication().getContext().getParameters().getFirstValue("port")
);
manager = DatastoreManager.getInstance(databaseDir);
}
示例4: createServer
import com.cloudant.sync.datastore.DatastoreManager; //导入依赖的package包/类
void createServer(final int port, final String dbname) throws Exception {
final String databaseDir = Files.createTempDirectory(null).toAbsolutePath().toString();
databaseDirs.put(port, databaseDir);
DatastoreManager manager = DatastoreManager.getInstance(databaseDir);
Datastore ds = manager.openDatastore(dbname);
ds.close();
Runnable r = new Runnable()
{
@Override
public void run()
{
final Router router = new Router();
router.attachDefault(HttpListener.class);
org.restlet.Application myApp = new org.restlet.Application() {
@Override
public org.restlet.Restlet createInboundRoot() {
Context ctx = getContext();
ctx.getParameters().add("databaseDir", databaseDir);
ctx.getParameters().add("port", Integer.toString(port));
router.setContext(ctx);
return router;
};
};
Component component = new Component();
component.getDefaultHost().attach("/", myApp);
try {
new Server(Protocol.HTTP, port, component).start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
new Thread(r).start();
}
示例5: onCreate
import com.cloudant.sync.datastore.DatastoreManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AndroidLoggingHandler.reset(new AndroidLoggingHandler());
java.util.logging.Logger.getLogger(HttpListener.class.getCanonicalName()).setLevel(Level.FINEST);
try {
// create datastore
final File databaseDir = getApplicationContext().getDir("datastores", MODE_PRIVATE);
final DatastoreManager manager = DatastoreManager.getInstance(databaseDir.getAbsolutePath());
Datastore ds = manager.openDatastore("mydb");
ds.close();
// Set up a Restlet service
final Router router = new Router();
router.attachDefault(HttpListener.class);
org.restlet.Application myApp = new org.restlet.Application() {
@Override
public org.restlet.Restlet createInboundRoot() {
Context ctx = getContext();
ctx.getParameters().add("databaseDir", databaseDir.getAbsolutePath());
ctx.getParameters().add("port", Integer.toString(PORT));
router.setContext(ctx);
return router;
};
};
Component component = new Component();
component.getDefaultHost().attach("/", myApp);
new Server(Protocol.HTTP, PORT, component).start();
} catch (Exception e) {
Log.e("snowch.MyActivity", "Error", e);
throw new RuntimeException(e);
}
}