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


Java ContentSource.newSession方法代码示例

本文整理汇总了Java中com.marklogic.xcc.ContentSource.newSession方法的典型用法代码示例。如果您正苦于以下问题:Java ContentSource.newSession方法的具体用法?Java ContentSource.newSession怎么用?Java ContentSource.newSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.marklogic.xcc.ContentSource的用法示例。


在下文中一共展示了ContentSource.newSession方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runQuery

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
public static ResultSequence runQuery(String xccUri, String query, String queryLanguage) 
        throws XccConfigException, URISyntaxException, RequestException {
    ContentSource cs = csMap.get(xccUri);
    if (cs == null) {
        cs = ContentSourceFactory.newContentSource(new URI(
        xccUri));
        csMap.put(xccUri, cs);
    }
    session = cs.newSession();
    AdhocQuery aquery = session.newAdhocQuery(query);

    RequestOptions options = new RequestOptions();
    options.setQueryLanguage(queryLanguage);
    options.setCacheResult(false);
    options.setDefaultXQueryVersion("1.0-ml");
    aquery.setOptions(options);
    return session.submitRequest(aquery);
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:19,代码来源:Utils.java

示例2: runQueryAgainstDb

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
public static ResultSequence runQueryAgainstDb(String xccUri, String query, String db)
    throws XccConfigException, URISyntaxException, RequestException {
    StringBuilder buf = new StringBuilder();
    buf.append("xdmp:eval('");
    buf.append(query);
    buf.append("',(),<options xmlns=\"xdmp:eval\">\n" + 
            "            <database>{xdmp:database(\"");
    buf.append(db);
    buf.append("\")}</database>\n" + 
            "          </options>)");
    ContentSource cs = csMap.get(xccUri);
    if (cs == null) {
        cs = ContentSourceFactory.newContentSource(new URI(
        xccUri));
        csMap.put(xccUri, cs);
    }
    session = cs.newSession();
    AdhocQuery aquery = session.newAdhocQuery(buf.toString());

    RequestOptions options = new RequestOptions();
    options.setCacheResult(false);
    options.setDefaultXQueryVersion("1.0-ml");
    aquery.setOptions(options);
    return session.submitRequest(aquery);
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:26,代码来源:Utils.java

示例3: getSession

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
/**
 * Get the session for this writer.  One writer only maintains one session.
 * 
 * @return Session for this writer.
 * @throws IOException
 */
protected Session getSession() throws IOException {
    if (session == null) {
        // start a session
        try {
            ContentSource cs = InternalUtilities.getOutputContentSource(
                    conf, hostName);
            session = cs.newSession();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Connect to " + session.getConnectionUri().getHost());
            }
            if (txnSize > 1) {
                session.setTransactionMode(TransactionMode.UPDATE);
            }
        } catch (XccConfigException e) {
            LOG.error("Error creating a new session: ", e);
            throw new IOException(e);
        }    
    }
    return session;
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:27,代码来源:MarkLogicRecordWriter.java

示例4: buildRunnable

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
protected Runnable buildRunnable(final ContentSource contentSource, final List<? extends DocumentWriteOperation> items) {
	return new Runnable() {
		@Override
		public void run() {
			Session session = contentSource.newSession();
			int count = items.size();
			Content[] array = new Content[count];
			for (int i = 0; i < count; i++) {
				array[i] = documentWriteOperationAdapter.adapt(items.get(i));
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Writing " + count + " documents to MarkLogic");
			}
			try {
				session.insertContent(array);
				if (logger.isInfoEnabled()) {
					logger.info("Wrote " + count + " documents to MarkLogic");
				}
			} catch (RequestException e) {
				throw new RuntimeException("Unable to insert content: " + e.getMessage(), e);
			} finally {
				session.close();
			}
		}
	};
}
 
开发者ID:marklogic-community,项目名称:ml-javaclient-util,代码行数:27,代码来源:XccBatchWriter.java

示例5: execCommand

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
@Override
protected int execCommand(String command, Map<String, Parameter> params) throws RequestException {
       if ("insertDocument".equals(command)) {

       	ContentCreateOptions options = ContentCreateOptions.newXmlInstance();
       	//options.setNamespace("MyNameSpace");
           String collect = params.get("collect").getName();
           if (collect != null) {
           	options.setCollections(new String[] {collect});
           }
           String prefix = params.get("prefix").getName();
           if (prefix == null) {
           	prefix = "doc";
           }
           String uri = prefix + cnt.getAndIncrement() + ".xml";
           String doc = params.get("doc").getName();
       	Content content = ContentFactory.newContent(uri, doc, options);
   		ContentSource xcs = getContentSource();
   		Session xss = xcs.newSession();
       	xss.insertContent(content);       
       	xss.close();
           return 1;
       }
	return 0;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:26,代码来源:MarkLogicXCCPlugin.java

示例6: execQuery

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
@Override
protected int execQuery(String query, Map<String, Parameter> params) throws RequestException {
	
	ContentSource xcs = getContentSource();
	Session xss = xcs.newSession();
	//xss.getDefaultRequestOptions().setResultBufferSize(fetchSize);
	Request request = xss.newAdhocQuery(query);
	bindParams(params, request);
	ResultSequence rs = xss.submitRequest(request);		
    int cnt = 0;
    if (fetchSize > 0) {
    	while (rs.hasNext() && cnt < fetchSize) {
    		rs.next();
    		cnt++;
    	}
    } else {
    	while (rs.hasNext()) {
    		rs.next();
    		cnt++;
    	}
    }
    rs.close();
    xss.close();
    return cnt;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:26,代码来源:MarkLogicXCCPlugin.java

示例7: runApp

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
@Override
public void runApp() throws Exception {
    URI uri = new URI(String.format(XCC_CONNECTION_URI_TEMPLATE, config.getUsername(), config.getPassword(), config.getHost(), config.getPort(), config.getDatabaseName()));
    ContentSource contentSource = ContentSourceFactory.newContentSource(uri);
    try (Session session = contentSource.newSession()) {
        Request request = session.newAdhocQuery(readFile(config.getMainFile()));
        for (XQueryRunnerVariable variable : config.getVariables()) {
            if (variable.ACTIVE) {
                request.setNewVariable(getName(variable.NAME, variable.NAMESPACE), getXdmValue(variable.TYPE,
                        variable.VALUE));
            }
        }
        ResultSequence rs = session.submitRequest(request);
        output.println(rs.asString());
    }
}
 
开发者ID:ligasgr,项目名称:intellij-xquery,代码行数:17,代码来源:MarklogicRunnerApp.java

示例8: assertDocsFormat

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
public static ResultSequence assertDocsFormat(String xccUri, String docType) 
        throws XccConfigException, URISyntaxException, RequestException {
    ContentSource cs = csMap.get(xccUri);
    if (cs == null) {
        cs = ContentSourceFactory.newContentSource(new URI(
        xccUri));
        csMap.put(xccUri, cs);
    }
    
    session = cs.newSession();
    String query = "function testDocument() {"
            + "var it=fn.doc();"
            + "for (var u of it) {"
            + "if (u.documentFormat != '" + docType +"') {"
            + "return false;"
            + "}}"
            + "return true;}"
            + "testDocument();";
    AdhocQuery aquery = session.newAdhocQuery(query);
    
    RequestOptions options = new RequestOptions();
    options.setCacheResult(false);
    options.setQueryLanguage("javascript");
    aquery.setOptions(options);
    
    return session.submitRequest(aquery);
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:28,代码来源:Utils.java

示例9: getMimetypesMap

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
/**
 * initialize mimetype map if not initialized, return the map
 * 
 * @return
 * @throws IOException
 */
private LinkedMapWritable getMimetypesMap() throws IOException {
    if (mimetypeMap != null)
        return mimetypeMap;
    String mtmap = conf.get(ConfigConstants.CONF_MIMETYPES);
    if (mtmap != null) {
        mimetypeMap = DefaultStringifier.load(conf,
            ConfigConstants.CONF_MIMETYPES, LinkedMapWritable.class);
        return mimetypeMap;
    }
    String host = conf.get(OUTPUT_HOST);
    Session session = null;
    ResultSequence result = null;
    try {
        ContentSource cs = InternalUtilities.getOutputContentSource(conf,
            host);
        session = cs.newSession();
        AdhocQuery query = session.newAdhocQuery(MIMETYPES_QUERY);
        RequestOptions options = new RequestOptions();
        options.setDefaultXQueryVersion("1.0-ml");
        query.setOptions(options);
        result = session.submitRequest(query);
        if (!result.hasNext())
            throw new IOException(
                "Server-side transform requires MarkLogic 7 or later");
        mimetypeMap = new LinkedMapWritable();
        while (result.hasNext()) {
            String suffs = result.next().asString();
            Text format = new Text(result.next().asString());
            // some extensions are in a space separated string
            for (String s : suffs.split(" ")) {
                Text suff = new Text(s);
                mimetypeMap.put(suff, format);
            }
        }
        return mimetypeMap;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new IOException(e);
    } finally {
        if (result != null) {
            result.close();
        }
        if (session != null) {
            session.close();
        }
    }
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:54,代码来源:TransformOutputFormat.java

示例10: testBug20168

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
@Test
public void testBug20168() throws Exception {
	String cmd = "COPY -input_host localhost "
			+ "-input_username admin -input_password admin "
			+ "-output_host localhost -output_username admin "
			+ "-output_password admin -thread_count 1"
			+ " -input_port " + Constants.port + " -input_database " + Constants.testDb
			+ " -output_port " + Constants.port + " -output_database " + Constants.copyDst;

	String[] args = cmd.split(" ");

	Utils.clearDB(Utils.getTestDbXccUri(), Constants.testDb);
	ContentCreateOptions options = new ContentCreateOptions();
	options.setFormatXml();

	ContentSource cs = ContentSourceFactory.newContentSource(new URI(
			Utils.getTestDbXccUri()));
	Session session = cs.newSession();

	session.setTransactionMode(TransactionMode.UPDATE);
	Content content = ContentFactory.newContent("nocontent", new byte[0],
			0, 0, options);
	session.insertContent(content);
	byte[] str = "<r>some content</r>".getBytes();
	content = ContentFactory.newContent("hascontent", str, 0, str.length,
			options);
	session.insertContent(content);
	session.commit();
	session.close();

	Utils.clearDB(Utils.getTestDbXccUri(), Constants.copyDst);

	String[] expandedArgs = null;
	expandedArgs = OptionsFileUtil.expandArguments(args);
	ContentPump.runCommand(expandedArgs);
	
	ResultSequence result = Utils
			.runQuery(Utils.getTestDbXccUri(),
					"fn:count(fn:collection())");
	assertTrue(result.hasNext());
	assertEquals("2", result.next().asString());
	Utils.closeSession();
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:44,代码来源:TestCopy.java

示例11: queryHosts

import com.marklogic.xcc.ContentSource; //导入方法依赖的package包/类
protected TextArrayWritable queryHosts(ContentSource cs, String matchHost,
		String replaceHost)
    throws IOException {
    Session session = null;
    ResultSequence result = null;
    try {
        session = cs.newSession();
        AdhocQuery query = session.newAdhocQuery(HOSTS_QUERY);
        // query hosts
        RequestOptions options = new RequestOptions();
        options.setDefaultXQueryVersion("1.0-ml");
        query.setOptions(options);
        result = session.submitRequest(query);

        ArrayList<Text> hosts = new ArrayList<Text>();
        while (result.hasNext()) {
            ResultItem item = result.next();
            String host = item.asString();
            if (matchHost != null && host.equals(matchHost)) {
            	hosts.add(new Text(replaceHost));
            } else {
                hosts.add(new Text(host));
            }
        }
        if (hosts.isEmpty()) {
            throw new IOException("Target database has no forests attached: "
                    + "check forests in database");
        }
        return new TextArrayWritable(hosts.toArray(new Text[hosts.size()]));
    } catch (RequestException e) {
        LOG.error(e.getMessage(), e);
        throw new IOException(e);
    } finally {
        if (result != null) {
            result.close();
        }
        if (session != null) {
            session.close();
        }
    }
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:42,代码来源:MarkLogicOutputFormat.java


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