List of usage examples for org.springframework.dao EmptyResultDataAccessException getMessage
@Override
@Nullable
public String getMessage()
From source file:dao.FlowsDAO.java
public static ObjectNode getPagedFlowsByProject(String applicationName, String project, int page, int size) { ObjectNode result;//from www .j a va 2 s . c o m if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(project)) { result = Json.newObject(); result.put("count", 0); result.put("page", page); result.put("itemsPerPage", size); result.put("totalPages", 0); result.set("flows", Json.toJson("")); return result; } String application = applicationName.replace(".", " "); Integer appID = getApplicationIDByName(applicationName); if (appID != 0) { javax.sql.DataSource ds = getJdbcTemplate().getDataSource(); DataSourceTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate txTemplate = new TransactionTemplate(tm); final int applicationID = appID; result = txTemplate.execute(new TransactionCallback<ObjectNode>() { public ObjectNode doInTransaction(TransactionStatus status) { ObjectNode resultNode = Json.newObject(); long count = 0; List<Flow> pagedFlows = new ArrayList<Flow>(); List<Map<String, Object>> rows = null; if (StringUtils.isNotBlank(project) && (!project.equalsIgnoreCase("root"))) { rows = getJdbcTemplate().queryForList(GET_PAGED_FLOWS_BY_APP_ID_AND_PROJECT_NAME, applicationID, project, (page - 1) * size, size); } else { rows = getJdbcTemplate().queryForList(GET_PAGED_FLOWS_WITHOUT_PROJECT_BY_APP_ID, applicationID, (page - 1) * size, size); } try { count = getJdbcTemplate().queryForObject("SELECT FOUND_ROWS()", Long.class); } catch (EmptyResultDataAccessException e) { Logger.error("Exception = " + e.getMessage()); } for (Map row : rows) { Flow flow = new Flow(); flow.id = (Long) row.get("flow_id"); flow.level = (Integer) row.get("flow_level"); flow.name = (String) row.get("flow_name"); flow.path = (String) row.get("flow_path"); flow.appCode = (String) row.get("app_code"); flow.group = project; if (StringUtils.isNotBlank(flow.path)) { int index = flow.path.indexOf(":"); if (index != -1) { flow.path = flow.path.substring(0, index); } } Object created = row.get("created_time"); if (created != null) { flow.created = DateFormat.format(created.toString()); } Object modified = row.get("modified_time"); if (modified != null) { flow.modified = DateFormat.format(row.get("modified_time").toString()); } int jobCount = 0; if (flow.id != null && flow.id != 0) { try { jobCount = getJdbcTemplate().queryForObject(GET_JOB_COUNT_BY_APP_ID_AND_FLOW_ID, new Object[] { appID, flow.id }, Integer.class); flow.jobCount = jobCount; } catch (EmptyResultDataAccessException e) { Logger.error("Exception = " + e.getMessage()); } } pagedFlows.add(flow); } resultNode.set("flows", Json.toJson(pagedFlows)); resultNode.put("count", count); resultNode.put("page", page); resultNode.put("itemsPerPage", size); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); return resultNode; } }); return result; } result = Json.newObject(); result.put("count", 0); result.put("page", page); result.put("itemsPerPage", size); result.put("totalPages", 0); result.set("flows", Json.toJson("")); return result; }
From source file:dao.FlowsDAO.java
public static ObjectNode getPagedJobsByFlow(String applicationName, Long flowId, int page, int size) { ObjectNode result;/* ww w .j a v a2s .c om*/ List<Job> pagedJobs = new ArrayList<Job>(); if (StringUtils.isBlank(applicationName) || (flowId <= 0)) { result = Json.newObject(); result.put("count", 0); result.put("page", page); result.put("itemsPerPage", size); result.put("totalPages", 0); result.set("jobs", Json.toJson("")); return result; } String application = applicationName.replace(".", " "); Integer appID = getApplicationIDByName(application); if (appID != 0) { javax.sql.DataSource ds = getJdbcTemplate().getDataSource(); DataSourceTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate txTemplate = new TransactionTemplate(tm); final long azkabanFlowId = flowId; result = txTemplate.execute(new TransactionCallback<ObjectNode>() { public ObjectNode doInTransaction(TransactionStatus status) { List<Map<String, Object>> rows = null; rows = getJdbcTemplate().queryForList(GET_PAGED_JOBS_BY_APP_ID_AND_FLOW_ID, appID, azkabanFlowId, (page - 1) * size, size); long count = 0; String flowName = ""; try { count = getJdbcTemplate().queryForObject("SELECT FOUND_ROWS()", Long.class); } catch (EmptyResultDataAccessException e) { Logger.error("Exception = " + e.getMessage()); } for (Map row : rows) { Job job = new Job(); job.id = (Long) row.get("job_id"); job.name = (String) row.get("job_name"); job.path = (String) row.get("job_path"); job.path = (String) row.get("job_path"); job.refFlowGroup = (String) row.get("flow_group"); if (StringUtils.isNotBlank(job.path)) { int index = job.path.indexOf("/"); if (index != -1) { job.path = job.path.substring(0, index); } } job.type = (String) row.get("job_type"); Object created = row.get("created_time"); job.refFlowId = (Long) row.get("ref_flow_id"); if (created != null) { job.created = DateFormat.format(created.toString()); } Object modified = row.get("modified_time"); if (modified != null) { job.modified = DateFormat.format(modified.toString()); } if (StringUtils.isBlank(flowName)) { flowName = (String) row.get("flow_name"); } pagedJobs.add(job); } ObjectNode resultNode = Json.newObject(); resultNode.put("count", count); resultNode.put("flow", flowName); resultNode.put("page", page); resultNode.put("itemsPerPage", size); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); resultNode.set("jobs", Json.toJson(pagedJobs)); return resultNode; } }); return result; } result = Json.newObject(); result.put("count", 0); result.put("page", page); result.put("itemsPerPage", size); result.put("totalPages", 0); result.set("jobs", Json.toJson("")); return result; }
From source file:dao.LineageDAO.java
public static ObjectNode getFlowLineage(String application, String project, Long flowId) { ObjectNode resultNode = Json.newObject(); List<LineageNode> nodes = new ArrayList<LineageNode>(); List<LineageEdge> edges = new ArrayList<LineageEdge>(); String flowName = null;// w w w. jav a 2 s. c o m Map<Long, Integer> addedJobNodes = new HashMap<Long, Integer>(); Map<Pair, Integer> addedDataNodes = new HashMap<Pair, Integer>(); if (StringUtils.isBlank(application) || StringUtils.isBlank(project) || (flowId <= 0)) { resultNode.set("nodes", Json.toJson(nodes)); resultNode.set("links", Json.toJson(edges)); return resultNode; } String applicationName = application.replace(".", " "); int appID = 0; try { appID = getJdbcTemplate().queryForObject(GET_APP_ID, new Object[] { applicationName }, Integer.class); } catch (EmptyResultDataAccessException e) { Logger.error("getFlowLineage get application id failed, application name = " + application); Logger.error("Exception = " + e.getMessage()); } Map<Long, List<LineageNode>> nodeHash = new HashMap<Long, List<LineageNode>>(); Map<String, List<LineageNode>> partitionedNodeHash = new HashMap<String, List<LineageNode>>(); if (appID != 0) { try { flowName = getJdbcTemplate().queryForObject(GET_FLOW_NAME, new Object[] { appID, flowId }, String.class); } catch (EmptyResultDataAccessException e) { Logger.error("getFlowLineage get flow name failed, application name = " + application + " flowId " + Long.toString(flowId)); Logger.error("Exception = " + e.getMessage()); } Long flowExecId = 0L; try { flowExecId = getJdbcTemplate().queryForObject(GET_LATEST_FLOW_EXEC_ID, new Object[] { appID, flowId }, Long.class); } catch (EmptyResultDataAccessException e) { Logger.error("getFlowLineage get flow execution id failed, application name = " + application + " flowId " + Long.toString(flowExecId)); Logger.error("Exception = " + e.getMessage()); } List<Map<String, Object>> rows = null; rows = getJdbcTemplate().queryForList(GET_FLOW_DATA_LINEAGE, appID, flowExecId); if (rows != null) { for (Map row : rows) { Long jobExecId = ((BigInteger) row.get("job_exec_id")).longValue(); LineageNode node = new LineageNode(); node.abstracted_path = (String) row.get("abstracted_object_name"); node.source_target_type = (String) row.get("source_target_type"); node.exec_id = jobExecId; Object recordCountObject = row.get("record_count"); if (recordCountObject != null) { node.record_count = ((BigInteger) recordCountObject).longValue(); } node.application_id = (int) row.get("app_id"); node.cluster = (String) row.get("app_code"); node.partition_type = (String) row.get("partition_type"); node.operation = (String) row.get("operation"); node.partition_start = (String) row.get("partition_start"); node.partition_end = (String) row.get("partition_end"); node.full_object_name = (String) row.get("full_object_name"); node.job_start_time = DateFormat.format(row.get("start_time").toString()); node.job_end_time = DateFormat.format(row.get("end_time").toString()); node.storage_type = ((String) row.get("storage_type")).toLowerCase(); node.node_type = "data"; node._sort_list = new ArrayList<String>(); node._sort_list.add("cluster"); node._sort_list.add("abstracted_path"); node._sort_list.add("storage_type"); node._sort_list.add("partition_type"); node._sort_list.add("partition_start"); node._sort_list.add("partition_end"); node._sort_list.add("source_target_type"); List<LineageNode> nodeList = nodeHash.get(jobExecId); if (nodeList != null) { nodeList.add(node); } else { nodeList = new ArrayList<LineageNode>(); nodeList.add(node); nodeHash.put(jobExecId, nodeList); } } } List<LineageNode> jobNodes = new ArrayList<LineageNode>(); List<Map<String, Object>> jobRows = null; jobRows = getJdbcTemplate().queryForList(GET_FLOW_JOB, appID, flowExecId, 30); int index = 0; int edgeIndex = 0; Map<Long, LineageNode> jobNodeMap = new HashMap<Long, LineageNode>(); List<Pair> addedEdges = new ArrayList<Pair>(); if (rows != null) { for (Map row : jobRows) { Long jobExecId = ((BigInteger) row.get("job_exec_id")).longValue(); LineageNode node = new LineageNode(); node._sort_list = new ArrayList<String>(); node.node_type = "script"; node.job_type = (String) row.get("job_type"); node.cluster = (String) row.get("app_code"); node.job_path = (String) row.get("job_path"); node.job_name = (String) row.get("job_name"); node.pre_jobs = (String) row.get("pre_jobs"); node.post_jobs = (String) row.get("post_jobs"); node.job_id = (Long) row.get("job_id"); node.job_start_time = DateFormat.format(row.get("start_time").toString()); node.job_end_time = DateFormat.format(row.get("end_time").toString()); node.exec_id = jobExecId; node._sort_list.add("cluster"); node._sort_list.add("job_path"); node._sort_list.add("job_name"); node._sort_list.add("job_type"); node._sort_list.add("job_start_time"); node._sort_list.add("job_end_time"); Integer id = addedJobNodes.get(jobExecId); if (id == null) { node.id = index++; nodes.add(node); jobNodeMap.put(node.job_id, node); jobNodes.add(node); addedJobNodes.put(jobExecId, node.id); } else { node.id = id; } String sourceType = (String) row.get("source_target_type"); if (sourceType.equalsIgnoreCase("target")) { List<LineageNode> sourceNodeList = nodeHash.get(jobExecId); if (sourceNodeList != null && sourceNodeList.size() > 0) { for (LineageNode sourceNode : sourceNodeList) { if (sourceNode.source_target_type.equalsIgnoreCase("source")) { Pair matchedSourcePair = new ImmutablePair<>(sourceNode.abstracted_path, sourceNode.partition_end); Integer nodeId = addedDataNodes.get(matchedSourcePair); if (nodeId == null) { List<LineageNode> nodeList = partitionedNodeHash .get(sourceNode.abstracted_path); if (StringUtils.isBlank(sourceNode.partition_end)) { Boolean bFound = false; if (nodeList != null) { for (LineageNode n : nodeList) { if (StringUtils.isNotBlank(n.partition_end) && n.partition_end .compareTo(sourceNode.job_start_time) < 0) { sourceNode.id = n.id; bFound = true; break; } } } if (!bFound) { sourceNode.id = index++; nodes.add(sourceNode); Pair sourcePair = new ImmutablePair<>(sourceNode.abstracted_path, sourceNode.partition_end); addedDataNodes.put(sourcePair, sourceNode.id); } } else { if (nodeList == null) { nodeList = new ArrayList<LineageNode>(); } nodeList.add(sourceNode); partitionedNodeHash.put(sourceNode.abstracted_path, nodeList); sourceNode.id = index++; nodes.add(sourceNode); Pair sourcePair = new ImmutablePair<>(sourceNode.abstracted_path, sourceNode.partition_end); addedDataNodes.put(sourcePair, sourceNode.id); } } else { sourceNode.id = nodeId; } LineageEdge edge = new LineageEdge(); edge.id = edgeIndex++; edge.source = sourceNode.id; edge.target = node.id; if (StringUtils.isNotBlank(sourceNode.operation)) { edge.label = sourceNode.operation; } else { edge.label = "load"; } edge.chain = "data"; edges.add(edge); } } } } else if (sourceType.equalsIgnoreCase("source")) { List<LineageNode> targetNodeList = nodeHash.get(jobExecId); if (targetNodeList != null && targetNodeList.size() > 0) { for (LineageNode targetNode : targetNodeList) { if (targetNode.source_target_type.equalsIgnoreCase("target")) { Pair matchedTargetPair = new ImmutablePair<>(targetNode.abstracted_path, targetNode.partition_end); Integer nodeId = addedDataNodes.get(matchedTargetPair); if (nodeId == null) { List<LineageNode> nodeList = partitionedNodeHash .get(targetNode.abstracted_path); if (StringUtils.isBlank(targetNode.partition_end)) { Boolean bFound = false; if (nodeList != null) { for (LineageNode n : nodeList) { if (StringUtils.isNotBlank(n.partition_end) && n.partition_end .compareTo(targetNode.job_start_time) < 0) { targetNode.id = n.id; bFound = true; break; } } } if (!bFound) { targetNode.id = index++; nodes.add(targetNode); Pair targetPair = new ImmutablePair<>(targetNode.abstracted_path, targetNode.partition_end); addedDataNodes.put(targetPair, targetNode.id); } } else { if (nodeList == null) { nodeList = new ArrayList<LineageNode>(); } nodeList.add(targetNode); partitionedNodeHash.put(targetNode.abstracted_path, nodeList); targetNode.id = index++; nodes.add(targetNode); Pair targetPair = new ImmutablePair<>(targetNode.abstracted_path, targetNode.partition_end); addedDataNodes.put(targetPair, targetNode.id); } } else { targetNode.id = nodeId; } LineageEdge edge = new LineageEdge(); edge.id = edgeIndex++; edge.source = node.id; edge.target = targetNode.id; if (StringUtils.isNotBlank(targetNode.operation)) { edge.label = targetNode.operation; } else { edge.label = "load"; } edge.chain = "data"; edges.add(edge); } } } } } for (LineageNode node : jobNodes) { Long jobId = node.job_id; if (StringUtils.isNotBlank(node.pre_jobs)) { String[] prevJobIds = node.pre_jobs.split(","); if (prevJobIds != null) { for (String jobIdString : prevJobIds) { if (StringUtils.isNotBlank(jobIdString)) { Long id = Long.parseLong(jobIdString); LineageNode sourceNode = jobNodeMap.get(id); if (sourceNode != null) { Pair pair = new ImmutablePair<>(sourceNode.id, node.id); if (!addedEdges.contains(pair)) { LineageEdge edge = new LineageEdge(); edge.id = edgeIndex++; edge.source = sourceNode.id; edge.target = node.id; edge.label = ""; edge.type = "job"; edges.add(edge); addedEdges.add(pair); } } } } } } if (StringUtils.isNotBlank(node.post_jobs)) { String[] postJobIds = node.post_jobs.split(","); if (postJobIds != null) { for (String jobIdString : postJobIds) { if (StringUtils.isNotBlank(jobIdString)) { Long id = Long.parseLong(jobIdString); LineageNode targetNode = jobNodeMap.get(id); if (targetNode != null) { Pair pair = new ImmutablePair<>(node.id, targetNode.id); if (!addedEdges.contains(pair)) { LineageEdge edge = new LineageEdge(); edge.id = edgeIndex++; edge.source = node.id; edge.target = targetNode.id; edge.label = ""; edge.type = "job"; edges.add(edge); addedEdges.add(pair); } } } } } } } } } resultNode.set("nodes", Json.toJson(nodes)); resultNode.set("links", Json.toJson(edges)); resultNode.put("flowName", flowName); return resultNode; }
From source file:dao.MetricsDAO.java
public static ObjectNode getPagedMetrics(String dashboardName, String group, Integer page, Integer size, String user) {//w ww. j a v a 2 s . c o m Integer userId = UserDAO.getUserIDByUserName(user); final JdbcTemplate jdbcTemplate = getJdbcTemplate(); javax.sql.DataSource ds = jdbcTemplate.getDataSource(); DataSourceTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate txTemplate = new TransactionTemplate(tm); ObjectNode result; final Integer id = userId; result = txTemplate.execute(new TransactionCallback<ObjectNode>() { public ObjectNode doInTransaction(TransactionStatus status) { List<Map<String, Object>> rows; if (StringUtils.isBlank(dashboardName)) { rows = jdbcTemplate.queryForList(SELECT_PAGED_METRICS, id, (page - 1) * size, size); } else if (StringUtils.isBlank(group)) { String dbName; if (dashboardName.equals("[Other]")) { dbName = null; } else { dbName = dashboardName; } rows = jdbcTemplate.queryForList(SELECT_PAGED_METRICS_BY_DASHBOARD_NAME, id, dbName, dbName, (page - 1) * size, size); } else { String dbName; if (dashboardName.equals("[Other]")) { dbName = null; } else { dbName = dashboardName; } String grp; if (group.equals("[Other]")) { grp = null; } else { grp = group; } rows = jdbcTemplate.queryForList(SELECT_PAGED_METRICS_BY_DASHBOARD_AND_GROUP, id, dbName, dbName, grp, grp, (page - 1) * size, size); } List<Metric> pagedMetrics = new ArrayList<>(); for (Map row : rows) { Metric metric = new Metric(); metric.id = (int) row.get("metric_id"); metric.name = (String) row.get("metric_name"); metric.description = (String) row.get("metric_description"); metric.refID = (String) row.get("metric_ref_id"); metric.refIDType = (String) row.get("metric_ref_id_type"); metric.dashboardName = (String) row.get("dashboard_name"); metric.category = (String) row.get("metric_category"); metric.group = (String) row.get("metric_group"); metric.watchId = (Long) row.get("watch_id"); 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("itemsPerPage", size); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); resultNode.set("metrics", Json.toJson(pagedMetrics)); return resultNode; } }); return result; }
From source file:dao.MetricsDAO.java
public static Metric getMetricByID(int id, String user) { Integer userId = UserDAO.getUserIDByUserName(user); Metric metric = null;/*from w w w . ja v a2 s .c o m*/ try { metric = (Metric) getJdbcTemplate().queryForObject(GET_METRIC_BY_ID, new MetricRowMapper(), userId, id); } catch (EmptyResultDataAccessException e) { Logger.error("Metric getMetricByID failed, id = " + id); Logger.error("Exception = " + e.getMessage()); } return metric; }
From source file:dao.SchemaHistoryDAO.java
public static ObjectNode getPagedSchemaDataset(String name, Long datasetId, int page, int size) { ObjectNode result = Json.newObject(); javax.sql.DataSource ds = getJdbcTemplate().getDataSource(); DataSourceTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate txTemplate = new TransactionTemplate(tm); result = txTemplate.execute(new TransactionCallback<ObjectNode>() { public ObjectNode doInTransaction(TransactionStatus status) { List<SchemaDataset> pagedScripts = null; if (StringUtils.isNotBlank(name)) { if (datasetId != null && datasetId > 0) { pagedScripts = getJdbcTemplate().query(GET_SPECIFIED_SCHEMA_DATASET_WITH_FILTER, new SchemaDatasetRowMapper(), datasetId, "%" + name + "%", (page - 1) * size, size); } else { pagedScripts = getJdbcTemplate().query(GET_PAGED_SCHEMA_DATASET_WITH_FILTER, new SchemaDatasetRowMapper(), "%" + name + "%", (page - 1) * size, size); }//from ww w . j av a 2 s . co m } else { if (datasetId != null && datasetId > 0) { pagedScripts = getJdbcTemplate().query(GET_SPECIFIED_SCHEMA_DATASET, new SchemaDatasetRowMapper(), datasetId, (page - 1) * size, size); } else { pagedScripts = getJdbcTemplate().query(GET_PAGED_SCHEMA_DATASET, new SchemaDatasetRowMapper(), (page - 1) * size, size); } } long count = 0; try { count = getJdbcTemplate().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("itemsPerPage", size); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); resultNode.set("datasets", Json.toJson(pagedScripts)); return resultNode; } }); return result; }
From source file:dao.ScriptFinderDAO.java
public static ObjectNode getPagedScripts(JsonNode filterOpt, int page, int size) { ObjectNode result = Json.newObject(); javax.sql.DataSource ds = getJdbcTemplate().getDataSource(); DataSourceTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate txTemplate = new TransactionTemplate(tm); String scriptName = null;//from w w w. jav a 2 s . c o m String scriptPath = null; String scriptType = null; String chainName = null; String jobName = null; String committerName = null; String committerEmail = null; if (filterOpt != null && (filterOpt.isContainerNode())) { if (filterOpt.has("scriptName")) { scriptName = filterOpt.get("scriptName").asText(); } if (filterOpt.has("scriptPath")) { scriptPath = filterOpt.get("scriptPath").asText(); } if (filterOpt.has("scriptType")) { scriptType = filterOpt.get("scriptType").asText(); } if (filterOpt.has("chainName")) { chainName = filterOpt.get("chainName").asText(); } if (filterOpt.has("jobName")) { jobName = filterOpt.get("jobName").asText(); } if (filterOpt.has("committerName")) { committerName = filterOpt.get("committerName").asText(); } if (filterOpt.has("committerEmail")) { committerEmail = filterOpt.get("committerEmail").asText(); } } final String finalScriptName = scriptName; final String finalScriptPath = scriptPath; final String finalScriptType = scriptType; final String finalChainName = chainName; final String finalJobName = jobName; final String finalCommitterName = committerName; result = txTemplate.execute(new TransactionCallback<ObjectNode>() { public ObjectNode doInTransaction(TransactionStatus status) { List<Map<String, Object>> rows = null; String whereClause = ""; boolean needAnd = false; Map<String, Object> params = new HashMap<String, Object>(); if (StringUtils.isNotBlank(finalScriptName)) { if (StringUtils.isBlank(whereClause)) { whereClause = " WHERE "; } if (needAnd) { whereClause += " AND "; } whereClause += " script_name like :scriptname "; needAnd = true; params.put("scriptname", "%" + finalScriptName + "%"); } if (StringUtils.isNotBlank(finalScriptPath)) { if (StringUtils.isBlank(whereClause)) { whereClause = " WHERE "; } if (needAnd) { whereClause += " AND "; } whereClause += " script_path like :scriptpath "; needAnd = true; params.put("scriptpath", "%" + finalScriptPath + "%"); } if (StringUtils.isNotBlank(finalScriptType)) { if (StringUtils.isBlank(whereClause)) { whereClause = " WHERE "; } if (needAnd) { whereClause += " AND "; } whereClause += " script_type like :scripttype "; needAnd = true; params.put("scripttype", "%" + finalScriptType + "%"); } if (StringUtils.isNotBlank(finalChainName)) { if (StringUtils.isBlank(whereClause)) { whereClause = " WHERE "; } if (needAnd) { whereClause += " AND "; } whereClause += " chain_name like :chainname "; needAnd = true; params.put("chainname", "%" + finalChainName + "%"); } if (StringUtils.isNotBlank(finalJobName)) { if (StringUtils.isBlank(whereClause)) { whereClause = " WHERE "; } if (needAnd) { whereClause += " AND "; } whereClause += " job_name like :jobname "; needAnd = true; params.put("jobname", "%" + finalJobName + "%"); } if (StringUtils.isNotBlank(finalCommitterName)) { if (StringUtils.isBlank(whereClause)) { whereClause = " WHERE "; } if (needAnd) { whereClause += " AND "; } whereClause += " ( committer_ldap like :committername or committer_name like :committername )"; needAnd = true; params.put("committername", "%" + finalCommitterName + "%"); } String query = GET_PAGED_SCRIPTS.replace("$WHERE_CLAUSE", whereClause); params.put("index", (page - 1) * size); params.put("size", size); NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate( getJdbcTemplate().getDataSource()); rows = namedParameterJdbcTemplate.queryForList(query, params); long count = 0; try { count = getJdbcTemplate().queryForObject("SELECT FOUND_ROWS()", Long.class); } catch (EmptyResultDataAccessException e) { Logger.error("Exception = " + e.getMessage()); } List<ScriptInfo> pagedScripts = new ArrayList<ScriptInfo>(); for (Map row : rows) { int applicationID = (Integer) row.get(ScriptInfoRowMapper.APPLICATION_ID_COLUMN); int jobID = (Integer) row.get(ScriptInfoRowMapper.JOB_ID_COLUMN); String scriptUrl = (String) row.get(ScriptInfoRowMapper.SCRIPT_URL_COLUMN); String scriptPath = (String) row.get(ScriptInfoRowMapper.SCRIPT_PATH_COLUMN); String scriptType = (String) row.get(ScriptInfoRowMapper.SCRIPT_TYPE_COLUMN); String chainName = (String) row.get(ScriptInfoRowMapper.CHAIN_NAME_COLUMN); String jobName = (String) row.get(ScriptInfoRowMapper.JOB_NAME_COLUMN); String scriptName = (String) row.get(ScriptInfoRowMapper.SCRIPT_NAME_COLUMN); String committerName = (String) row.get(ScriptInfoRowMapper.COMMITTER_NAMES_COLUMN); String committerEmail = (String) row.get(ScriptInfoRowMapper.COMMITTER_EMAILS_COLUMN); ScriptInfo scriptInfo = new ScriptInfo(); scriptInfo.applicationID = applicationID; scriptInfo.jobID = jobID; scriptInfo.scriptUrl = scriptUrl; scriptInfo.scriptPath = scriptPath; scriptInfo.scriptType = scriptType; scriptInfo.scriptName = scriptName; scriptInfo.chainName = chainName; scriptInfo.jobName = jobName; scriptInfo.committerName = committerName; scriptInfo.committerEmail = committerEmail; pagedScripts.add(scriptInfo); } ObjectNode resultNode = Json.newObject(); resultNode.put("count", count); resultNode.put("page", page); resultNode.put("itemsPerPage", size); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); resultNode.set("scripts", Json.toJson(pagedScripts)); return resultNode; } }); return result; }
From source file:dao.SearchDAO.java
public static ObjectNode getPagedDatasetByKeyword(String category, String keyword, String source, int page, int size) { List<Dataset> pagedDatasets = new ArrayList<Dataset>(); final JdbcTemplate jdbcTemplate = getJdbcTemplate(); javax.sql.DataSource ds = jdbcTemplate.getDataSource(); DataSourceTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate txTemplate = new TransactionTemplate(tm); ObjectNode result;/*from w w w . j a v a 2 s.c o m*/ result = txTemplate.execute(new TransactionCallback<ObjectNode>() { public ObjectNode doInTransaction(TransactionStatus status) { List<Map<String, Object>> rows = null; if (StringUtils.isBlank(source) || source.toLowerCase().equalsIgnoreCase("all")) { String query = SEARCH_DATASET_WITH_PAGINATION.replace("$keyword", keyword); rows = jdbcTemplate.queryForList(query, (page - 1) * size, size); } else { String query = SEARCH_DATASET_BY_SOURCE_WITH_PAGINATION.replace("$keyword", keyword); rows = jdbcTemplate.queryForList(query, source, (page - 1) * size, size); } for (Map row : rows) { Dataset ds = new Dataset(); ds.id = (Long) row.get(DatasetRowMapper.DATASET_ID_COLUMN); ds.name = (String) row.get(DatasetRowMapper.DATASET_NAME_COLUMN); ds.source = (String) row.get(DatasetRowMapper.DATASET_SOURCE_COLUMN); ds.urn = (String) row.get(DatasetRowMapper.DATASET_URN_COLUMN); ds.schema = (String) row.get(DatasetRowMapper.DATASET_SCHEMA_COLUMN); pagedDatasets.add(ds); } 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("source", source); resultNode.put("itemsPerPage", size); resultNode.put("totalPages", (int) Math.ceil(count / ((double) size))); resultNode.set("data", Json.toJson(pagedDatasets)); return resultNode; } }); return result; }
From source file:dao.SearchDAO.java
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;/*w ww . j a va 2 s . co m*/ 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; }
From source file:dao.SearchDAO.java
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;/* ww w . j ava 2 s . co m*/ 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; }