diff --git a/java/AsyncOperations/client.ncconf b/java/AsyncOperations/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/AsyncOperations/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/BackingSource/client.ncconf b/java/BackingSource/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/BackingSource/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/BasicOperations/client.ncconf b/java/BasicOperations/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/BasicOperations/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/BasicOperationsWithJSON/client.ncconf b/java/BasicOperationsWithJSON/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/BasicOperationsWithJSON/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/BulkOperations/client.ncconf b/java/BulkOperations/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/BulkOperations/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/CacheItemVersioning/client.ncconf b/java/CacheItemVersioning/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/CacheItemVersioning/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/CacheLoader/client.ncconf b/java/CacheLoader/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/CacheLoader/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/CompactSerialization/client.ncconf b/java/CompactSerialization/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/CompactSerialization/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/ContinuousQuery/client.ncconf b/java/ContinuousQuery/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/ContinuousQuery/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/DataStructures/client.ncconf b/java/DataStructures/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/DataStructures/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/Dependency/client.ncconf b/java/Dependency/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/Dependency/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/DistributedPubSub/README.md b/java/DistributedPubSub/README.md deleted file mode 100644 index cfac1f2..0000000 --- a/java/DistributedPubSub/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# BASIC OPERATIONS - -### Table of contents - -* [Introduction](#introduction) -* [Prerequisites](#prerequisites) -* [Build and Run the sample](#build-and-run-the-sample) -* [Additional Resources](#additional-resources) -* [Technical Support](#technical-support) -* [Copyrights](#copyrights) - -### Introduction - -This sample program demonstrates how to use the NCache messaging API to publish or subscribe messages. It shows how to create, get or delete a message topic and publish or subscribe messages using it. - -This sample has 2 projects: - -1) Publisher: It will create a topic, publish some messages on it and then deletes it. -2) Subscriber: It will create or get a topic and then create subscription on it. - -### Prerequisites - -Before the sample application is executed make sure that: - -- config.properties have been changed according to the configurations. - - Change the cache name -- By default this sample uses 'demoCache', make sure that cache is running. -- This sample requires sample data project. Build SampleData project and install its mvn package using the following commands: - - Open command prompt. - - cd to the SampleData directory. - - run: - ``` mvn clean package ``` - -### Build and Run the Sample -- Run the following commands: - ``` mvn clean package ``` -- Open your project in your favourite compiler and run the sample application. -- OR cd to target and run this command: - - ``` cd target ``` - - ``` java -cp * com.alachisoft.ncache.samples.publisher.RunPublisher ``` - - ``` java -cp * com.alachisoft.ncache.samples.subscriber.RunSubscriber ``` - -### Additional Resources - -##### Documentation -The complete online documentation for NCache is available at: -http://www.alachisoft.com/resources/docs/#ncache - -##### Programmers' Guide -The complete programmers guide of NCache is available at: -http://www.alachisoft.com/resources/docs/ncache/prog-guide/ - -### Technical Support - -Alachisoft [C] provides various sources of technical support. - -- Please refer to http://www.alachisoft.com/support.html to select a support resource you find suitable for your issue. -- To request additional features in the future, or if you notice any discrepancy regarding this document, please drop an email to [support@alachisoft.com](mailto:support@alachisoft.com). - -### Copyrights - -[C] Copyright 2021 Alachisoft \ No newline at end of file diff --git a/java/DistributedPubSub/client.ncconf b/java/DistributedPubSub/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/DistributedPubSub/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/DistributedPubSub/pom.xml b/java/DistributedPubSub/pom.xml deleted file mode 100644 index a5b32ca..0000000 --- a/java/DistributedPubSub/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - ncache.samples - base - 5 - - 4.0.0 - - DistributedPubSub - ${revision} - jar - - - - ncache.samples - sampledata - ${project.version} - system - ${basedir}/../SampleData/target/sampledata-5.2.0.jar - - - com.alachisoft.ncache - ncache-client - ${project.version} - - - - \ No newline at end of file diff --git a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/MessageFailedListeners.java b/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/MessageFailedListeners.java deleted file mode 100644 index 57afed8..0000000 --- a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/MessageFailedListeners.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.alachisoft.ncache.samples.callbacks; - -import com.alachisoft.ncache.runtime.caching.MessageFailedEventArgs; -import com.alachisoft.ncache.runtime.caching.TopicDeleteEventArgs; -import com.alachisoft.ncache.runtime.caching.TopicListener; - -public class MessageFailedListeners implements TopicListener { - @Override - public void onTopicDeleted(Object o, TopicDeleteEventArgs topicDeleteEventArgs) { - - } - - @Override - public void onMessageDeliveryFailure(Object o, MessageFailedEventArgs args) { - System.out.println("Message not delivered. Reason: " + args.getMessgeFailureReason()); - } -} diff --git a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/MessageReceivedCallbacks.java b/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/MessageReceivedCallbacks.java deleted file mode 100644 index 0016260..0000000 --- a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/MessageReceivedCallbacks.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.alachisoft.ncache.samples.callbacks; - -import com.alachisoft.ncache.runtime.caching.MessageEventArgs; -import com.alachisoft.ncache.runtime.caching.messaging.MessageReceivedListener; - -public class MessageReceivedCallbacks implements MessageReceivedListener { - @Override - public void onMessageReceived(Object o, MessageEventArgs messageEventArgs) { - System.out.println("Message Recieved for: " + messageEventArgs.getTopicName()); - } -} diff --git a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/TopicDeletedCallback.java b/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/TopicDeletedCallback.java deleted file mode 100644 index e7421b4..0000000 --- a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/callbacks/TopicDeletedCallback.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.alachisoft.ncache.samples.callbacks; - -import com.alachisoft.ncache.runtime.caching.MessageFailedEventArgs; -import com.alachisoft.ncache.runtime.caching.TopicDeleteEventArgs; -import com.alachisoft.ncache.runtime.caching.TopicListener; - -public class TopicDeletedCallback implements TopicListener { - @Override - public void onTopicDeleted(Object o, TopicDeleteEventArgs topicDeleteEventArgs) { - System.out.println("Topic " + topicDeleteEventArgs.getTopicName() + " deleted."); - } - - @Override - public void onMessageDeliveryFailure(Object o, MessageFailedEventArgs messageFailedEventArgs) { - - } -} diff --git a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/publisher/Publisher.java b/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/publisher/Publisher.java deleted file mode 100644 index cb846b0..0000000 --- a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/publisher/Publisher.java +++ /dev/null @@ -1,133 +0,0 @@ -// =============================================================================== -// Alachisoft (R) NCache Sample Code. -// =============================================================================== -// Copyright © Alachisoft. All rights reserved. -// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT -// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE. -// =============================================================================== -package com.alachisoft.ncache.samples.publisher; - -import com.alachisoft.ncache.samples.callbacks.MessageFailedListeners; -import com.alachisoft.ncache.client.Cache; -import com.alachisoft.ncache.client.CacheManager; -import com.alachisoft.ncache.runtime.caching.DeliveryOption; -import com.alachisoft.ncache.runtime.caching.Message; -import com.alachisoft.ncache.runtime.caching.Topic; -import com.alachisoft.ncache.runtime.exceptions.CacheException; -import com.alachisoft.ncache.runtime.util.TimeSpan; - -import java.io.Closeable; - -/** - * Class that provides the functionality of the publisher - */ -public class Publisher implements Closeable { - - private Topic _topic; - private Cache _cache; - private boolean _isStarted; - - /** - * Event subscriber for the event of message delivery failure. - * @throws Exception - */ - public void subscribe() throws Exception { - if(!_isStarted) throw new Exception("Publisher is not started."); - MessageFailedListeners eventListeners = new MessageFailedListeners(); - _topic.addMessageDeliveryFailureListener(eventListeners); - } - - /** - * Event unsubscriber for the event of message delivery failure. - * @throws Exception - */ - public void unSubscribe() throws Exception { - if(!_isStarted) throw new Exception("Publisher is not started."); - _topic.removeMessageDeliveryFailureListener(); - } - - /** - * This methods starts the specified cache and creates the specified topic on it. - * @param cacheName The cache's name. - * @param topicName The topic's name. - * @throws Exception - */ - public void start(String cacheName, String topicName) throws Exception { - if(cacheName == null){ - throw new Exception("The CacheID cannot be null."); - } - - if(cacheName.isEmpty()){ - throw new Exception("The CacheID cannot be empty."); - } - - // Initialize an instance of the cache to begin performing operations: - _cache = CacheManager.getCache(cacheName); - - // Create messaging topic. - _topic = _cache.getMessagingService().createTopic(topicName); - - // Marking it as started. - _isStarted = true; - } - - /** - * This method publishes a message, which is created by the provided arguments. - * @param payLoad The payload for the message. - * @param timeSpan Optional and nullable message expiry time. - * @throws Exception - */ - public void publish(Object payLoad, TimeSpan timeSpan) throws Exception { - if(timeSpan == null) - timeSpan = new TimeSpan(); - - // Creating new message instance with the specified expiration TimeSpan. - Message message = new Message(payLoad, timeSpan); - - // Publishing the above created message. - _topic.publish(message, DeliveryOption.All, true); - } - - /** - * This method publishes a message, which is created by the provided arguments. - * @param payLoad The payload for the message. - * @throws Exception - */ - public void publish(Object payLoad) throws Exception { - - Message message = new Message(payLoad); - - _topic.publish(message, DeliveryOption.All, true); - } - - /** - * This method deletes the specified 'Topic' in the argumnet. - * @param topicName Name of the topic to be deleted. - * @throws CacheException - */ - public void deleteTopic(String topicName) throws CacheException { - if(topicName == null) throw new IllegalArgumentException(); - - // Deleting the topic. - _cache.getMessagingService().deleteTopic(topicName); - } - - /** - * This methods releases the resource by the instance. - */ - @Override - public void close() { - - _isStarted = false; - - //Disposing the acquired resources. - try { - if (_topic != null) _topic.close(); - if (_cache != null) _cache.close(); - }catch (Exception ex){ - ex.printStackTrace(); - } - } -} diff --git a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/publisher/RunPublisher.java b/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/publisher/RunPublisher.java deleted file mode 100644 index c860048..0000000 --- a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/publisher/RunPublisher.java +++ /dev/null @@ -1,91 +0,0 @@ -// =============================================================================== -// Alachisoft (R) NCache Sample Code. -// =============================================================================== -// Copyright © Alachisoft. All rights reserved. -// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT -// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE. -// =============================================================================== -package com.alachisoft.ncache.samples.publisher; -import com.alachisoft.ncache.runtime.util.TimeSpan; - -import java.io.*; -import java.util.Properties; -import java.util.Scanner; - -/** - * A sample program that demonstrates how to use the messaging api in NCache. - * @requirements - * 1. A running NCache cache - * 2. Connection attributes in app.config - */ -public class RunPublisher { - public static void main(String[] args) { - try{ - // Initialize connection - Properties _properties = getProperties(); - // Initialize cache - String cacheName= _properties.getProperty("CacheID"); - - String topicName = "myTopic"; - int messageCount = 100; - - // Creates a publisher's instance. - Publisher publisher = new Publisher(); - // Starts the publisher on the topic. - publisher.start(cacheName, topicName); - publisher.subscribe(); - - System.out.println("Publisher Started..."); - - for(int i=1; i<=messageCount; i++) - { - String payLoad = String.format("Message %s", i); - - if(i % 2 == 0) - { - // Publishes the message with expiry. - publisher.publish(payLoad, TimeSpan.FromMinutes(5)); - System.out.println("Message published with the expiry of 5 minutes."); - Thread.sleep(1000); - } - else - { - // Publishes the message. - publisher.publish(payLoad); - System.out.println("Message published without expiry."); - Thread.sleep(1000); - } - } - - System.out.println("Press enter to continue..."); - Scanner s = new Scanner(System.in); - String u = s.nextLine(); - - //Deletes the topic. - publisher.deleteTopic(topicName); - System.out.println("Topic Deleted."); - - publisher.unSubscribe(); - }catch (Exception ex){ - ex.printStackTrace(); - } - } - - /** - This method returns property file - */ - private static Properties getProperties() throws IOException - { - String path = "config.properties"; - InputStream inputStream = RunPublisher.class.getClassLoader().getResourceAsStream(path); - Properties properties=new Properties(); - if (inputStream != null) { - properties.load(inputStream); - } else { - throw new FileNotFoundException("property file '" + path + "' not found in the classpath"); - } - return properties; - } -} diff --git a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/subscriber/RunSubscriber.java b/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/subscriber/RunSubscriber.java deleted file mode 100644 index c29ecb7..0000000 --- a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/subscriber/RunSubscriber.java +++ /dev/null @@ -1,60 +0,0 @@ -// =============================================================================== -// Alachisoft (R) NCache Sample Code. -// =============================================================================== -// Copyright © Alachisoft. All rights reserved. -// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT -// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE. -// =============================================================================== -package com.alachisoft.ncache.samples.subscriber; - -import com.alachisoft.ncache.samples.callbacks.MessageReceivedCallbacks; -import java.io.*; -import java.util.Properties; - -/** - * A sample program that demonstrates how to use the messaging api in NCache. - */ -public class RunSubscriber { - public static void main(String[] args) { - try - { - // Initialize connection - Properties _properties = getProperties(); - // Initialize cache - String cacheName= _properties.getProperty("CacheID"); - - String topicName = "myTopic"; - // Creates a subscriber's instance. - TopicSubscriber subscriber = new TopicSubscriber(); - - // Subscribes on it, using the provided cache-Id and the topic-name. - MessageReceivedCallbacks messageReceivedCallbacks = new MessageReceivedCallbacks(); - subscriber.subscribe(cacheName, topicName, messageReceivedCallbacks); - - Thread.sleep(10000); - - - }catch (Exception e) - { - e.printStackTrace(); - } - } - - /** - This method returns property file - */ - private static Properties getProperties() throws IOException - { - String path = "config.properties"; - InputStream inputStream = RunSubscriber.class.getClassLoader().getResourceAsStream(path); - Properties properties=new Properties(); - if (inputStream != null) { - properties.load(inputStream); - } else { - throw new FileNotFoundException("property file '" + path + "' not found in the classpath"); - } - return properties; - } -} diff --git a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/subscriber/TopicSubscriber.java b/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/subscriber/TopicSubscriber.java deleted file mode 100644 index 8bd1343..0000000 --- a/java/DistributedPubSub/src/main/java/com/alachisoft/ncache/samples/subscriber/TopicSubscriber.java +++ /dev/null @@ -1,83 +0,0 @@ -// =============================================================================== -// Alachisoft (R) NCache Sample Code. -// =============================================================================== -// Copyright © Alachisoft. All rights reserved. -// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT -// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -// FITNESS FOR A PARTICULAR PURPOSE. -// =============================================================================== -package com.alachisoft.ncache.samples.subscriber; - -import com.alachisoft.ncache.samples.callbacks.MessageReceivedCallbacks; -import com.alachisoft.ncache.samples.callbacks.TopicDeletedCallback; -import com.alachisoft.ncache.client.Cache; -import com.alachisoft.ncache.client.CacheManager; -import com.alachisoft.ncache.runtime.caching.Topic; - -import java.io.Closeable; -import java.util.Scanner; - -/** - * Class that provides the functionality of the publisher - */ -public class TopicSubscriber implements Closeable { - - private Topic _topic; - private Cache _cache; - - /** - * This method initializes the specified cache and subscribes to the specified topic for the published messages on it. - * @param cacheName The name of the cache to initialize. - * @param topicName The name of the topic to subscribe to. - * @param messageReceivedCallbacks The callback which will be invoked when a message is published on the topic. - * @throws Exception - */ - public void subscribe(String cacheName, String topicName, MessageReceivedCallbacks messageReceivedCallbacks) throws Exception { - if(cacheName == null){ - throw new Exception("The CacheID cannot be null."); - } - - if(cacheName.isEmpty()){ - throw new Exception("The CacheID cannot be empty."); - } - - // Initialize an instance of the cache to begin performing operations: - _cache = CacheManager.getCache(cacheName); - - // Gets the topic. - _topic = _cache.getMessagingService().createTopic(cacheName); - - // Creates the topic if it doesn't exist. - if(_topic == null) - _topic = _cache.getMessagingService().createTopic(topicName); - - // Subscribes to the topic. - _topic.createSubscription(messageReceivedCallbacks); - Thread.sleep(10000); - } - - /** - * This property lets the user to subscribe for the topic's deletion event. - */ - public void deleteTopicCallback() - { - TopicDeletedCallback topicDeletedCallback = new TopicDeletedCallback(); - _topic.addTopicDeletedListener(topicDeletedCallback); - } - - /** - * This methods releases the resource by the instance. - */ - @Override - public void close() { - try - { - if (_topic != null) _topic.close(); - if (_cache != null) _cache.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/java/DistributedPubSub/src/main/resources/config.properties b/java/DistributedPubSub/src/main/resources/config.properties deleted file mode 100644 index 02ce463..0000000 --- a/java/DistributedPubSub/src/main/resources/config.properties +++ /dev/null @@ -1 +0,0 @@ -CacheID=demoCache \ No newline at end of file diff --git a/java/Events/client.ncconf b/java/Events/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/Events/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/ItemLocking/client.ncconf b/java/ItemLocking/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/ItemLocking/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/PubSub/client.ncconf b/java/PubSub/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/PubSub/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/PubSub/src/main/java/com/alachisoft/ncache/samples/DurableSubscriber/DurableSubscriber.java b/java/PubSub/src/main/java/com/alachisoft/ncache/samples/DurableSubscriber/DurableSubscriber.java index 5a89c09..9a0be18 100644 --- a/java/PubSub/src/main/java/com/alachisoft/ncache/samples/DurableSubscriber/DurableSubscriber.java +++ b/java/PubSub/src/main/java/com/alachisoft/ncache/samples/DurableSubscriber/DurableSubscriber.java @@ -80,7 +80,7 @@ private static DurableTopicSubscription runSubscriber(String topicName, String s //Creates durable subscription //subscriptionName: User defined name for subscription //Subscription Policy: If subscription policy is shared , it means subscription can hold multiple active subscribers - //If subscription policy is exclusive , it means subscription can hold one active client only. + // If subscription policy is exclusive , it means subscription can hold one active client only. return topic.createDurableSubscription(subscriptionName, policy, messageReceivedListener, new TimeSpan(1, 0, 0)); diff --git a/java/PubSub/src/main/java/com/alachisoft/ncache/samples/NonDurableSubscriber/NonDurableSubscriber.java b/java/PubSub/src/main/java/com/alachisoft/ncache/samples/NonDurableSubscriber/NonDurableSubscriber.java index afad315..1c15f65 100644 --- a/java/PubSub/src/main/java/com/alachisoft/ncache/samples/NonDurableSubscriber/NonDurableSubscriber.java +++ b/java/PubSub/src/main/java/com/alachisoft/ncache/samples/NonDurableSubscriber/NonDurableSubscriber.java @@ -108,7 +108,7 @@ private static void initializeCache(String cacheName) throws Exception { // Print output on console System.out.println(); - System.out.println("Cache initialized succesfully."); + System.out.println("Cache " + cacheName + " initialized succesfully."); } /** diff --git a/java/PubSub/src/main/java/com/alachisoft/ncache/samples/Publisher/Orders.java b/java/PubSub/src/main/java/com/alachisoft/ncache/samples/Publisher/Orders.java index 1e5a638..d036624 100644 --- a/java/PubSub/src/main/java/com/alachisoft/ncache/samples/Publisher/Orders.java +++ b/java/PubSub/src/main/java/com/alachisoft/ncache/samples/Publisher/Orders.java @@ -10,7 +10,7 @@ public class Orders implements Serializable { private LocalDate orderDate; private LocalDate shippedDate; - public void setOrderDate(LocalDate orderDate) { + protected void setOrderDate(LocalDate orderDate) { this.orderDate = orderDate; } @@ -50,8 +50,8 @@ public ElectronicOrder() } } -class GarmentsOrders extends Orders implements Serializable { - public GarmentsOrders() +class GarmentsOrder extends Orders implements Serializable { + public GarmentsOrder() { UUID uuid = UUID.randomUUID(); setOrderId("GarmentsOrder"+ uuid.toString()); diff --git a/java/PubSub/src/main/java/com/alachisoft/ncache/samples/Publisher/Publisher.java b/java/PubSub/src/main/java/com/alachisoft/ncache/samples/Publisher/Publisher.java index c027961..be7ede1 100644 --- a/java/PubSub/src/main/java/com/alachisoft/ncache/samples/Publisher/Publisher.java +++ b/java/PubSub/src/main/java/com/alachisoft/ncache/samples/Publisher/Publisher.java @@ -37,14 +37,14 @@ public static void run() }).start(); new Thread(() -> { try { - runBulkPublisher("GarmentsOrders", GarmentsOrders.class); + runBulkPublisher("GarmentsOrders", GarmentsOrder.class); } catch (Exception e) { e.printStackTrace(); } }).start(); new Thread(() -> { try { - runAsyncPublisher("GarmentsOrders", GarmentsOrders.class); + runAsyncPublisher("GarmentsOrders", GarmentsOrder.class); } catch (Exception e) { e.printStackTrace(); } @@ -92,10 +92,11 @@ private void publishAsyncMessages(String topicName, Class // Publishes the message with expiry. Message message = new Message(order, new TimeSpan(0, 0, 15)); _topic.publishAsync(message, DeliveryOption.All, true); + System.out.println("Messages for " + t.getName() + " OrderId: " + order.getOrderId() + " generated"); - } - Thread.sleep(5 * 1000);//Sleep for 5 seconds. + Thread.sleep(5 * 1000);//Sleep for 5 seconds. + } } private static void runBulkPublisher(String topicName, Class t) throws Exception { @@ -129,7 +130,7 @@ private void publishBulkMesages(String topicName, Class t) // if any exceptions are encountered, throw to client if(messageExceptionMap.size() > 0) - throw new Exception("Publist Bulk topics has encountered " + messageExceptionMap.size() + " exeptions"); + throw new Exception("Publish Bulk topics has encountered " + messageExceptionMap.size() + " exeptions"); System.out.println(messageList.size() + " Messages for " + t.getName() + " generated"); @@ -146,7 +147,7 @@ private Map generateMessages(T order { // Adds the message with expiry to bulk Message message = new Message(order, new TimeSpan(0, 0, 15)); - messageList.put(message, DeliveryOption.All); + messageList.put(message, DeliveryOption.Any); } return messageList; } @@ -157,7 +158,7 @@ private Map generateMessages(T order * @throws CacheException */ private static void deleteTopics(String topicName) throws CacheException { - if(topicName == null) throw new IllegalArgumentException(); + if(topicName == null) throw new IllegalArgumentException("topicName"); // Deleting the topic. _cache.getMessagingService().deleteTopic(topicName); @@ -189,10 +190,11 @@ private void PublishMessages(String topicName, Class t) th // Publishes the message with expiry. Message message = new Message(order, new TimeSpan(0, 0, 15)); _topic.publish(message, DeliveryOption.All, true); + System.out.println("Messages for " + t.getName() + " OrderId: " + order.getOrderId() + " generated"); - } - Thread.sleep(5 * 1000);//Sleep for 5 seconds. + Thread.sleep(5 * 1000);//Sleep for 5 seconds. + } } @@ -224,7 +226,7 @@ private static void initializeCache(String cacheName) throws Exception { // Print output on console System.out.println(); - System.out.println("Cache initialized succesfully."); + System.out.println("Cache " + cacheName + " initialized successfully."); } /** diff --git a/java/SampleData/target/sampledata-5.2.0.jar b/java/SampleData/target/sampledata-5.2.0.jar deleted file mode 100644 index 5479f42..0000000 Binary files a/java/SampleData/target/sampledata-5.2.0.jar and /dev/null differ diff --git a/java/SearchUsingSQL/client.ncconf b/java/SearchUsingSQL/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/SearchUsingSQL/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/Book.java b/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/Book.java index 7636c25..c648cb9 100644 --- a/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/Book.java +++ b/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/Book.java @@ -5,40 +5,28 @@ import java.util.Date; @Entity -@org.hibernate.annotations.NamedQuery(name = "Book.findBookByIsbn", -query = "select b from Book b where b.isbn = ?1") public class Book implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Integer id; - - private long isbn; + private long id; private String title; public Book(){} - public long getIsbn() { - return isbn; + public long getId() { + return id; } - public void setId(Integer id) { + public void setId(long id) { this.id = id; } - public void setIsbn(long isbn) { - this.isbn = isbn; - } - - public Integer getId() { - return id; - } - - public Book(long isbn, String title, String subTitle, + public Book(long id, String title, String subTitle, String author, Date publishedDate, String publisher, long pages, String description, String webURL) { - this.isbn = isbn; + this.id = id; this.title = title; this.subTitle = subTitle; this.author = author; @@ -64,14 +52,6 @@ public Book(long isbn, String title, String subTitle, private String webURL; - public long getISBN() { - return isbn; - } - - public void setISBN(long isbn) { - this.isbn = isbn; - } - public String getTitle() { return title; } diff --git a/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/controller/BookController.java b/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/controller/BookController.java index 77fae14..06cf5e7 100644 --- a/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/controller/BookController.java +++ b/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/controller/BookController.java @@ -51,9 +51,9 @@ public String saveBook(@ModelAttribute("book") Book book, BindingResult result) } @RequestMapping(value = "/bookstore/edit", method = RequestMethod.GET) - public String showEditBookPage(@RequestParam int id, ModelMap model) { + public String showEditBookPage(@RequestParam long id, ModelMap model) { Book book = booksService.get(id); - model.put("book", book); + model.addAttribute("book", book == null ? new Book() : book); return "newBook"; } @@ -75,7 +75,7 @@ public String deleteBook(@RequestParam int id) { @RequestMapping(value="/bookstore", method = RequestMethod.POST) public ModelAndView findBook(ModelMap model, @RequestParam long isbn){ - Book book = booksService.findBookByIsbn(isbn); + Book book = booksService.get(isbn); if (book == null) { return returnError(model, isbn); diff --git a/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/repository/BookRepository.java b/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/repository/BookRepository.java index 3726cdb..f4d8957 100644 --- a/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/repository/BookRepository.java +++ b/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/repository/BookRepository.java @@ -8,10 +8,9 @@ import java.util.List; @Repository -public interface BookRepository extends CrudRepository { - Book findById(int id); +public interface BookRepository extends CrudRepository { + Book findById(long id); @NonNull List findAll(); - void deleteById(int id); - Book findBookByIsbn(long isbn); + void deleteById(long id); } \ No newline at end of file diff --git a/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/service/BookService.java b/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/service/BookService.java index 8015a48..34e8000 100644 --- a/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/service/BookService.java +++ b/java/Spring-JCache/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/service/BookService.java @@ -22,24 +22,19 @@ public List listAll() { return repo.findAll(); } - @CachePut(value = cacheName, key = "#book.getISBN()") - public void save(Book book) { - repo.save(book); + @CachePut(value = cacheName, key = "#book.id") + public Book save(Book book) { + return repo.save(book); } - @CachePut(value = cacheName, key = "#book.getISBN()") - public void update(Book book) { repo.save(book); } + @CachePut(value = cacheName, key = "#book.id") + public Book update(Book book) { return repo.save(book); } @Cacheable(value = cacheName, key = "#id") - public Book get(int id) { + public Book get(long id) { return repo.findById(id); } - @Cacheable(value = cacheName, key = "#isbn") - public Book findBookByIsbn(long isbn) { - return repo.findBookByIsbn(isbn); - } - @CacheEvict(value = cacheName, allEntries = true) public void delete(int id) { repo.deleteById(id); diff --git a/java/Spring-JCache/src/main/resources/sqlDataScript.sql b/java/Spring-JCache/src/main/resources/sqlDataScript.sql index c422656..24b1f7a 100644 --- a/java/Spring-JCache/src/main/resources/sqlDataScript.sql +++ b/java/Spring-JCache/src/main/resources/sqlDataScript.sql @@ -1,22 +1,43 @@ -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (1, 'Marijn Haverbeke', 'JavaScript lies at the heart of almost every modern web application, from social apps to the newest browser-based games. Though simple for beginners to pick up and play with, JavaScript is a flexible, complex language that you can use to build full-scale applications.', - 9781593275846, 472, '2014-12-14', 'No Starch Press', 'A Modern Introduction to Programming', 'Eloquent JavaScript, Second Edition', 'http://eloquentjavascript.net/'); - -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (2, 'Addy Osmani', 'With Learning JavaScript Design Patterns, you\'ll learn how to write beautiful, structured, and maintainable JavaScript by applying classical and modern design patterns to the language. If you want to keep your code efficient, more manageable, and up-to-date with the latest best practices, this book is for you.', - 9781449331818, 254, '2012-07-01', 'O\'Reilly Media', 'A JavaScript and jQuery Developer\'s Guide', 'Learning JavaScript Design Patterns', 'http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/'); - -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (3, 'Axel Rauschmayer', 'Like it or not, JavaScript is everywhere these days-from browser to server to mobile-and now you, too, need to learn the language or dive deeper than you have. This concise book guides you into and through JavaScript, written by a veteran programmer who once found himself in the same position.', - 9781449365035, 460, '2014-02-01', 'O\'Reilly Media', 'An In-Depth Guide for Programmers', 'Speaking JavaScript', 'http://speakingjs.com/'); - -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (4, 'Eric Elliott', 'Take advantage of JavaScript\'s power to build robust web-scale or enterprise applications that are easy to extend and maintain. By applying the design patterns outlined in this practical book, experienced JavaScript developers will learn how to write flexible and resilient code that\'s easier-yes, easier-to work with as your code base grows.', - 9781491950296, 254, '2014-07-01', 'O\'Reilly Media', 'Robust Web Architecture with Node, HTML5, and Modern JS Libraries', 'Programming JavaScript Applications', 'http://chimera.labs.oreilly.com/books/1234000000262/index.html'); - -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (5, 'Nicholas C. Zakas', 'ECMAScript 6 represents the biggest update to the core of JavaScript in the history of the language. In Understanding ECMAScript 6, expert developer Nicholas C. Zakas provides a complete guide to the object types, syntax, and other exciting changes that ECMAScript 6 brings to JavaScript.', - 9781593277574, 352, '2016-09-03', 'No Starch Press', 'The Definitive Guide for JavaScript Developers', 'Understanding ECMAScript 6', 'https://leanpub.com/understandinges6/read'); +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Marijn Haverbeke'', ''JavaScript lies at the heart of almost every modern web application, from social apps to + the newest browser - based games.Though simple for beginners to pick up and play with, JavaScript is a flexible, + complex language that you can use to build full-scale applications.'', + 9781593275846, 472, ''2014-12-14'', ''No Starch Press'', ''A Modern Introduction to Programming'', + ''Eloquent JavaScript, Second Edition '', ''http://eloquentjavascript.net/''); + +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Addy Osmani'', ''With Learning JavaScript Design Patterns, you\''ll learn how to write beautiful, + structured, and maintainable JavaScript by applying classical and modern design patterns to the language.If you + want to keep your code efficient, more manageable, and up - to - date with the latest best practices, + this book is for you.'', + 9781449331818, 254, ''2012-07-01'', ''O\''Reilly Media'', ''A JavaScript and jQuery Developer\''s Guide'', + ''Learning JavaScript Design Patterns'', + ''http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/''); + +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Axel Rauschmayer'', '' Like it or not, + JavaScript is everywhere these days-from browser to server to mobile-and now you, too, + need to learn the language or dive deeper than you have. This concise book guides you into and through JavaScript, + written by a veteran programmer who once found himself in the same position.'', + 9781449365035, 460, ''2014-02-01'', ''O\''Reilly Media'', ''An In-Depth Guide for Programmers'', + ''Speaking JavaScript'', ''http://speakingjs.com/''); + +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Eric Elliott'', + ''Take advantage of JavaScript\''s power to build robust web-scale or enterprise applications that are easy to extend and maintain. By applying the design patterns outlined in this practical book, + experienced JavaScript developers will learn how to write flexible and resilient code that\''s easier-yes, + easier - to work with as your code base grows.'', + 9781491950296, 254, ''2014-07-01'', ''O\''Reilly Media'', ''Robust Web Architecture with Node, HTML5, and Modern + JS Libraries '', ''Programming JavaScript Applications'', + ''http://chimera.labs.oreilly.com/books/1234000000262/index.html''); + +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Nicholas C. Zakas'', + ''ECMAScript 6 represents the biggest update to the core of JavaScript in the history of the language. In Understanding ECMAScript 6, + expert developer Nicholas C. Zakas provides a complete guide to the object types, syntax, and other exciting + changes that ECMAScript 6 brings to JavaScript.'', + 9781593277574, 352, ''2016-09-03'', ''No Starch Press'', ''The Definitive Guide for JavaScript Developers'', + ''Understanding ECMAScript 6'', ''https://leanpub.com/understandinges6/read''); diff --git a/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/bookdetails.jsp b/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/bookdetails.jsp index 10bfb7e..c4162c2 100644 --- a/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/bookdetails.jsp +++ b/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/bookdetails.jsp @@ -1,4 +1,3 @@ -<%@ page import="java.util.Map" %> <%@ page import="com.alachisoft.ncache.springbootsample.bookstore.Book" %> <%@page contentType="text/html" pageEncoding="UTF-8" %> @@ -28,7 +27,7 @@ Book book = (Book) result; %> - <% out.println(book.getISBN()); %> + <% out.println(book.getId()); %> <% out.println(book.getTitle()); %> <% out.println(book.getSubTitle()); %> <% out.println(book.getPages()); %> diff --git a/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/bookstore.jsp b/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/bookstore.jsp index 86a9955..f682880 100644 --- a/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/bookstore.jsp +++ b/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/bookstore.jsp @@ -31,16 +31,16 @@ - ${book.isbn} + ${book.id} ${book.title} ${book.subTitle} ${book.pages} ${book.author} ${book.publisher} Update + href="${pageContext.request.contextPath}/bookstore/edit?id=${book.id}">Update Delete + href="${pageContext.request.contextPath}/bookstore/delete/?id=${book.id}">Delete diff --git a/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/newBook.jsp b/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/newBook.jsp index 5b871a7..b67372d 100644 --- a/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/newBook.jsp +++ b/java/Spring-JCache/src/main/webapp/WEB-INF/jsp/newBook.jsp @@ -22,12 +22,11 @@
Add Book
-
- ISBN - ISBN + - +
Title diff --git a/java/Streaming/client.ncconf b/java/Streaming/client.ncconf deleted file mode 100644 index 4fffe19..0000000 --- a/java/Streaming/client.ncconf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/java/GroupsAndTags/client.ncconf b/java/client.ncconf similarity index 56% rename from java/GroupsAndTags/client.ncconf rename to java/client.ncconf index 1ec9255..efb0db5 100644 --- a/java/GroupsAndTags/client.ncconf +++ b/java/client.ncconf @@ -1,12 +1,7 @@ - - + - + diff --git a/java/hibernate/client.ncconf b/java/hibernate/client.ncconf deleted file mode 100644 index 10e7b71..0000000 --- a/java/hibernate/client.ncconf +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/pom.xml b/java/pom.xml index 5e52163..65e6fe4 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -15,7 +15,6 @@ BasicOperations BackingSource BasicOperationsWithJSON - BulkCustomDependency BulkOperations CacheItemVersioning CacheLoader @@ -45,6 +44,51 @@ src/main/java + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + copy-resources-to-target + package + + copy-resources + + + ${basedir}/target + true + + + ${basedir}/../ + + client.ncconf + + + + + + + copy-resources-to-module + package + + copy-resources + + + ${basedir} + true + + + ${basedir}/../ + + client.ncconf + + + + + + + org.apache.maven.plugins maven-dependency-plugin @@ -75,10 +119,6 @@ com.alachisoft.ncache.samples.Main - - - - diff --git a/java/sessions/web/index.jsp b/java/sessions/web/index.jsp index a23cd55..240bb7d 100644 --- a/java/sessions/web/index.jsp +++ b/java/sessions/web/index.jsp @@ -33,7 +33,7 @@ } %> - +

