I recently made a change to one of my app engine models. I changed a Key field to a String. I forgot to remove all the old records. I have already added new records that have strings in the key fields. If I do a query for all the records I get an error, can not cast Key to String. If I try and change the class back to the old way I get can not cast String to Key. All this info is on the local file. How can I delete this data and start fresh?
When you say "local file" you mean in local development server? If yes,
then the local development GAE server also comes with a Admin console which you can use to view and edit the data store. Its located at http://localhost:8080/_ah/admin (check port number)
alternately you can restart your GAE and the local data would be wiped off
If no,
You have an admin console un app engine (view it in your app's dashboard). You can execute queries to modify data store from there
worst case, you can write a small servlet that will execute "delete" queries for the data that you dont want and execute that servlet
I'm assuming that your interest is NOT is supporting both the use cases - hence not thinking about that here.
Related
I am new to coding at this level, and was wondering how I would get a database that multiple users on different networks could edit.
I am trying to make an application where customers of a lawn service can download my "app" or code, insert their address, and update their work log. This information can then be retrieved by the boss on a different machine.
I have a java application that uses swing as the front end. It prompts the user to enter their address, asks them whether they would like to update/retrieve work log/access different dress.
First, I had this data serialized so it could be retrieved later, but this only functions on one machine.
Next, I connected it with MySQL via JDBC so it is stored in a simple table with address as the primary key and work log as the only other column.
At the very least, I would like to figure out how to make this program work so I could export it, send it to someone else, and they could update the same database as me.
I can work on more action listeners etc later, right now I cannot figure out how different machines on different networks can access the same database via an executable jar.
Thanks so much.
*When sending executable jar to another machine, it only has access to *information they enter.
*I want it to have access to previously entered information, as well as *information that may be or may have been entered on other machines.
Here is an approach that would work for you and allow you to use your swing app with the least amount of object mapping. I assume that’s your goal since you went down the serialization path. Try this:
1. Data in the database is properly normalized to third normal form.
2. The JDBC query executes a stored procedure to get your object data fully denormalized in consumable format.
3. The stored procedure uses SQL command For JSON.
4. Map the result set to your java object using GSON. GSON will automatically map json to your object.
5. Should the end user change an object, push it back to the database and read it again. Don’t just update it locally.
I store my objects in a hashmap with a unique identifier. That way when I read in an object because it has been updated, inserting into the hashmap with the same unique id with replace the old version with the new. Put a change listener on the hashmap so that you can update the ui when an update is read in from the database. Using javafx you could further map to Observable Lists so the GUI updates automatically.
You could technically do this with the serialized object too. Just store a version ID and a unique ID with the serialized object.
Either way, you would finally create an async task that is periodically checking the version ID in the database against the objects in your hashmap. If the version changes for a particular unique identifier, then bring it in and do your mapping/class loading etc.
From your explanation, it seems like what you're trying to do is a straightforward client-server application.
The client : your Java app
The server : MySQL database server (on a
web-server online).
So all you need to do is let the client install/access the Java app, and use one database.
If it is not compulsory for you to use Java, simply consider a PHP solution, which your users may access using their web browsers.
I'm developing a chat application in Java.
The architecture used is Server - Client(s) architecture.
The majority of the code is in Java, JavaFX for the GUI and PostgreSQL as the Database.
As this is a chat application (desktop), I'd like to know which is the best way to store chat history:
Locally in a text file, that the client has to read every-time
In the database as of type String (VarChar)
In the server as Lists
Some questions based on the three ways:
If a client connects from a different machine the text file will not be there
Is it possible to store every text entry in the database with a chatroomID?
How many objects can be stored in the server for as long as it runs?
Out of your three choices, I recommend you choose option #2 for storing chat history: A database, and here is why:
If you store the chat history locally in a text file, you run into issues such as how to sync with others. Also, you can modify the contents of the text file without going through your Java program (such as with an editor). If this file contains chats with sensitive information and someone has access to your computer, they can read it. This spells trouble.
Storing in a database is a great idea because it provides a central location for all your Java program. This is especially handy if multiple people are using your Java client, that way they can fetch chat history, as well as easily transfer chats to others! I wouldn't only use a type String (VarChar), but try to think of some other useful fields or columns that might be useful (i.e. timeSent, chatUserID, timeRead, etc). This also brings up the point that by using a database, you are able to set up some sort of user access rights (username and password) so that specific people can read specific chats.
If you store the chats on the server as a list within the Java server itself, and if your server restarts, you lose all your chat history. Bummer.
To sum up, keeping your Java client-server-database architecture is perfectly fine, and technically all 3 options could work, but databases is the way to go for storing your chat history! Even if setting up the database takes a little bit of work, it proves to be superior in efficiency and security out of the other 2 methods described since databases are built for archiving data.
I'm in a similar situation, I'm also developing a chat from 0, the only difference is that I'm doing it for iOS.
The way I'm developing my chat is:
I use an Ubuntu web server.
The server has a database in Mysql and the communication with the user is done through NodeJS.
In NodeJS I have a socket "Socket.io" which facilitates notifications between users.
On the iOS device, I store all the messages that it receives in Core Data, which is an extension of SQLite.
In order to obtain the pending messages depending on the device where the user is connected and I use an ID for each device, this ID is created and identified by the MAC physical address and thus what messages to obtain from the server and what not.
Initially I base myself on this database to know how to structure my application: https://github.com/yoosuf/Messenger
Socket.IO is incredibly easy to use and the best thing is that it has libraries for different programming languages, here is its page:
https://socket.io/
https://github.com/socketio/socket.io
I would say Nr2 - for safety reasons (if you care about it) and because it is a pretty easy way.
For the beginning a database with 4 columns should be enough (Date/Time, ChatroomID, UserID or just a name and the message itself). If a user sends a new message it creates a new row containing all the information that is needed for the columns. You can easily iterate through it as well when your client reloads (maybe every 10 seconds)
I have created a java application that is inserting data to a mysql database. Under some conditions, i need to post some of these data via email, using a java application that I will write as well.
My problem is that i am not sure how i should implement this.
From what I understand, I could use a UDF inside MySql to execute a java application, for which there are many against opinions into using it. Let alone that both the database and the mail client application will reside in a VM that i dont have admin access, and dont want to install anything that neither me nor the admin knows.
My other alternative, that I can think of, is to set up the mail client (or some other application), to run every minute just to check for newly inserted data. Is this a better aproach? Isn't it going to use resources for doing almost nothing. At the moment the VM might not be heavily loaded, but i have no idea how many applications there might end up running on the same machine.
Is there any other alternative i should consider using?
You also need to consider the speed of internet, database server load, system resources. If you have enough memory and less load to insert data in databases or database load is not so much then you can approach this by cron setup. For linux call a script for every 5 minutes. The script perform the following-
1. Fetch unread Emails as files
3. Perfrom shell script to read needed data.
3. write data to mysql
4. Delete the email
If you have heavy loaded system then wise you need to do this once or twice in an hour or may vary.
I am building an app and I can't seem to handle the data that contain diacritics or other type of UTF-8 characters. In my case I'm in need of this chars: ă-Ă-â-Â-î-Î-ş-Ş-ţ-Ţ.
Now, first, there is a input on the front-end that gathers some info from the users, sends it via AngularJS http module to the API. The headers are all good, the data goes to the API all good. Then, on the server side, if I log the info, it outputs: ?-?-â-Â-î-Î-?-?-?-?, and of course, the same info is put in the db (checked with phpmyadmin).
The weird thing is, as my app pulls the data from the db to print it to my app, all goes well, it prints as it should be ă-Ă-â-Â-î-Î-ş-Ş-ţ-Ţ, until I restart the server, after which it prints as it is shown in the db.
I want to point out that it isn't the cache, I'm testing the app in cache-free environment. I even tried to access from different end-points just to be sure it is not from some local issue.
Anyone has any ideas ?
I solved it myself: the problem was from JPA persistence level from Java. It didn't interpret the UTF-8 right because I was giving it inside the url. Actually what I needed to do was to create a parameter in glassfish jdbc.
I want to create java desktop application, which stores it's data offline in a database (not just some config files). The application should work fine when the user is offline. When the user becomes online, the offline database should be able to sync with the online master.
Any ideas which technologies can be used to achieve this?
This has been discussed on stackoverflow a lot and it usually boils down to: don't roll out your own solution - This is a very specialized field - Look up SymmetricDS. It does what you want.
One of my fav discussions is Strategy for Offline/Online data synchronization
Use one of the available pure java DB implementations as a local DB. Use any other DB as a remote one.
Implement logic that tries to connect to remote DB and fall backs to local one on failure. If it connects successfully to remote DB implement the data synchronization.
When the local application operates, it should not only change database, but also log the changes. That changes are sent to the server when the connection is available. Also, the application receives logged changes stored on the server (from other application instances).
The main problem is how to merge changes made by different instances. There can be 3 variants:
1) Each application instance can modify only its private part of the whole database. Your are lucky, no merging needed, and server can store only logs and not run the whole database.
2) modifications always can be merged automatically (for example, application can add a value to a common variable, but cannot set it directly). The server runs the whole database, accepts partial logs from clients, generates its own log and sends it to clients.
3) Clients are allowed to do arbitrary modifications. This leads to potential conflicts. In case of conflicts, one of conflicting changes should be rejected. That means, that if a client made local modifications, that modifications can be rejected later by the server. The user interface must reflect this issue. In the rest, this is similar to the variant 2.