how can i make the updated database reaches all users? - java

I am developing a menu app for restaurant , I want the user to be able to add a new dish (new row in a table) and when the row is added to the database all other users (who have the app in their device)can see the new update.
I want to use SQLite. is that possible if yes, how?

For such kind of scenario, you need to store the new menu item from a user on backend database (a database which is hosted on an external server) of your application, and all the other users using the application will get that data by calling a web call to your backend.

Related

Java httpservlet and routing. How starting?

my boss asked me to develop an webservice that should work in this matter:
an external app contact my app and:
if the method used is GET and the url contacted is:
http://localhost:8080/webapp/webservice/?findall
will return all rows find in a table;
If the same external app contact my app in the same method but send a key and a value like:
http://localhost:8080/webapp/webservice/?field1=value1
my app will return a set of rows filtered by field/value.
And soon on with with any method sending request and with other fields.
I know how do the operations using JPA 2.1 but how mapping the actions?
Someone could help me to starting in the right direction with JDK1.8?

Best way to fetch dynamic data from server in android

I am new in android and developing an android application in which admin can insert data on server and users can load that data on their devices. I don't want to load data from server every time user land on that activity. I want to save fetched data at client side using greendao and load only the new one. And i think i have to hit the backend at least once. I am looking for a most convenient method to achieve this.
My preferred way would be to track the device on the server side:
for example create a table like cachedDevices(deviceId,dataId). then whenever you are requesting new data, your server could query your data against cachedDevices internally and only send new data...
you should also be aware of that each device should have unique Id...

how to operate an app running on two tablets from on tablet in android

I am working on app running on two tablets, which have two type of logins. Customer and Shopkeeper, it will run on two tabs at same time. I am getting tabs device id and saving it. because it can't be run on any other tablet without registered tablets.The issue is that after login when I go on main screen, when i enter number from any tablets, the next screen must be changed on both tablets. I am not getting the idea how to operate two tabs from any one of them.Can you help me to get this idea. any help will be appreciated.
I have 2 separate options here :
A. Use CouchDB.
Couch DB has this functionality to sync data between client and server.
Steps :
Tablet1 enter a value
Value saved in tablet1 CouchDB. (You can use something like couchbase-android)
Data synced from client COUCHDB to Server CouchDB ( you can use Cloudant here )
Data synced from Server CouchDB to client CouchDB in the Tablet1
Tablet2 use a listener to listen to record change in the database
Tablet2 change its state based on the record change.
B. Use Notification Server
Tablet1 enter a value
Tablet1 send message to Notification Server, indicating the changes
Notification Server send notification to Tablet2
Tablet2 use Notification Listener to listen to all notification
Tablet2 change it state based on data contained in the notification message.

Send RegistrationId To Backend

I am following the Client side GCM code on the Android dev site; I came across this:
private void sendRegistrationIdToBackend() {
// Your implementation here.
}
Now this questions is not WHAT to implement there, I know how to do httpost's and send param's to the server.
My questions is WHERE do I send this in my Database?
I am implementing GCM in an app that already has registered users, so I have a users MySQL table. Now here are my questions: From what I have read, do RegistrationId's have a unique relationship with a user? If so, can I just put the RegistrationId for the user into a new column in my users table? The only issue I see: What if the user uses the app on multiple devices. So that makes me think my logic is wrong. And if it is wrong...
..should I just do what I have seen in demos and put registration ID's in their own table -- and if so, should they be put there with the user Id in the same row so that a reg Id can be identified to a particular user (not just device)?
The relation between a user and a Registration ID is many-to-many :
As you realized, if a user has multiple devices, that user would be associated with multiple Registration IDs.
If on a single device one user logs out and another user logs in, both would be associated with the same Registration ID. In that case, however, you can cancel the association of the Registration ID to the old user before associating it with the new user. This would simplify the relation between a user and a Registration ID to one-to-many.
Given those two points, having a table that contains for each Registration ID a user ID would work. Just don't forget to remove entries from this table when users log out, since when a user logs out in a specific device, the Registration ID that what given to that instance of the app is no longer associated with that user.
It depends on what your app wants to do:
If the user will use only one device you can put it in the user table.
If the user can have many devices and the same notifications should be sent to all of them you can have a list of registration ids for each user (a one to many table).
If each device will have different notifications you should add a table for the devices, and add the registration id there.
You could also group the registration IDs related to a single user using the notification key.
http://developer.android.com/google/gcm/notifications.html
That way you have one entry per user and you only need to send one message per user, GCM takes care of the rest.

How to Logoff user when a user logsIn some where else

I am trying to implement the functionality with which , when a user is loggedIn at one place and when he try to login to some where else , He should automatically be LoggedOut from the previous place .
Like in GMAIL..
If some one can give me the concept , As i think I need to save the user LoggedIn Status in Db,As sessions doesnt looks to be heplful. But then I dont understand how we update user status in DB ,if there is no activity for lets say 5 minutes (how will i capture the inactivity and updating in db).
If some one can please guide, I am struggling on this for hours now .
Thanks
When user login add the user session with id to a hashmap. When the same user logins again check for entry in the HashMap and if available invalidate the session and create new session for the user.
If you are using Spring Security, it provides this functionality out of the box.
Otherwise:
Create a java.util.Map (A ConcurrentMap is prefered, so manipulating it concurrently won't corrupt it), and stores it in application scope (ServletContext).
Now, you shall store each user and a reference to its session upon login in the map, and if a user logins again, just fetch previous session object and invalidate it.
Now implement an instance of javax.servlet.http.HttpSessionListener, and in void sessionDestroyed(javax.servlet.http.HttpSessionEvent httpSessionEvent); method, remove the specified session from the Map. (This listener is invoked on session invalidation, whether it is done automatically by container or if you do it programmatically). just register this listener in web.xml and everything is done.
p.s. I know that it will be some-how harder, if you are deploying your application on a cluster of web-containers, but when you have just one server, that's ok.
p.s. I don't recommend storing session information in DB.

Categories

Resources