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


Java JdbcTemplate.getDataSource方法代码示例

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


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

示例1: PGSynchronizedQuery

import org.springframework.jdbc.core.JdbcTemplate; //导入方法依赖的package包/类
PGSynchronizedQuery(@NonNull JdbcTemplate jdbcTemplate, @NonNull String sql,
        @NonNull PreparedStatementSetter setter, @NonNull RowCallbackHandler rowHandler,
        AtomicLong serialToContinueFrom, PGLatestSerialFetcher fetcher) {
    this.serialToContinueFrom = serialToContinueFrom;
    latestFetcher = fetcher;
    this.jdbcTemplate = jdbcTemplate;
    this.sql = sql;
    this.setter = setter;
    this.rowHandler = rowHandler;

    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(
            jdbcTemplate.getDataSource());
    transactionTemplate = new TransactionTemplate(transactionManager);
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:15,代码来源:PGSynchronizedQuery.java

示例2: getPagedMetricByKeyword

import org.springframework.jdbc.core.JdbcTemplate; //导入方法依赖的package包/类
public static ObjectNode getPagedMetricByKeyword(final String category, String keyword, int page, int size)
{
	List<Metric> pagedMetrics = new ArrayList<Metric>();
	final JdbcTemplate jdbcTemplate = getJdbcTemplate();
	javax.sql.DataSource ds = jdbcTemplate.getDataSource();
	DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);

	TransactionTemplate txTemplate = new TransactionTemplate(tm);

	ObjectNode result;
	result = txTemplate.execute(new TransactionCallback<ObjectNode>()
	{
		public ObjectNode doInTransaction(TransactionStatus status)
		{
			String query = SEARCH_METRIC_WITH_PAGINATION.replace("$keyword", keyword);
			List<Map<String, Object>> rows = null;
			rows = jdbcTemplate.queryForList(query, (page-1)*size, size);
			for (Map row : rows) {

				Metric metric = new Metric();
				metric.id = (Integer)row.get(MetricRowMapper.METRIC_ID_COLUMN);
				metric.name = (String)row.get(MetricRowMapper.METRIC_NAME_COLUMN);
				metric.refID = (String)row.get(MetricRowMapper.METRIC_REF_ID_COLUMN);
				metric.refIDType = (String)row.get(MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN);
				metric.description = (String)row.get(MetricRowMapper.METRIC_DESCRIPTION_COLUMN);
				metric.dashboardName = (String)row.get(MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN);
				metric.category = (String)row.get(MetricRowMapper.METRIC_CATEGORY_COLUMN);
				metric.group = (String)row.get(MetricRowMapper.METRIC_GROUP_COLUMN);
				metric.source = "metric";
				metric.urn = "";
				if (StringUtils.isNotBlank(metric.dashboardName))
				{
					metric.urn += metric.dashboardName + "/";
				}
				if (StringUtils.isNotBlank(metric.group))
				{
					metric.urn += metric.group + "/";
				}
				if (StringUtils.isNotBlank(metric.name))
				{
					metric.urn += metric.name;
				}

				ObjectNode schema = Json.newObject();
				schema.put(MetricRowMapper.METRIC_REF_ID_COLUMN, metric.refID);
				schema.put(MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN, metric.refIDType);
				schema.put(MetricRowMapper.METRIC_DESCRIPTION_COLUMN, metric.description);
				schema.put(MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN, metric.dashboardName);
				schema.put(MetricRowMapper.METRIC_CATEGORY_COLUMN, metric.category);
				schema.put(MetricRowMapper.METRIC_GROUP_COLUMN, metric.group);
				metric.schema = schema.toString();
				pagedMetrics.add(metric);
			}
			long count = 0;
			try {
				count = jdbcTemplate.queryForObject(
						"SELECT FOUND_ROWS()",
						Long.class);
			}
			catch(EmptyResultDataAccessException e)
			{
				Logger.error("Exception = " + e.getMessage());
			}

			ObjectNode resultNode = Json.newObject();
			resultNode.put("count", count);
			resultNode.put("page", page);
			resultNode.put("category", category);
			resultNode.put("itemsPerPage", size);
			resultNode.put("totalPages", (int)Math.ceil(count/((double)size)));
			resultNode.set("data", Json.toJson(pagedMetrics));

			return resultNode;
		}
	});

	return result;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:79,代码来源:SearchDAO.java

示例3: getPagedFlowByKeyword

import org.springframework.jdbc.core.JdbcTemplate; //导入方法依赖的package包/类
public static ObjectNode getPagedFlowByKeyword(String category, String keyword, int page, int size)
{
	final List<FlowJob> pagedFlows = new ArrayList<FlowJob>();
	final JdbcTemplate jdbcTemplate = getJdbcTemplate();
	javax.sql.DataSource ds = jdbcTemplate.getDataSource();
	DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);

	TransactionTemplate txTemplate = new TransactionTemplate(tm);

	ObjectNode result;
	result = txTemplate.execute(new TransactionCallback<ObjectNode>()
	{
		public ObjectNode doInTransaction(TransactionStatus status)
		{
			String query = SEARCH_FLOW_WITH_PAGINATION.replace("$keyword", keyword);
			List<Map<String, Object>> rows = null;

			rows = jdbcTemplate.queryForList(query, (page-1)*size, size);
			for (Map row : rows) {

				FlowJob flow = new FlowJob();
				flow.flowId = (Long)row.get(FlowRowMapper.FLOW_ID_COLUMN);
				flow.flowName = (String)row.get(FlowRowMapper.FLOW_NAME_COLUMN);
				flow.flowPath = (String)row.get(FlowRowMapper.FLOW_PATH_COLUMN);
				flow.flowGroup = (String)row.get(FlowRowMapper.FLOW_GROUP_COLUMN);
				flow.appCode = (String)row.get(FlowRowMapper.APP_CODE_COLUMN);
				flow.appId = (Integer)row.get(FlowRowMapper.APP_ID_COLUMN);
				flow.displayName = flow.flowName;
				flow.link = "#/flows/name/" + flow.appCode + "/" +
						Long.toString(flow.flowId) + "/page/1?urn=" + flow.flowGroup;
				flow.path = flow.appCode + "/" + flow.flowPath;
				pagedFlows.add(flow);
			}
			long count = 0;
			try {
				count = jdbcTemplate.queryForObject(
						"SELECT FOUND_ROWS()",
						Long.class);
			}
			catch(EmptyResultDataAccessException e)
			{
				Logger.error("Exception = " + e.getMessage());
			}

			ObjectNode resultNode = Json.newObject();
			resultNode.put("count", count);
			resultNode.put("isFlowJob", true);
			resultNode.put("page", page);
			resultNode.put("category", category);
			resultNode.put("itemsPerPage", size);
			resultNode.put("totalPages", (int)Math.ceil(count/((double)size)));
			resultNode.set("data", Json.toJson(pagedFlows));

			return resultNode;
		}
	});

	return result;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:60,代码来源:SearchDAO.java

示例4: getPagedJobByKeyword

import org.springframework.jdbc.core.JdbcTemplate; //导入方法依赖的package包/类
public static ObjectNode getPagedJobByKeyword(String category, String keyword, int page, int size)
{
	final List<FlowJob> pagedFlowJobs = new ArrayList<FlowJob>();
	final JdbcTemplate jdbcTemplate = getJdbcTemplate();
	javax.sql.DataSource ds = jdbcTemplate.getDataSource();
	DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);

	TransactionTemplate txTemplate = new TransactionTemplate(tm);

	ObjectNode result;
	result = txTemplate.execute(new TransactionCallback<ObjectNode>()
	{
		public ObjectNode doInTransaction(TransactionStatus status)
		{
			String query = SEARCH_JOB_WITH_PAGINATION.replace("$keyword", keyword);
			List<Map<String, Object>> rows = null;

			rows = jdbcTemplate.queryForList(query, (page-1)*size, size);
			for (Map row : rows) {

				FlowJob flowJob = new FlowJob();
				flowJob.flowId = (Long)row.get(FlowRowMapper.FLOW_ID_COLUMN);
				flowJob.jobId = (Long)row.get(FlowRowMapper.JOB_ID_COLUMN);
				flowJob.jobName = (String)row.get(FlowRowMapper.JOB_NAME_COLUMN);
				flowJob.jobPath = (String)row.get(FlowRowMapper.JOB_PATH_COLUMN);
				flowJob.jobType = (String)row.get(FlowRowMapper.JOB_TYPE_COLUMN);
				flowJob.flowName = (String)row.get(FlowRowMapper.FLOW_NAME_COLUMN);
				flowJob.flowPath = (String)row.get(FlowRowMapper.FLOW_PATH_COLUMN);
				flowJob.flowGroup = (String)row.get(FlowRowMapper.FLOW_GROUP_COLUMN);
				flowJob.appCode = (String)row.get(FlowRowMapper.APP_CODE_COLUMN);
				flowJob.appId = (Integer)row.get(FlowRowMapper.APP_ID_COLUMN);
				flowJob.displayName = flowJob.jobName;
				flowJob.link = "#/flows/name/" + flowJob.appCode + "/" +
						Long.toString(flowJob.flowId) + "/page/1?urn=" + flowJob.flowGroup;
				flowJob.path = flowJob.appCode + "/" + flowJob.jobPath;

				pagedFlowJobs.add(flowJob);
			}
			long count = 0;
			try {
				count = jdbcTemplate.queryForObject(
						"SELECT FOUND_ROWS()",
						Long.class);
			}
			catch(EmptyResultDataAccessException e)
			{
				Logger.error("Exception = " + e.getMessage());
			}

			ObjectNode resultNode = Json.newObject();
			resultNode.put("count", count);
			resultNode.put("isFlowJob", true);
			resultNode.put("page", page);
			resultNode.put("category", category);
			resultNode.put("itemsPerPage", size);
			resultNode.put("totalPages", (int)Math.ceil(count/((double)size)));
			resultNode.set("data", Json.toJson(pagedFlowJobs));

			return resultNode;
		}
	});

	return result;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:65,代码来源:SearchDAO.java

示例5: getMicroDataSource

import org.springframework.jdbc.core.JdbcTemplate; //导入方法依赖的package包/类
public DataSource getMicroDataSource(){
	//JdbcTemplate retTemplate=(JdbcTemplate) MicroDbHolder.getDbSource(dbName);
	JdbcTemplate retTemplate=(JdbcTemplate) getMicroJdbcTemplate(dbName);
	return retTemplate.getDataSource();
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:6,代码来源:MicroMetaDao.java


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