当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseClient类代码示例

本文整理汇总了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;
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:24,代码来源:Util.java

示例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();

}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:26,代码来源:MarkLogicRepositoryConnectionTest.java

示例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");
}
 
开发者ID:marklogic,项目名称:marklogic-sesame,代码行数:20,代码来源:MarkLogicRepositoryConnectionTest.java

示例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;
    }
}
 
开发者ID:nikos,项目名称:spring-boot-starter-marklogic,代码行数:20,代码来源:MarkLogicConnections.java

示例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();
	}
}
 
开发者ID:marklogic-community,项目名称:ml-app-deployer,代码行数:26,代码来源:DeleteModulesCommand.java

示例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);
		}
	}
}
 
开发者ID:marklogic-community,项目名称:ml-app-deployer,代码行数:23,代码来源:GenerateModelArtifactsCommand.java

示例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();
	}
}
 
开发者ID:marklogic-community,项目名称:ml-app-deployer,代码行数:21,代码来源:LoadSchemasCommand.java

示例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"));
}
 
开发者ID:marklogic-community,项目名称:ml-app-deployer,代码行数:17,代码来源:LoadSchemasTest.java

示例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());
	}
}
 
开发者ID:marklogic-community,项目名称:ml-app-deployer,代码行数:25,代码来源:LoadSchemasTest.java

示例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);
}
 
开发者ID:nikos,项目名称:spring-boot-starter-marklogic,代码行数:24,代码来源:SPARQLManager.java

示例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");
	}
}
 
开发者ID:marklogic-community,项目名称:ml-javaclient-util,代码行数:25,代码来源:DefaultBatchHandler.java

示例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;
}
 
开发者ID:marklogic-community,项目名称:ml-javaclient-util,代码行数:23,代码来源:ExportToFileJob.java

示例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()));
}
 
开发者ID:marklogic-community,项目名称:ml-javaclient-util,代码行数:26,代码来源:UrisQueryQueryBatcherBuilder.java

示例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);
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:17,代码来源:MarkLogicRepository.java

示例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();
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:13,代码来源:MarkLogicRepositoryTest.java


注:本文中的com.marklogic.client.DatabaseClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。