本文整理汇总了Java中com.marklogic.client.DatabaseClient类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseClient类的具体用法?Java DatabaseClient怎么用?Java DatabaseClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseClient类属于com.marklogic.client包,在下文中一共展示了DatabaseClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClientBasedOnAuth
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
/**
* Public utility that returns DatabaseClient based on auth
* @return DatabaseClient
*/
public DatabaseClient getClientBasedOnAuth(String host, int port, String user, String password, String database, String auth) {
Authentication type;
if(auth != null)
{
type = Authentication.valueOfUncased(auth);
if(type == Authentication.BASIC)
{
return DatabaseClientFactory.newClient(host, port, database, new DatabaseClientFactory.BasicAuthContext(user, password));
}
else if(type == Authentication.DIGEST)
{
return DatabaseClientFactory.newClient(host, port, new DatabaseClientFactory.DigestAuthContext(user, password));
}
}
return null;
}
示例2: setupData
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
private void setupData() {
DatabaseClient dbClient = DatabaseClientFactory.newClient(host, restPort, "admin", "admin",
Authentication.DIGEST);
String tripleDocOne = "<semantic-document>\n" + "<title>First Title</title>\n" + "<popularity>1</popularity>\n"
+ "<size>100</size>\n" + "<sem:triples xmlns:sem=\"http://marklogic.com/semantics\">"
+ "<sem:triple><sem:subject>http://example.org/r9928</sem:subject>"
+ "<sem:predicate>http://example.org/p3</sem:predicate>"
+ "<sem:object datatype=\"http://www.w3.org/2001/XMLSchema#int\">1</sem:object></sem:triple>"
+ "</sem:triples>\n" + "</semantic-document>";
String tripleDocTwo = "<semantic-document>\n" + "<title>Second Title</title>\n" + "<popularity>5</popularity>\n"
+ "<size>500</size>\n" + "<sem:triples xmlns:sem=\"http://marklogic.com/semantics\">"
+ "<sem:triple><sem:subject>http://example.org/r9929</sem:subject>"
+ "<sem:predicate>http://example.org/p3</sem:predicate>"
+ "<sem:object datatype=\"http://www.w3.org/2001/XMLSchema#int\">2</sem:object></sem:triple>"
+ "</sem:triples>\n" + "</semantic-document>";
DataMovementManager dmManager = dbClient.newDataMovementManager();
WriteBatcher batcher = dmManager.newWriteBatcher();
batcher.add("/directory1/doc1.xml", new StringHandle().with(tripleDocOne)).add("/directory2/doc2.xml",
new StringHandle().with(tripleDocTwo));
batcher.flushAndWait();
dbClient.release();
}
示例3: writeQueryOption
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
public void writeQueryOption(DatabaseClient client, String queryOptionName) throws FileNotFoundException
{
// create a manager for writing query options
QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager();
// create handle
ReaderHandle handle = new ReaderHandle();
// write the files
BufferedReader docStream = new BufferedReader(new FileReader(MarkLogicRepositoryConnectionTest.class.getResource(TEST_DIR_PREFIX+ queryOptionName).getFile()));
handle.set(docStream);
//handle.setFormat(Format.XML);
// write the query options to the database
optionsMgr.writeOptions(queryOptionName, handle);
System.out.println("Write " + queryOptionName + " to database");
}
示例4: auth
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
/**
* Authenticate the given user with MarkLogic database, returns false
* if unsuccessful since user has no permissions to access the database.
*/
public synchronized boolean auth(String username, String password) {
logger.info("Setting up connection to MarkLogic server {}:{} for user {} ...", host, port, username);
try {
DatabaseClient client = DatabaseClientFactory.newClient(host, port, username, password,
DatabaseClientFactory.Authentication.DIGEST);
// ~~
testQuery(client);
logger.info("Successfully logged in {}", username);
clients.putIfAbsent(username, client);
return true;
} catch (Exception e) {
logger.warn("Unable to login user {}: {}", username, e.getMessage());
return false;
}
}
示例5: execute
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
@Override
public void execute(CommandContext context) {
if (pattern == null || pattern.trim().length() == 0) {
logger.warn("No pattern was specified, so not deleting any modules");
}
AppConfig appConfig = context.getAppConfig();
String dbName = databaseName != null ? databaseName : appConfig.getModulesDatabaseName();
if (logger.isInfoEnabled()) {
logger.info(format("Deleting modules in database '%s' with URIs matching pattern '%s'", dbName, pattern));
}
DatabaseClient client = appConfig.newAppServicesDatabaseClient(dbName);
String xquery = "for $uri in cts:uri-match('%s') where fn:doc-available($uri) return xdmp:document-delete($uri)";
try {
client.newServerEval().xquery(format(xquery, pattern)).evalAs(String.class);
if (logger.isInfoEnabled()) {
logger.info("Finished deleting modules");
}
} finally {
client.release();
}
}
示例6: execute
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
@Override
public void execute(CommandContext context) {
AppConfig appConfig = context.getAppConfig();
String modelsPath = appConfig.getModelsPath();
File modelsDir = new File(modelsPath);
if (modelsDir.exists()) {
DatabaseClient client = appConfig.newDatabaseClient();
EntityServicesManager mgr = new EntityServicesManager(client);
for (File f : modelsDir.listFiles()) {
GeneratedCode code = loadModelDefinition(appConfig, f, mgr);
File modulesDir = selectModulesDir(appConfig);
modulesDir.mkdirs();
generateInstanceConverter(appConfig, code, modulesDir);
generateSearchOptions(code, modulesDir);
generateDatabaseProperties(appConfig, code);
generateSchema(appConfig, code);
generateExtractionTemplate(appConfig, code);
}
}
}
示例7: loadSchemasIntoSchemasDatabase
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
protected void loadSchemasIntoSchemasDatabase(CommandContext context) {
AppConfig config = context.getAppConfig();
DatabaseClient client = config.newSchemasDatabaseClient();
SchemasLoader schemasLoader = buildSchemasLoader(context, client);
try {
String schemasPath = config.getSchemasPath();
logger.info("Loading schemas from path: " + schemasPath);
schemasLoader.loadSchemas(schemasPath);
logger.info("Finished loading schemas from: " + schemasPath);
} catch (FailedRequestException fre) {
if (fre.getMessage().contains("NOSUCHDB")) {
logger.warn("Unable to load schemas because no schemas database exists; cause: " + fre.getMessage());
}
else {
throw fre;
}
} finally {
client.release();
}
}
示例8: testSchemaLoading
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
@Test
public void testSchemaLoading() {
initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(),
new DeployContentDatabasesCommand(1), newCommand());
appDeployer.deploy(appConfig);
DatabaseClient client = appConfig.newSchemasDatabaseClient();
GenericDocumentManager docMgr = client.newDocumentManager();
assertNull("Rules document loaded", docMgr.exists("notExists"));
assertNotNull("Rules document loaded", docMgr.exists("/my.rules").getUri());
assertNotNull("XSD document loaded", docMgr.exists("/x.xsd").getUri());
assertNull(docMgr.exists("/.do-not-load"));
assertNull(docMgr.exists(".do-not-load"));
}
示例9: testCustomSchemasPathWithCustomFileFilter
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
@Test
public void testCustomSchemasPathWithCustomFileFilter() {
initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(),
new DeployContentDatabasesCommand(1), newCommand());
appConfig.setSchemasPath("src/test/resources/schemas-marklogic9");
appConfig.setSchemasFileFilter(new CustomFileFilter());
appDeployer.deploy(appConfig);
DatabaseClient client = appConfig.newSchemasDatabaseClient();
GenericDocumentManager docMgr = client.newDocumentManager();
assertNotNull("TDEXML document loaded", docMgr.exists("/x.tdex").getUri());
assertNotNull("TDEJSON document loaded", docMgr.exists("/x.tdej").getUri());
assertNull(docMgr.exists("/to-be-ignored/test.xml"));
assertNull(docMgr.exists("to-be-ignored/test.xml"));
for (String uri : new String[]{"/x.tdex", "/x.tdej"}) {
DocumentMetadataHandle h = docMgr.readMetadata(uri, new DocumentMetadataHandle());
assertEquals("Files ending in tdex and tdej go into a special collection", "http://marklogic.com/xdmp/tde",
h.getCollections().iterator().next());
}
}
示例10: install
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
public static void install(DatabaseClient client) throws IOException {
ResourceExtensionsManager resourceMgr = client.newServerConfigManager()
.newResourceExtensionsManager();
ExtensionMetadata metadata = new ExtensionMetadata();
metadata.setTitle("SPARQL Resource Services");
metadata.setDescription("This plugin supports SPARQL operations");
metadata.setProvider("MarkLogic");
metadata.setVersion("0.1");
InputStream sourceStream = SPARQLManager.class.getClassLoader().getResourceAsStream("scripts/sparql-service.xqy");
if (sourceStream == null)
throw new RuntimeException("Could not read sparql service resource extension");
InputStreamHandle handle = new InputStreamHandle(sourceStream);
MethodParameters post = new MethodParameters(MethodType.POST);
post.add("default-graph-uri", "xs:string");
post.add("named-graph-uri", "xs:string");
post.add("format", "xs:string");
resourceMgr.writeServices(NAME, handle, metadata, post);
}
示例11: handleBatch
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
@Override
public void handleBatch(DatabaseClient client, List<? extends DocumentWriteOperation> items) {
DocumentManager<?, ?> mgr = buildDocumentManager(client);
if (contentFormat != null) {
mgr.setContentFormat(contentFormat);
}
DocumentWriteSet set = mgr.newWriteSet();
for (DocumentWriteOperation item : items) {
set.add(item);
}
int count = set.size();
if (logger.isDebugEnabled()) {
logger.debug("Writing " + count + " documents to MarkLogic");
}
if (serverTransform != null) {
mgr.write(set, serverTransform);
} else {
mgr.write(set);
}
if (logger.isInfoEnabled()) {
logger.info("Wrote " + count + " documents to MarkLogic");
}
}
示例12: run
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
@Override
public QueryBatcherJobTicket run(DatabaseClient databaseClient) {
QueryBatcherJobTicket ticket = super.run(databaseClient);
if (ticket.getQueryBatcher().isStopped()) {
try {
if (fileFooter != null) {
fileWriter.write(fileFooter);
}
} catch (IOException ie) {
throw new RuntimeException(ie);
} finally {
try {
this.fileWriter.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return ticket;
}
示例13: buildQueryBatcher
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
@Override
public QueryBatcher buildQueryBatcher(DatabaseClient databaseClient, DataMovementManager dataMovementManager) {
ServerEvaluationCall call = databaseClient.newServerEval();
if (javascript != null) {
if (wrapQueryIfAppropriate) {
javascript = wrapJavascriptIfAppropriate(javascript);
}
if (logger.isInfoEnabled()) {
logger.info("Calling JavaScript: " + javascript);
}
call = call.javascript(javascript);
} else if (xquery != null) {
if (wrapQueryIfAppropriate) {
xquery = wrapXqueryIfAppropriate(xquery);
}
if (logger.isInfoEnabled()) {
logger.info("Calling XQuery: " + xquery);
}
call = call.xquery(xquery);
} else {
throw new IllegalStateException("Either xquery or javascript must be defined");
}
return dataMovementManager.newQueryBatcher(new EvalResultIterator(call.eval().iterator()));
}
示例14: MarkLogicRepository
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
/**
* Constructor initialized with MarkLogic Java Client Api DatabaseClient.
*
* @param databaseClient a Java Client API DatabaseClient. Can be made with com.marklogic.client.DatabaseClientFactory
*/
public MarkLogicRepository(DatabaseClient databaseClient) {
super();
this.f = SimpleValueFactory.getInstance();
this.databaseClient = databaseClient;
this.quadMode = true;
this.host = databaseClient.getHost();
this.port = databaseClient.getPort();
this.database = databaseClient.getDatabase();
this.securityContext = databaseClient.getSecurityContext();
this.client = new MarkLogicClient(databaseClient);
}
示例15: TestRepoWithJavaAPIClientDatabaseClient
import com.marklogic.client.DatabaseClient; //导入依赖的package包/类
@Test
public void TestRepoWithJavaAPIClientDatabaseClient()
throws Exception {
DatabaseClient databaseClient = DatabaseClientFactory.newClient(host, port, new DatabaseClientFactory.DigestAuthContext(user, password));
Repository rep = new MarkLogicRepository(databaseClient);
rep.initialize();
Assert.assertTrue(rep instanceof Repository);
RepositoryConnection conn = rep.getConnection();
Assert.assertTrue(conn instanceof RepositoryConnection);
conn.close();
rep.shutDown();
}