I'm going to build an app. Until now everything runs very well. Now I have a problem. The app gets its content from a mysql database.A column is called item.I have a ratingbar. The user can rate the item there.Every time the user evaluates an item the value is stored on the database in the respective item line.The values are then added. In other words, when a user evaluates 20 times with 5 stars, the value adds up to 100 and so on.
I want to limit this. I will that the user can evaluate each day only once an item. I will it without a registration mask for the user. How can I solve this problem?
I know that i can identifier the WIFI MAC Adreess and other Unique Identifiers, but how can i solve this with them?
I can not use sqlite database, because the items should update with the time from the mysql database.
A registration mask should not be excluded. If this process is quite possible with them, then I supplement it with it.
I am looking forward to every comment
every computer has a machine ID, you will hash that and encrypt that to use as your identifier..most telecomms do not like using MAc addresses as IDs
One option would be to create UUID during every installation and sending this UUID to your server along with every request. In server, you can control very well if user can provide feedback once a day or others based on your requirement. Pls refer this link on how to create UUID.
https://developer.android.com/reference/java/util/UUID.html
Related
I am designing a program in java and using mysql as DB. The program allows multiple users to connect to the DB.
An important part of the program is instantly updating the users that another one has made a change in a specific table that will have the user do an action and hence the changes will be show on his end.
I thought of listening on a socket but I couldn't resolve the concept of multiple users and how the sender will notify a specific user only not the entire group
this is similar to text message
So what I am trying to do is run a while loop that runs every 10 seconds to enhance the performance a little bit and will check the table against the username I am using to log in
this will get me what I wan but I know it is not efficient
Any Ideas ???
Use the "version control" pattern in the database table. Add a numeric column that is incremented each time the table is updated, such as:
alter table users add version_number bigint:
Then, each time the row is updated, you should increment this value as well:
update users
set my_value = ...,
version_number = version_number + 1 -- include this change
where id = 1234
This way, each client will remember the last version_number they saw. I they find a different version number, then a change has happened so an action should be taken.
I'm currently developing an application in Java that connects to a MySQL database using JDBC, and displays records in jTable. The application is going to be run by more than one user at a time and I'm trying to implement a way to see if the table has been modified. EG if user one modifies a column such as stock level, and then user two tries to access the same record tries to change it based on level before user one interacts.
At the moment I'm storing the checksum of the table that's being displayed as a variable and when a user tries to modify a record it will do a check whether the stored checksum is the same as the one generated before the edit.
As I'm new to this I'm not sure if this a correct way to do it or not; as I have no experience in this matter.
Calculating the checksum of an entire table seems like a very heavy-handed solution and definitely something that wouldn't scale in the long term. There are multiple ways of handling this but the core theme is to do as little work as possible to ensure that you can scale as the number of users increase. Imagine implementing the checksum based solution on table with million rows continuously updated by hundreds of users!
One of the solutions (which requires minimal re-work) would be to "check" the stock name against which the value is updated. In the background, you'll fire across a query to the table to see if the data for "that particular stock" has been updated after the table was populated. If yes, you can warn the user or mark the updated cell as dirty to indicate that that value has changed. The problem here is that the query won't be fired off till the user tries to save the updated value. Or you could poll the database to avoid that but again hardly an efficient solution.
As a more robust solution, I would recommend using a database which implements native "push notifications" to all the connected clients. Redis is a NoSQL database which comes to mind for this.
Another tried and tested technique would be to forgo direct database connection and use a middleware layer like a messaging queue (e.g. RabbitMQ). Message queues enable design of systems which communicate using message. So for e.g. every update the stock value in the JTable would be sent across as a message to an "update database queue". Once the update is done, a message would be sent across to a "update notification queue" to which all clients would be connected. This will enable all of them to know that the value of a given stock has been updated and act accordingly. The advantage to this solution is that you get to keep your existing stack (Java, MySQL) and can implement notifications without polling the DB and killing it.
Checksum is a way to see if data has changed.
Anyway I would suggest you store a column "last_update_date", this column is supposed to be always updated at every update of the record.
So you juste have to store this date (precision date time) and do the check with that.
You can also add a column version number : a simple counter incremented by 1 at each update.
Note:
You can add a trigger on update for updating last_update_date, it should be 100% reliable, maybe you don't need a trigger if you control all updates.
When using in network communication:
A checksum is a count of the number of bits in a transmission unit
that is included with the unit so that the receiver can check to see
whether the same number of bits arrived. If the counts match, it's
assumed that the complete transmission was received.
So it can be translated to check 2 objects are different, your approach is correct.
I am planning on creating a small website with JavaEE where a user can vote but only every 5 minutes. There are two buttons. One to vote yes and the other to vote no. I want the buttons to only be clickable every 5 minutes. Whats the best way to do this?
I thought of getting the users IP and entering it into my DB along with the timestamp. Everytime a user would vote I would get their IP from the DB and check if 5 mins have passed since their last vote. What do you think of this solution? Is this best practise?
I am trying to avoid a login or any other sort of authentication.
I plan on using JSF, Java, mySQL and AJAX.
One possible solution could be a cookie containing the last date of vote in client side plus saving the user IP and date of vote in a datatabse in server side.
If there is no cookie in client side and if there is zero entry in your database containing the user's IP address, or if the date stored in this enty is inferior to your vote recover time, then the user can vote.
Keep in mind that the more people will click your buttons, the more request your server will have to handle.
There is no risk zero, but you can get close to it.
i'm trying to do mail program. i've done this using jsonArray, Http protocals and some other functions. But, now i want to implement the program likely unread mails and starred mails. If i'm pressing anyof new mail it'll assign likely 1 to database. Otherwise, keep it 0. And, also if i want to set any mails in important (starred) this will keep 1 to database. Otherwise, keep 0. Now, i want to create a database related to these concepts? Anyone know about this concept Please help me to do this? Thanks in advance.
Use SQLite,
Below tutorial will help you to get started,
http://developer.android.com/guide/topics/data/data-storage.html#db
http://www.vogella.de/articles/AndroidSQLite/article.html#overview_sqlite
Good luck!
Edited :
Create a database with a table "Whatever name"
Than have content such as
|SeqNo|MailFrom|MailTo|Subject|Body|Starred|etc...|
Example
|1|blah#clah.com|blahblah#blah.com|Hi|Hello|0|etc...|
|2|bla1#clah.com|blahbfgv#blah.com|Hi|Hello|1|etc...|
Hope you can match example with given table format, It's like a simple SQL database where you can query while loading inbox and check whether user has selected a mail and starred it! However you can create those star button which will change state of that table's column while being click.
I want to display a list of all the users in my site but I only want to display 10 people per age. I don't know how exactly to do this. I know how to do it by just displaying all the users in one page but that's not very good is it?
If I do it with the code I have now, it will only get the first ten users over and over again.
I want to be able to get all the users for a one time query, store it globally and then move through the list retrieving the next 10 and so on for display.
I am developing on appengine using Java and the Spring Framework some of the solutions I have been thinking about,
Store in the session and go through the list (very bad I guess)
hand it to the JSP, specifically to one of the scopes, page, request etc. But I think request will not work.
Look for a Spring controller that can handle this.
Generally speaking, you would use a form variable on your page (via GET or POST) called 'page', which would be a number. When you receive that in the servlet you would calculate a range based on the page number and configured rows per page.
Take a look at Paging through large datasets (yes it's Python but the same principles apply) and Queries and Indexes from the Google App Engine documentation.
Take a look at http://valuelist.sourceforge.net/
If you keep page size at 10 then you can retrieve your 10 users per age group for each page based on page number:
SELECT TOP 10 users FROM myusers
WHERE AGE = function(page_number)
ORDER BY some_ordering
I hope that JPA + appengine support such type of query.
Some database engines provide handy extensions to SQL for just this purpose. Like, in MySQL you can say something like "select ... whatever ... limit 50,10", where "50" is the row to start with and 10 is the number of rows to retrieve. Then on your display page you simply put next and previous buttons that pass the appropriate starting row number back to the server for the next run at the query.
If the SQL engine you're using has no such handy function, then you have to build an query-specific "where" clause based on the sort order.
To take a simple case, suppose in your example you are displaying the records in order by "user_name". You can use Statement.setMaxRows(10) to limit any queries to 10 rows. Then on your first call you execute, say, "select ... whatever ... from user order by user_name". Save the last user_name found. In your next button, you pass this user_name back to the server, and the query for the next call is "select ... whatever ... from user where user_name>'xxx' order by user_name", where 'xxx' is the last user_name from the previous call. Do the setMaxRows again so you are again limited to 10 rows of output. You can then let the user step through the entire output this way.
Letting the user go backwards is a bit of a pain. I've done it by keeping a table in a session variable with the starting key value for each page.