Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 4 files changed
  • 0 comments
  • 1 contributor
3  java/src/main/java/com/wineshop/services/VineyardRepository.java
@@ -2,12 +2,13 @@
2 2
3 3 import org.granite.messaging.service.annotations.RemoteDestination;
4 4 import org.granite.tide.data.DataEnabled;
  5 +import org.granite.tide.data.DataEnabled.PublishMode;
5 6 import org.granite.tide.spring.data.FilterableJpaRepository;
6 7
7 8 import com.wineshop.entities.Vineyard;
8 9
9 10 @RemoteDestination
10   -@DataEnabled
  11 +@DataEnabled(topic="wineshopTopic", publish=PublishMode.ON_SUCCESS)
11 12 public interface VineyardRepository
12 13 extends FilterableJpaRepository<Vineyard, Long> {
13 14 }
12 javafx/src/main/java/com/wineshop/client/Login.java
@@ -32,6 +32,7 @@
32 32
33 33 import javax.inject.Inject;
34 34
  35 +import org.granite.client.tide.data.DataObserver;
35 36 import org.granite.client.tide.events.TideEvent;
36 37 import org.granite.client.tide.events.TideEventObserver;
37 38 import org.granite.client.tide.javafx.spring.Identity;
@@ -60,6 +61,9 @@
60 61 @Inject
61 62 private Identity identity;
62 63
  64 + @Inject
  65 + private DataObserver wineshopTopic;
  66 +
63 67
64 68 @SuppressWarnings("unused")
65 69 @FXML
@@ -88,7 +92,13 @@ public void initialize(URL url, ResourceBundle rb) {
88 92
89 93 @Override
90 94 public void handleEvent(TideEvent event) {
91   - if (ServerSession.SESSION_EXPIRED.equals(event.getType())) {
  95 + if (ServerSession.LOGIN.equals(event.getType())) {
  96 + wineshopTopic.subscribe();
  97 + }
  98 + else if (ServerSession.LOGOUT.equals(event.getType())) {
  99 + wineshopTopic.unsubscribe();
  100 + }
  101 + else if (ServerSession.SESSION_EXPIRED.equals(event.getType())) {
92 102 labelMessage.setVisible(true);
93 103 labelMessage.setText("Session expired");
94 104 }
10 javafx/src/main/java/com/wineshop/client/Main.java
@@ -32,6 +32,7 @@
32 32
33 33 import org.granite.client.tide.ContextManager;
34 34 import org.granite.client.tide.collections.javafx.PagedQuery;
  35 +import org.granite.client.tide.data.DataObserver;
35 36 import org.granite.client.tide.data.EntityManager;
36 37 import org.granite.client.tide.javafx.JavaFXApplication;
37 38 import org.granite.client.tide.javafx.JavaFXServerSessionStatus;
@@ -154,6 +155,15 @@ public App init() {
154 155 public ManagedEntity<Vineyard> vineyard(EntityManager entityManager) {
155 156 return new ManagedEntity<Vineyard>(entityManager);
156 157 }
  158 +
  159 + /**
  160 + * Client declaration of the data publishing topic
  161 + */
  162 + @Bean
  163 + public DataObserver wineshopTopic(ServerSession serverSession,
  164 + EntityManager entityManager) {
  165 + return new DataObserver(serverSession, entityManager);
  166 + }
157 167 }
158 168
159 169 /**
3  webapp/src/main/webapp/WEB-INF/spring/app-config.xml
@@ -49,4 +49,7 @@
49 49 <!-- Publish JPA changes though AOP so even changes happening outside GraniteDS are dispatched -->
50 50 <graniteds:tide-data-publishing-advice mode="aspectj"/>
51 51
  52 + <!-- Topic destination for publishing data updates -->
  53 + <graniteds:messaging-destination id="wineshopTopic" no-local="true" session-selector="true"/>
  54 +
52 55 </beans>

No commit comments for this range

Something went wrong with that request. Please try again.