Skip to content

Commit

Permalink
Merge pull request #602 from UnifiedViews/mssql-partial-updates-broken
Browse files Browse the repository at this point in the history
Updates for using mssql server (not to be merged with fixing check of…
  • Loading branch information
tomas-knap authored Jan 5, 2017
2 parents f6752de + 8ee35c9 commit af69463
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 19 deletions.
6 changes: 6 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
<artifactId>jetty-server</artifactId>
<version>${jetty.server.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<type>jar</type>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cz.cuni.mff.xrg.odcs.commons.app.execution.server;

import java.util.List;

import cz.cuni.mff.xrg.odcs.commons.app.dao.db.DbAccess;

import java.util.List;

public interface DbExecutionServer extends DbAccess<ExecutionServer> {

/**
Expand Down Expand Up @@ -42,4 +42,16 @@ public interface DbExecutionServer extends DbAccess<ExecutionServer> {
*/
long getCountOfUnallocatedQueuedExecutionsWithIgnorePriority();

/**
* To set sql driver information (e.g., by Spring from config.properties)
* @param sqlDriverInfo
*/
public void setSqlDriverInfo(String sqlDriverInfo);

/**
* To get sql driver information
* @return
*/
public String getSqlDriverInfo();

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package cz.cuni.mff.xrg.odcs.commons.app.execution.server;

import java.util.List;

import javax.persistence.TypedQuery;

import org.springframework.transaction.annotation.Transactional;

import cz.cuni.mff.xrg.odcs.commons.app.ScheduledJobsPriority;
import cz.cuni.mff.xrg.odcs.commons.app.dao.db.DbAccessBase;
import cz.cuni.mff.xrg.odcs.commons.app.pipeline.PipelineExecutionStatus;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.TypedQuery;
import java.util.List;

public class DbExecutionServerImpl extends DbAccessBase<ExecutionServer> implements DbExecutionServer {

public DbExecutionServerImpl() {
super(ExecutionServer.class);
}

private String sqlDriverInfo;

@Override
public ExecutionServer getExecutionServer(String backendId) {
final String stringQuery = "SELECT e FROM ExecutionServer e WHERE e.backendId = :backendId";
Expand All @@ -33,14 +33,33 @@ public List<ExecutionServer> getAllExecutionServers() {
@Override
@Transactional
public int allocateQueuedExecutionsForBackendByPriority(String backendID, int limit) {
final String queryStr = "UPDATE exec_pipeline SET backend_id = '%s'"
String query = null;
if ( sqlDriverInfo != null && sqlDriverInfo.startsWith("com.microsoft.sqlserver.jdbc") ) {
// Version for Ms SQL Server (with TOP instead of LIMIT)
// sqlDriverInfo is taken from config.properties, see: commons-app-context.xml
final String queryStrMsSql = "UPDATE exec_pipeline SET backend_id = '%s'"
+ " WHERE id IN (SELECT id FROM"
+ " (SELECT e.id from exec_pipeline e WHERE e.backend_id IS NULL AND e.status = %d"
+ " ORDER BY e.order_number ASC, e.id ASC LIMIT %d FOR UPDATE) AS temp)";
String query = String.format(queryStr,
backendID,
0, // = QUEUED
limit);
+ " (SELECT TOP %d e.id from exec_pipeline e WHERE e.backend_id IS NULL AND e.status = %d"
+ " ORDER BY e.order_number ASC, e.id ASC) AS temp)";

query = String.format(queryStrMsSql,
backendID,
limit,
0 // = QUEUED
);
} else {
// Version for everything else (note limit/status params are inverse)
final String queryStrDefault = "UPDATE exec_pipeline SET backend_id = '%s'"
+ " WHERE id IN (SELECT id FROM"
+ " (SELECT e.id from exec_pipeline e WHERE e.backend_id IS NULL AND e.status = %d"
+ " ORDER BY e.order_number ASC, e.id ASC LIMIT %d) AS temp)";
query = String.format(queryStrDefault,
backendID,
0, // = QUEUED
limit
);
};

return this.em.createNativeQuery(query).executeUpdate();
}

Expand All @@ -58,4 +77,13 @@ public long getCountOfUnallocatedQueuedExecutionsWithIgnorePriority() {
return count;
}

@Override
public void setSqlDriverInfo(String sqlDriverInfo) {
this.sqlDriverInfo = sqlDriverInfo;
}

@Override
public String getSqlDriverInfo() {
return sqlDriverInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public class ExecutionServer implements Serializable, DataObject {
@Column(name = "id")
private Long id;

// TIMESTAMP won't work with MS SQL Server in this case, hence
// changed to DATETIME.
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_update", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
@Column(name = "last_update", nullable = false, columnDefinition = "DATETIME")
private Date lastUpdate;

@Column(name = "backend_id", unique = true, length = 128)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public List<Schedule> getAllTimeBasedNotQueuedRunningForCluster() {
+ " SELECT s1.id FROM exec_schedule s1"
+ " LEFT JOIN exec_pipeline e"
+ " ON e.id = s1.pipeline_id WHERE e.status IN (%d, %d))"
+ " ORDER BY s.id ASC"
+ " FOR UPDATE";
+ " ORDER BY s.id ASC" ;

String query = String.format(queryStr, 1, 0, 1);
return this.em.createNativeQuery(query, Schedule.class).getResultList();
Expand Down
4 changes: 3 additions & 1 deletion commons-app/src/main/resources/commons-app-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@
<bean id="dbUserActor" class="cz.cuni.mff.xrg.odcs.commons.app.user.DbUserActorImpl"/>
<bean id="dbNamespacePrefix" class="cz.cuni.mff.xrg.odcs.commons.app.rdf.namespace.DbNamespacePrefixImpl"/>
<bean id="dbRuntimeProperties" class="cz.cuni.mff.xrg.odcs.commons.app.properties.DbRuntimePropertiesImpl"/>
<bean id="dbExecutionServer" class="cz.cuni.mff.xrg.odcs.commons.app.execution.server.DbExecutionServerImpl"/>
<bean id="dbExecutionServer" class="cz.cuni.mff.xrg.odcs.commons.app.execution.server.DbExecutionServerImpl">
<property name="sqlDriverInfo" value="${database.sql.driver}"/>
</bean>

<!-- authorizator required by dao -->
<bean id="dbAuthorizator" class="cz.cuni.mff.xrg.odcs.commons.app.dao.db.DbAuthorizatorImpl"/>
Expand Down
7 changes: 7 additions & 0 deletions frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@
<version>${commons.validator.version}</version>
</dependency>

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<type>jar</type>
</dependency>

</dependencies>

<build>
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/main/webapp/WEB-INF/config.sample.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ database.sql.password = unifiedviews
# database.sql.password = unifiedviews
# }

# for mariadb {
#database.sql.driver = org.mariadb.jdbc.Driver
#database.sql.url = jdbc:mariadb://localhost:3306/unifiedviews?characterEncoding=utf8
#database.sql.user = unifiedviews
#database.sql.password = unifiedviews
# }

# for mssql
#database.sql.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
#database.sql.url = jdbc:sqlserver://localhost:1433;databaseName=unifiedviews
#database.sql.user = unifiedviews
#database.sql.password = unifiedviews


# Connection configuration setting for RDF database
# use local rdf platform {
Expand Down
6 changes: 6 additions & 0 deletions master/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<type>jar</type>
</dependency>
</dependencies>

<build>
Expand Down
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,26 @@
<noDeploy>true</noDeploy>
</configuration>
</plugin>
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<version>1.1.5</version>
<configuration>
<alwaysGenerate>true</alwaysGenerate>
<addResourcesDirToRebelXml>true</addResourcesDirToRebelXml>
<showGenerated>true</showGenerated>
</configuration>
<executions>
<execution>
<id>generate-rebel-xml</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down

0 comments on commit af69463

Please sign in to comment.