Project

General

Profile

« Previous | Next » 

Revision 29933

Added node to launch generic sql commands
Use of alternative methods for sql queries

View differences:

modules/dnet-msro-service/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/db/ExecuteSqlJobNode.java
1
package eu.dnetlib.msro.workflows.nodes.db;
2

  
3
import java.io.IOException;
4

  
5
import org.apache.commons.io.IOUtils;
6
import org.springframework.beans.factory.annotation.Required;
7

  
8
import com.googlecode.sarasvati.Arc;
9
import com.googlecode.sarasvati.NodeToken;
10

  
11
import eu.dnetlib.enabling.database.rmi.DatabaseService;
12
import eu.dnetlib.enabling.tools.ServiceLocator;
13
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode;
14

  
15
public class ExecuteSqlJobNode extends AsyncJobNode {
16
	private String db;
17
	private String dbParam;
18
	private String dbProperty;
19

  
20
	private String sql;
21
	
22
	private ServiceLocator<DatabaseService> dbServiceLocator;
23
	
24
	@Override
25
	protected String execute(NodeToken token) throws Exception {
26
		dbServiceLocator.getService().updateSQL(findDb(token), fetchSqlAsText(sql));
27
		
28
		return Arc.DEFAULT_ARC;
29
	}
30
	
31
	private String fetchSqlAsText(final String path) throws IOException {
32
		return IOUtils.toString(getClass().getResourceAsStream(path));
33
	}
34
	
35
	private String findDb(final NodeToken token) {
36
		if (dbParam != null && !dbParam.isEmpty()) {
37
			return token.getEnv().getAttribute(dbParam);
38
		} else if (dbProperty != null && !dbProperty.isEmpty()) {
39
			return getPropertyFetcher().getProperty(dbProperty);
40
		} else {
41
			return db;
42
		}
43
	}
44
	
45
	public String getDb() {
46
		return db;
47
	}
48

  
49
	public void setDb(String db) {
50
		this.db = db;
51
	}
52

  
53
	public String getDbParam() {
54
		return dbParam;
55
	}
56

  
57
	public void setDbParam(String dbParam) {
58
		this.dbParam = dbParam;
59
	}
60

  
61
	public String getDbProperty() {
62
		return dbProperty;
63
	}
64

  
65
	public void setDbProperty(String dbProperty) {
66
		this.dbProperty = dbProperty;
67
	}
68

  
69
	public String getSql() {
70
		return sql;
71
	}
72

  
73
	public void setSql(String sql) {
74
		this.sql = sql;
75
	}
76

  
77
	public ServiceLocator<DatabaseService> getDbServiceLocator() {
78
		return dbServiceLocator;
79
	}
80

  
81
	@Required
82
	public void setDbServiceLocator(ServiceLocator<DatabaseService> dbServiceLocator) {
83
		this.dbServiceLocator = dbServiceLocator;
84
	}
85
	
86
}
modules/dnet-msro-service/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/db/QueryDbJobNode.java
1 1
package eu.dnetlib.msro.workflows.nodes.db;
2 2

  
3
import java.io.IOException;
4

  
3 5
import javax.xml.ws.wsaddressing.W3CEndpointReference;
4 6

  
5 7
import org.apache.commons.io.IOUtils;
8
import org.apache.commons.lang.StringUtils;
6 9
import org.springframework.beans.factory.annotation.Required;
7 10

  
8 11
import com.googlecode.sarasvati.Arc;
......
19 22
	private String dbProperty;
20 23

  
21 24
	private String sql;
25
	private String sqlForSize;
22 26
	private String xslt;
23 27
	private String outputEprParam;
24 28

  
......
26 30

  
27 31
	@Override
28 32
	protected String execute(final NodeToken token) throws Exception {
29
		final String sqlText = IOUtils.toString(getClass().getResourceAsStream(sql));
30

  
33
		final String sqlText = fetchSqlAsText(sql);
34
				
31 35
		W3CEndpointReference epr = null;
32 36

  
33
		if (xslt != null && !xslt.isEmpty()) {
37
		if (StringUtils.isNotBlank(xslt)) {
34 38
			final String xsltText = IOUtils.toString(getClass().getResourceAsStream(xslt));
35
			epr = dbServiceLocator.getService().xsltSearchSQL(findDb(token), sqlText, xsltText);
39
			
40
			if (StringUtils.isBlank(sqlForSize)) {
41
				epr = dbServiceLocator.getService().xsltSearchSQL(findDb(token), sqlText, xsltText);
42
			} else {
43
				epr = dbServiceLocator.getService().alternativeXsltSearchSQL(findDb(token), sqlText, fetchSqlAsText(sqlForSize),xsltText);
44
			}
36 45
		} else {
37
			epr = dbServiceLocator.getService().searchSQL(findDb(token), sqlText);
46
			if (StringUtils.isBlank(sqlForSize)) {
47
				epr = dbServiceLocator.getService().searchSQL(findDb(token), sqlText);
48
			} else {
49
				epr = dbServiceLocator.getService().alternativeSearchSQL(findDb(token), sqlText, fetchSqlAsText(sqlForSize));
50
			}
38 51
		}
39 52

  
40 53
		token.getEnv().setAttribute(outputEprParam, epr.toString());
......
42 55
		return Arc.DEFAULT_ARC;
43 56
	}
44 57

  
58
	
59
	private String fetchSqlAsText(final String path) throws IOException {
60
		return IOUtils.toString(getClass().getResourceAsStream(path));
61
	}
62
	
45 63
	private String findDb(final NodeToken token) {
46 64
		if (dbParam != null && !dbParam.isEmpty()) {
47 65
			return token.getEnv().getAttribute(dbParam);
......
109 127
		this.dbProperty = dbProperty;
110 128
	}
111 129

  
130
	public String getSqlForSize() {
131
		return sqlForSize;
132
	}
133

  
134
	public void setSqlForSize(String sqlForSize) {
135
		this.sqlForSize = sqlForSize;
136
	}
137

  
112 138
}
modules/dnet-msro-service/trunk/src/main/resources/eu/dnetlib/msro/service/applicationContext-msro-nodes.xml
136 136
	<bean id="wfNodeQueryDb" class="eu.dnetlib.msro.workflows.nodes.db.QueryDbJobNode"
137 137
		scope="prototype" p:dbServiceLocator-ref="msroDbServiceLocator" />
138 138

  
139
	<bean id="wfNodeExecuteSql" class="eu.dnetlib.msro.workflows.nodes.db.ExecuteSqlJobNode"
140
		scope="prototype" p:dbServiceLocator-ref="msroDbServiceLocator" />
141

  
139 142
	<!-- MDStore -->
140 143
	<bean id="wfNodeCreateMDStore"
141 144
		class="eu.dnetlib.msro.workflows.nodes.repohi.CreateMDStoreJobNode"

Also available in: Unified diff