Using NCache's Session Store Provider Implementation

Using NCache's Session Store Provider Implementation

diff --git a/java/spring/README.md b/java/spring/README.md index 91d2feb..8886b2c 100644 --- a/java/spring/README.md +++ b/java/spring/README.md @@ -39,7 +39,7 @@ Before running this sample make sure that: - ``` java -jar ncache-spring-0.0.1-SNAPSHOT.war ``` - After running this sample application for the first time a table with a name book will be created in a - database. Initially, the table will empty there won't be any data, so there are two ways to create a new book: + database. Using the web browser, visit http://localhost:8080/bookstore/. Initially, the table will empty there won't be any data, so there are two ways to create a new book: - either by creating a book one by one from the sample application by clicking on a Create new book button, from this you can also check each book you have created is also cached in NCache by checking the cache count. - A quick way to add books to the table is by running an SQL script(sqlDataScript.sql) shipped with the sample, diff --git a/java/spring/pom.xml b/java/spring/pom.xml index 90c191a..0e25a24 100644 --- a/java/spring/pom.xml +++ b/java/spring/pom.xml @@ -51,7 +51,7 @@ com.alachisoft.ncache ncache-spring - 5.2.0 + 5.2.1 @@ -90,10 +90,20 @@ org.springframework.boot spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + copy-dependencies + prepare-package + + copy-dependencies + - com.alachisoft.ncache.springbootsample.SpringBootSampleApplication + ${project.build.directory} diff --git a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/CachingConfiguration.java b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/CachingConfiguration.java index 2084aa4..1de26ed 100644 --- a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/CachingConfiguration.java +++ b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/CachingConfiguration.java @@ -15,8 +15,6 @@ public class CachingConfiguration public CacheManager cacheManager() { SpringConfigurationManager springConfigurationManager = new SpringConfigurationManager(); - URL resource = getClass().getClassLoader().getResource("ncache-spring.xml"); - springConfigurationManager.setConfigFile(resource.getPath()); NCacheCacheManager cacheManager = new NCacheCacheManager(); cacheManager.setSpringConfigurationManager(springConfigurationManager); return cacheManager; diff --git a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/Book.java b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/Book.java index 7636c25..f23860c 100644 --- a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/Book.java +++ b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/Book.java @@ -5,14 +5,10 @@ import java.util.Date; @Entity -@org.hibernate.annotations.NamedQuery(name = "Book.findBookByIsbn", -query = "select b from Book b where b.isbn = ?1") public class Book implements Serializable { + // @GeneratedValue(strategy = GenerationType.AUTO) @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Integer id; - private long isbn; private String title; @@ -23,18 +19,10 @@ public long getIsbn() { return isbn; } - public void setId(Integer id) { - this.id = id; - } - public void setIsbn(long isbn) { this.isbn = isbn; } - public Integer getId() { - return id; - } - public Book(long isbn, String title, String subTitle, String author, Date publishedDate, String publisher, long pages, String description, String webURL) { @@ -64,14 +52,6 @@ public Book(long isbn, String title, String subTitle, private String webURL; - public long getISBN() { - return isbn; - } - - public void setISBN(long isbn) { - this.isbn = isbn; - } - public String getTitle() { return title; } diff --git a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/controller/BookController.java b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/controller/BookController.java index 77fae14..a841d44 100644 --- a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/controller/BookController.java +++ b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/controller/BookController.java @@ -13,6 +13,7 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.view.RedirectView; +import javax.transaction.Transactional; import java.text.SimpleDateFormat; import java.util.Date; @@ -51,9 +52,9 @@ public String saveBook(@ModelAttribute("book") Book book, BindingResult result) } @RequestMapping(value = "/bookstore/edit", method = RequestMethod.GET) - public String showEditBookPage(@RequestParam int id, ModelMap model) { + public String showEditBookPage(@RequestParam long id, ModelMap model) { Book book = booksService.get(id); - model.put("book", book); + model.addAttribute("book", book == null ? new Book() : book); return "newBook"; } @@ -66,8 +67,9 @@ public String updateBook(@ModelAttribute("book") Book book, BindingResult result return "redirect:/bookstore"; } + @Transactional @RequestMapping(value = "/bookstore/delete") - public String deleteBook(@RequestParam int id) { + public String deleteBook(@RequestParam long id) { booksService.delete(id); return "redirect:/bookstore"; } @@ -75,7 +77,7 @@ public String deleteBook(@RequestParam int id) { @RequestMapping(value="/bookstore", method = RequestMethod.POST) public ModelAndView findBook(ModelMap model, @RequestParam long isbn){ - Book book = booksService.findBookByIsbn(isbn); + Book book = booksService.get(isbn); if (book == null) { return returnError(model, isbn); @@ -87,6 +89,7 @@ public ModelAndView findBook(ModelMap model, @RequestParam long isbn){ private ModelAndView returnError(ModelMap model, long isbn) { String errorMessage = "The book with ISBN: " + isbn + " is not available."; model.put("errorMessage", errorMessage); - return new ModelAndView(new RedirectView("bookstore")); + //return new ModelAndView(new RedirectView("bookstore", true)); + return homePage((Model) model); } } \ No newline at end of file diff --git a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/repository/BookRepository.java b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/repository/BookRepository.java index 3726cdb..a700fd4 100644 --- a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/repository/BookRepository.java +++ b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/repository/BookRepository.java @@ -5,13 +5,13 @@ import org.springframework.lang.NonNull; import org.springframework.stereotype.Repository; +import javax.transaction.Transactional; import java.util.List; @Repository -public interface BookRepository extends CrudRepository { - Book findById(int id); +public interface BookRepository extends CrudRepository { + Book findByIsbn(long isbn); @NonNull List findAll(); - void deleteById(int id); - Book findBookByIsbn(long isbn); + void deleteByIsbn(long isbn); } \ No newline at end of file diff --git a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/service/BookService.java b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/service/BookService.java index c520927..98ea24b 100644 --- a/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/service/BookService.java +++ b/java/spring/src/main/java/com/alachisoft/ncache/springbootsample/bookstore/service/BookService.java @@ -20,26 +20,21 @@ public List listAll() { return repo.findAll(); } - @CachePut(value = "books", key = "#book.getISBN()") - public void save(Book book) { - repo.save(book); + @CachePut(value = "books", key = "#book.isbn") + public Book save(Book book) { + return repo.save(book); } - @CachePut(value = "books", key = "#book.getISBN()") - public void update(Book book) { repo.save(book); } - - @Cacheable(value = "books", key = "#id") - public Book get(int id) { - return repo.findById(id); - } + @CachePut(value = "books", key = "#book.isbn") + public Book update(Book book) { return repo.save(book); } @Cacheable(value = "books", key = "#isbn") - public Book findBookByIsbn(long isbn) { - return repo.findBookByIsbn(isbn); + public Book get(long isbn) { + return repo.findByIsbn(isbn); } @CacheEvict(value = "books", allEntries = true) - public void delete(int id) { - repo.deleteById(id); + public void delete(long isbn) { + repo.deleteByIsbn(isbn); } } diff --git a/java/spring/src/main/resources/ncache-spring.xml b/java/spring/src/main/resources/ncache-spring.xml index d059f02..82fa7f9 100644 --- a/java/spring/src/main/resources/ncache-spring.xml +++ b/java/spring/src/main/resources/ncache-spring.xml @@ -1,5 +1,5 @@ - + diff --git a/java/spring/src/main/resources/sqlDataScript.sql b/java/spring/src/main/resources/sqlDataScript.sql index c422656..24b1f7a 100644 --- a/java/spring/src/main/resources/sqlDataScript.sql +++ b/java/spring/src/main/resources/sqlDataScript.sql @@ -1,22 +1,43 @@ -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (1, 'Marijn Haverbeke', 'JavaScript lies at the heart of almost every modern web application, from social apps to the newest browser-based games. Though simple for beginners to pick up and play with, JavaScript is a flexible, complex language that you can use to build full-scale applications.', - 9781593275846, 472, '2014-12-14', 'No Starch Press', 'A Modern Introduction to Programming', 'Eloquent JavaScript, Second Edition', 'http://eloquentjavascript.net/'); - -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (2, 'Addy Osmani', 'With Learning JavaScript Design Patterns, you\'ll learn how to write beautiful, structured, and maintainable JavaScript by applying classical and modern design patterns to the language. If you want to keep your code efficient, more manageable, and up-to-date with the latest best practices, this book is for you.', - 9781449331818, 254, '2012-07-01', 'O\'Reilly Media', 'A JavaScript and jQuery Developer\'s Guide', 'Learning JavaScript Design Patterns', 'http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/'); - -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (3, 'Axel Rauschmayer', 'Like it or not, JavaScript is everywhere these days-from browser to server to mobile-and now you, too, need to learn the language or dive deeper than you have. This concise book guides you into and through JavaScript, written by a veteran programmer who once found himself in the same position.', - 9781449365035, 460, '2014-02-01', 'O\'Reilly Media', 'An In-Depth Guide for Programmers', 'Speaking JavaScript', 'http://speakingjs.com/'); - -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (4, 'Eric Elliott', 'Take advantage of JavaScript\'s power to build robust web-scale or enterprise applications that are easy to extend and maintain. By applying the design patterns outlined in this practical book, experienced JavaScript developers will learn how to write flexible and resilient code that\'s easier-yes, easier-to work with as your code base grows.', - 9781491950296, 254, '2014-07-01', 'O\'Reilly Media', 'Robust Web Architecture with Node, HTML5, and Modern JS Libraries', 'Programming JavaScript Applications', 'http://chimera.labs.oreilly.com/books/1234000000262/index.html'); - -INSERT INTO sakila.book (id, author, description, isbn, pages, published_date, publisher, sub_title, title, weburl) -VALUES (5, 'Nicholas C. Zakas', 'ECMAScript 6 represents the biggest update to the core of JavaScript in the history of the language. In Understanding ECMAScript 6, expert developer Nicholas C. Zakas provides a complete guide to the object types, syntax, and other exciting changes that ECMAScript 6 brings to JavaScript.', - 9781593277574, 352, '2016-09-03', 'No Starch Press', 'The Definitive Guide for JavaScript Developers', 'Understanding ECMAScript 6', 'https://leanpub.com/understandinges6/read'); +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Marijn Haverbeke'', ''JavaScript lies at the heart of almost every modern web application, from social apps to + the newest browser - based games.Though simple for beginners to pick up and play with, JavaScript is a flexible, + complex language that you can use to build full-scale applications.'', + 9781593275846, 472, ''2014-12-14'', ''No Starch Press'', ''A Modern Introduction to Programming'', + ''Eloquent JavaScript, Second Edition '', ''http://eloquentjavascript.net/''); + +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Addy Osmani'', ''With Learning JavaScript Design Patterns, you\''ll learn how to write beautiful, + structured, and maintainable JavaScript by applying classical and modern design patterns to the language.If you + want to keep your code efficient, more manageable, and up - to - date with the latest best practices, + this book is for you.'', + 9781449331818, 254, ''2012-07-01'', ''O\''Reilly Media'', ''A JavaScript and jQuery Developer\''s Guide'', + ''Learning JavaScript Design Patterns'', + ''http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/''); + +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Axel Rauschmayer'', '' Like it or not, + JavaScript is everywhere these days-from browser to server to mobile-and now you, too, + need to learn the language or dive deeper than you have. This concise book guides you into and through JavaScript, + written by a veteran programmer who once found himself in the same position.'', + 9781449365035, 460, ''2014-02-01'', ''O\''Reilly Media'', ''An In-Depth Guide for Programmers'', + ''Speaking JavaScript'', ''http://speakingjs.com/''); + +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Eric Elliott'', + ''Take advantage of JavaScript\''s power to build robust web-scale or enterprise applications that are easy to extend and maintain. By applying the design patterns outlined in this practical book, + experienced JavaScript developers will learn how to write flexible and resilient code that\''s easier-yes, + easier - to work with as your code base grows.'', + 9781491950296, 254, ''2014-07-01'', ''O\''Reilly Media'', ''Robust Web Architecture with Node, HTML5, and Modern + JS Libraries '', ''Programming JavaScript Applications'', + ''http://chimera.labs.oreilly.com/books/1234000000262/index.html''); + +INSERT INTO sakila.book (author, description, id, pages, published_date, publisher, sub_title, title, weburl) +VALUES (''Nicholas C. Zakas'', + ''ECMAScript 6 represents the biggest update to the core of JavaScript in the history of the language. In Understanding ECMAScript 6, + expert developer Nicholas C. Zakas provides a complete guide to the object types, syntax, and other exciting + changes that ECMAScript 6 brings to JavaScript.'', + 9781593277574, 352, ''2016-09-03'', ''No Starch Press'', ''The Definitive Guide for JavaScript Developers'', + ''Understanding ECMAScript 6'', ''https://leanpub.com/understandinges6/read''); diff --git a/java/spring/src/main/webapp/WEB-INF/jsp/bookdetails.jsp b/java/spring/src/main/webapp/WEB-INF/jsp/bookdetails.jsp index 10bfb7e..3baf806 100644 --- a/java/spring/src/main/webapp/WEB-INF/jsp/bookdetails.jsp +++ b/java/spring/src/main/webapp/WEB-INF/jsp/bookdetails.jsp @@ -1,4 +1,5 @@ -<%@ page import="java.util.Map" %> +<%@ page import="com.alachisoft.ncache.springbootsample.bookstore.Book" %> +<%@ page import="com.alachisoft.ncache.springbootsample.bookstore.Book" %> <%@ page import="com.alachisoft.ncache.springbootsample.bookstore.Book" %> <%@page contentType="text/html" pageEncoding="UTF-8" %> @@ -28,7 +29,7 @@ Book book = (Book) result; %> - + diff --git a/java/spring/src/main/webapp/WEB-INF/jsp/bookstore.jsp b/java/spring/src/main/webapp/WEB-INF/jsp/bookstore.jsp index 97cff91..f27c1e8 100644 --- a/java/spring/src/main/webapp/WEB-INF/jsp/bookstore.jsp +++ b/java/spring/src/main/webapp/WEB-INF/jsp/bookstore.jsp @@ -38,21 +38,23 @@ + href="${pageContext.request.contextPath}/bookstore/delete/?id=${book.isbn}">Delete
<% out.println(book.getISBN()); %> <% out.println(book.getIsbn()); %> <% out.println(book.getTitle()); %> <% out.println(book.getSubTitle()); %> <% out.println(book.getPages()); %> ${book.author} ${book.publisher} Update + href="${pageContext.request.contextPath}/bookstore/edit?id=${book.isbn}">Update Delete

- <% - Object error = request.getAttribute("errorMessage"); - if(error != null){ - out.println(error); - } - %> + + <% + Object error = request.getAttribute("errorMessage"); + if(error != null){ + out.println((String) error); + } + %> +

@@ -62,7 +64,7 @@
- +
diff --git a/java/spring/src/main/webapp/WEB-INF/jsp/error.jsp b/java/spring/src/main/webapp/WEB-INF/jsp/error.jsp new file mode 100644 index 0000000..4750d5f --- /dev/null +++ b/java/spring/src/main/webapp/WEB-INF/jsp/error.jsp @@ -0,0 +1,43 @@ +<%-- + Created by IntelliJ IDEA. + User: saad_farooq + Date: 14/09/2021 + Time: 6:06 PM + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Error + + +
+
+ There was an error. + Go back to home page. +
+
+ + + + diff --git a/java/spring/src/main/webapp/WEB-INF/jsp/newBook.jsp b/java/spring/src/main/webapp/WEB-INF/jsp/newBook.jsp index 5b871a7..425d7e3 100644 --- a/java/spring/src/main/webapp/WEB-INF/jsp/newBook.jsp +++ b/java/spring/src/main/webapp/WEB-INF/jsp/newBook.jsp @@ -22,12 +22,11 @@
Add Book
-
- ISBN - ISBN + - +
Title