About SQLSpaces

SQLSpaces is an implementation of the TupleSpaces concept that features many new ideas while keeping the API clear and simple. It is based on top of a relational database, which gives the project its name: link.

How to use SQLSpaces module

Import SQLSpaces module into your project

Add the needed dependencies into your pom.xml

						
							org.ddbstoolkit.toolkit.modules.middleware.sqlspaces
							ddbstoolkit-sqlspaces
							1.0.0-beta2
							compile
						

Create your data model and your data module

You need to create your data model and instantiate your DistributableEntityManager of your needed module.

Start your SQLSpaces receiver interface

				DistributableReceiverInterface receiver = null;
				try {
					receiver = new SqlSpacesReceiver(manager, "defaultCluster", "receiver");
					receiver.start();
				} finally {
					if(receiver != null) {
						receiver.stop();
					}
				}

Your SQLSpaces program will now received data actions from the cluster "defaultCluster" and his peer name is "receiver".

Instantiate your SQLSpaces sender interface

				DistributableSenderInterface senderInterface = new SqlSpacesSender("defaultCluster", "sender");

The sender interface will send data command actions to receiver interfaces in the cluster "defaultCluster". In the cluster, the peer will be named "sender".

SQLSpaces module actions

Get list of receiver peers

				senderInterface.open();
		
				List peers = senderInterface.getListPeers();
				
				senderInterface.close();

Add an element

				senderInterface.open();
		
				Actor anActor = new Actor();
				anActor.setPeerUid("receiver");
				anActor.setActorName("Steven");
					
				senderInterface.add(anActor);
				
				senderInterface.close();

Update an element

				senderInterface.open();
		
				Actor anActor = new Actor();
				anActor.setPeerUid("receiver");
				anActor.setActorId(3);
				anActor.setActorName("Steven");
					
				senderInterface.update(anActor);
				
				senderInterface.close();

Delete an element

				senderInterface.open();
		
				Actor anActor = new Actor();
				anActor.setPeerUid("receiver");
				anActor.setActorId(3);
					
				senderInterface.delete(anActor);
				
				senderInterface.close();

Read an element

				senderInterface.open();
		
				Actor anActor = new Actor();
				anActor.setPeerUid("receiver");
				anActor.setActorId(3);
					
				anActor = senderInterface.read(anActor);
				
				senderInterface.close();

Read last added element

				senderInterface.open();
		
				Actor anActor = new Actor();
				anActor.setPeerUid("receiver");
		
				Actor anActor = senderInterface.readLastElement(anActor);
				
				senderInterface.close();

List elements

				senderInterface.open();
		
				//List all films
				List films = senderInterface.listAll(new Film(), null, null);
		
				//List all films ordered by film_ID
				films = senderInterface.listAll(new Film(), null, OrderBy.get("filmId", OrderByType.ASC));
				
				List conditions = new ArrayList<>();
        		conditions.add("film_name LIKE 'S%'");
				
				//List all films who starts with 'S'
				films = senderInterface.listAll(new Film(), conditions, null);
				
				//Same thing with Conditions
				Conditions conditionLike = Conditions.createConditions().add(
				Conditions.like("filmName", "S%"));
				List results = senderInterface.listAll(new Film(),conditionLike, null);
				
				senderInterface.close();

Load elements linked to an entity

				senderInterface.open();
 
				Film lastFilmAdded = senderInterface.readLastElement(new Actor());
				
				//List actors of a movie ordered by actor_id field
				lastFilmAdded = senderInterface.loadArray(lastFilmAdded, "actors", OrderBy.get("actorId", OrderByType.ASC));				
 
				senderInterface.close();

Execute transactions

				senderInterface.open();
				
				//Start a new transaction
				DDBSTransaction transactionAddCommit = new DDBSTransaction("myTransaction");
     
				Actor anActor = new Actor();
				anActor.setActorName("Steven");
				
				transactionAddCommit.add(filmToAdd);
		
				//Execute the transaction
				senderInterface.executeTransaction(transactionAddCommit);
				
				//Commit the transaction
				senderInterface.commit(transactionAddCommit);
				
				//Rollback the transaction
				senderInterface.rollback(transactionAddCommit);				
 
				senderInterface.close();