This repository has been archived by the owner on Mar 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1572fc9
commit 765a6b6
Showing
10 changed files
with
615 additions
and
555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
target/ | ||
bower_components/ | ||
node_modules/ | ||
dist/ | ||
.idea/ | ||
.tmp/ | ||
.project | ||
.classpath | ||
.settings | ||
.metadata/ | ||
*.iml | ||
*.log | ||
*.tmp | ||
*.zip | ||
*.bak | ||
*.versionsBackup | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...rk/src/main/java/com/networknt/saga/repository/AggregateInstanceSubscriptionsDAOImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.networknt.saga.repository; | ||
|
||
import com.networknt.saga.orchestration.EnlistedAggregate; | ||
import com.networknt.saga.orchestration.EventClassAndAggregateId; | ||
import com.networknt.saga.orchestration.SagaTypeAndId; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
public class AggregateInstanceSubscriptionsDAOImpl implements AggregateInstanceSubscriptionsDAO{ | ||
|
||
private Logger logger = LoggerFactory.getLogger(getClass()); | ||
private DataSource dataSource; | ||
|
||
|
||
public AggregateInstanceSubscriptionsDAOImpl(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
public void setDataSource(DataSource dataSource) {this.dataSource = dataSource;} | ||
|
||
@Override | ||
public void update(String sagaType, String sagaId, List<EventClassAndAggregateId> eventHandlers) { | ||
|
||
String psDelete = "DELETE FROM aggregate_instance_subscriptions WHERE saga_type = ? AND saga_id =?"; | ||
String psInsert = "INSERT INTO aggregate_instance_subscriptions(aggregate_id, event_type, saga_type, saga_id) values(?, ?, ?, ?)"; | ||
try (final Connection connection = dataSource.getConnection()) { | ||
connection.setAutoCommit(false); | ||
PreparedStatement stmt = connection.prepareStatement(psDelete); | ||
stmt.executeUpdate(); | ||
PreparedStatement ps = connection.prepareStatement(psInsert); | ||
for (EventClassAndAggregateId eventClassAndAggregateId : eventHandlers) { | ||
ps.setString(1, Long.toString(eventClassAndAggregateId.getAggregateId())); | ||
ps.setString(2, eventClassAndAggregateId.getEventClass().getName()); | ||
ps.setString(3, sagaType); | ||
ps.setString(4, sagaId); | ||
ps.addBatch(); | ||
} | ||
ps.executeBatch(); | ||
connection.commit(); | ||
} catch (SQLException e) { | ||
logger.error("SqlException:", e); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public List<SagaTypeAndId> findSagas(String aggregateType, String aggregateId, String eventType){ | ||
String psSelect = "Select saga_type, saga_id from aggregate_instance_subscriptions where aggregate_id = ? and event_type = ?"; | ||
|
||
List<SagaTypeAndId> sagas = new ArrayList<>(); | ||
try (final Connection connection = dataSource.getConnection()) { | ||
|
||
PreparedStatement ps = connection.prepareStatement(psSelect); | ||
ps.setString(1, aggregateId); | ||
ps.setString(2, eventType); | ||
|
||
ResultSet rs = ps.executeQuery(); | ||
while (rs.next()) { | ||
sagas.add(new SagaTypeAndId(rs.getString("saga_type"), rs.getString("saga_id") )); | ||
} | ||
} catch (SQLException e) { | ||
logger.error("SqlException:", e); | ||
} | ||
return sagas; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
saga-framework/src/main/java/com/networknt/saga/repository/EnlistedAggregatesDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.networknt.saga.repository; | ||
|
||
|
||
|
||
import com.networknt.saga.orchestration.EnlistedAggregate; | ||
|
||
|
||
import java.util.Set; | ||
|
||
public interface EnlistedAggregatesDao { | ||
|
||
|
||
void save(String sagaId, Set<EnlistedAggregate> enlistedAggregates) ; | ||
|
||
|
||
Set<EnlistedAggregate> findEnlistedAggregates(String sagaId); | ||
|
||
Set<String> findSagas(Class aggregateType, String aggregateId); | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
saga-framework/src/main/java/com/networknt/saga/repository/EnlistedAggregatesDaoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.networknt.saga.repository; | ||
|
||
|
||
import com.networknt.saga.orchestration.EnlistedAggregate; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class EnlistedAggregatesDaoImpl implements EnlistedAggregatesDao{ | ||
|
||
private Logger logger = LoggerFactory.getLogger(getClass()); | ||
private DataSource dataSource; | ||
|
||
|
||
public EnlistedAggregatesDaoImpl(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
public void setDataSource(DataSource dataSource) {this.dataSource = dataSource;} | ||
|
||
|
||
@Override | ||
public void save(String sagaId, Set<EnlistedAggregate> enlistedAggregates) { | ||
|
||
String psInsert = "INSERT INTO saga_enlisted_aggregates(saga_id, aggregate_type, aggregate_id) values(?,?,?)"; | ||
|
||
for (EnlistedAggregate ela : enlistedAggregates) { | ||
|
||
try (final Connection connection = dataSource.getConnection()) { | ||
|
||
PreparedStatement stmt = connection.prepareStatement(psInsert); | ||
stmt.setString(1, sagaId); | ||
stmt.setString(2, ela.getAggregateClass().getName()); | ||
stmt.setString(3, ela.getAggregateId().toString()); | ||
stmt.executeUpdate(); | ||
} catch (SQLException e) { | ||
logger.error("SqlException:", e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Set<EnlistedAggregate> findEnlistedAggregates(String sagaId) { | ||
return null; | ||
/* return new HashSet<>(jdbcTemplate.query("Select aggregate_type, aggregate_id from saga_enlisted_aggregates where saga_id = ?", | ||
(rs, rowNum) -> { | ||
try { | ||
return new EnlistedAggregate((Class) ClassUtils.forName(rs.getString("aggregate_type"), getClass().getClassLoader()), rs.getString("aggregate_id")); | ||
} catch (ClassNotFoundException e) { | ||
throw new RuntimeException(); | ||
} | ||
}, | ||
sagaId));*/ | ||
} | ||
|
||
@Override | ||
public Set<String> findSagas(Class aggregateType, String aggregateId) { | ||
|
||
String psSelect = "Select saga_id from saga_enlisted_aggregates where aggregate_type = ? AND aggregate_id = ?"; | ||
|
||
Set<String> sagas = new HashSet<>(); | ||
try (final Connection connection = dataSource.getConnection()) { | ||
|
||
PreparedStatement ps = connection.prepareStatement(psSelect); | ||
ps.setString(1, aggregateType.getName()); | ||
ps.setString(1, aggregateId); | ||
|
||
ResultSet rs = ps.executeQuery(); | ||
while (rs.next()) { | ||
sagas.add(rs.getString("saga_id")); | ||
} | ||
} catch (SQLException e) { | ||
logger.error("SqlException:", e); | ||
} | ||
return sagas; | ||
|
||
/* | ||
return new HashSet<>(jdbcTemplate.query("Select saga_id from saga_enlisted_aggregates where aggregate_type = ? AND aggregate_id = ?", | ||
(rs, rowNum) -> { | ||
return rs.getString("aggregate_type"); | ||
}, | ||
aggregateType, aggregateId));*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters