I am following a 'Issue tracking' gwt project with screenshots here:
http://code.google.com/p/gwt-mvp-sample/wiki/screenshots
This template code can show exactly one Issue object with the IssueDisplayWidget
I need to allow the app to record many Issues (even just using in-memory List<> class for testing). And allow the IssueDisplayWidget to show every Issue added.
How could I achieve this?
You can use ListDataProvider to represent data and update table after each adding with EventBus or directly.
Related
I'm learning Android by forking and modifying an open source app, FrontlineSMS for Android. Here's my copy!
I want to add a few tables, Poll and PollResponse, to the database, where Poll->PR is a one-to-many relationship.
I've added classes for Poll to the project. What is the "right" way to define the PollResponse object?
Saving the Poll data happens on line 562 of Keyword.java, and somehow in there a row is added to the database with a new ID created for that row. This is the place where I also want to save a few rows into PollResponse (which doesn't exist yet) and assign their id_poll field the value from the newly created Poll row. Is there a clean way to accomplish this child relationship, as some part of src/net/frontlinesms/android/model/Poll.java or /src/net/frontlinesms/android/model/PollDao.java? Or do I need to create completely separate PollResponse objects, save the data for the Poll, then query the database for the newly created ID and save that in PollResponses? The latter is the only way I can think to do it but it seems ugly. I also tried searching around for solutions to this but I may not have the right keywords in mind.
I discovered how to create a new table Poll by creating Poll.java and PollDao.java and adding the class to /src/net/frontlinesms/android/db/FrontlineSmsSqliteHelper.java , but I'm largely fumbling around this project, reading Android development guides and trial and error. Sorry for the lack of links, I'm only allowed 2 until I get more than 10 reputation. Thanks for your help!
*EDIT - Could there be a case for rewriting this project to use an ORM like greenDAO? Again I'm still learning Android so I'm not sure if the project uses any packaged ORM. It seems like it's custom written.
I have a use case where in I need to read rows from a file, transform them using an engine and then write the output to a database (that can be configured).
While I could write a query builder of my own, I was interested in knowing if there's already an available solution (library).
I searched online and could find jOOQ library but it looks like it is type-safe and has a code-gen tool so is probably suited for static database schema's. In the use case that I have db's can be configured dynamically and the meta-data is programatically read and made available for write-purposes (so a list of tables would be made available, user can select the columns to write and the insert script for these column needs to be dynamically created).
Is there any library that could help me with the use case?
If I understand correctly you need to query the database structure, display the result to via a GUI and have the user map data from a file to that structure?
Assuming this is the case, you're not looking for a 'library', you're looking for an ETL tool.
Alternatively, if you're set on writing something yourself, the (very) basic way to do this is:
the structure of a database using Connection.getMetaData(). The exact usage can vary between drivers so you'll need to create an abstraction layer that meets your needs - I'd assume you're just interested in the table structure here.
the format of the file needs to be mapped to a similar structure to the tables.
provide a GUI that allows the user to connect elements from the file to columns in the table including any type mapping that is needed.
create a parametrized insert statement based on file element to column mapping - this is just a simple bit of string concatenation.
loop throw the rows in the file performing a batch insert for each.
My advice, get an ETL tool, this sounds like a simple problem, but it's full of idiosyncrasies - getting even an 80% solution will be tough and time consuming.
jOOQ (the library you referenced in your question) can be used without code generation as indicated in the jOOQ manual:
http://www.jooq.org/doc/latest/manual/getting-started/use-cases/jooq-as-a-standalone-sql-builder
http://www.jooq.org/doc/latest/manual/sql-building/plain-sql
When searching through the user group, you'll find other users leveraging jOOQ in the way you intend
The setps you need to do is:
read the rows
build each row into an object
transform the above object to target object
insert the target object into the db
Among the above 4 steps, the only thing you need to do is step 3.
And for the above purpose, you can use Transmorph, EZMorph, Commons-BeanUtils, Dozer, etc.
I am planning on creating an android application sometime in the future in which I'll want it to display a lot of constant data on the screen.
I'm not sure the best way to do this but I see two options:
Storing the data within the code itself such as creating a constants class.
Using an embedded database to hold the data.
I'm guessing option #2 is the best way? But it just seems weird using a database if I'm not going to be doing any updating to the database, I would only be selecting.
The total amount of data that I need the application to display is maybe about 400 lines consisting of a string and two integers...
Is there a different way people use for such a situation that I don't know about?
But it just seems weird using a database if I'm not going to be doing
any updating to the database
I am totally disagree with you. Database is not only for updating. It can be used as a better storage and definitely a best way for searching. So as you want to preserve the data then it is definitely wise to use database.
But if you want to handle data which will not persists , i,e you will use different datas for different run then you can use temporary class or other data structure to store data.
Finally, If you are planning to have portability then File storage is an easier solution.
SO you can see, that it totally depends on what you want.
I want to build a fairly simple Android application.
The basic data model of my app consist on several basic elements with relationships between them.
I want the data to be persistant so I'm thinking about using an sqlite DB.
I looked at the Android Developer website, and the closest thing that I could find that is relevant to my question is the "NotePad Tutorial" which make use of an sqlite DB to store notes.
I think by now I got the handle on the basics, but I still have some questions though:
In the tutorial they have only one table in the DB. If my application requires a more complicated scheme - should I still use the same method? that is - putting everything inside a subclass of SQLiteOpenHelper? Or is there a more "structured" way to go?
Should I bother creating classes for all the data elements stored in my DB? I mean this is what I learned that I should do, but in the documentation there is no hint about that.
If I Should create classes - How should I use them correctly? I mean, since the result of the query is a Cursor object, and not a collection of rows, Should/Can I parse that into objects?
Thanks!
Define all the tables in the same subclass, this makes easy to see all the table at one place and possibly write SQL for upgade etc
Yes, that would be easier for manipulation in the java side and makes code clean
Read from the cursor and initialize an arraylist of objects one by one.
I know how to retrieve data (just text in a table) from a database in Java and how to show it in the console. But I want to load it in a JTable.
Is there a good (modern) way (tutorial), without using Vectors?
Check out this tutorial: How to Use Tables
Seems your question is similar with these two questions:
How to fill data in a JTable with database?
Displaying data from database in JTable
Check out GlazedLists it comes with ready made TableModels that are based on modern collection interfaces.
http://www.glazedlists.com/
If you don't want to use an extra library. You can easily implement your own javax.swing.table.TableModel. I like to implement TableModel and java.util.List so I'm working with just a simple List, and hooking up any List easily.