I am working on a library management system in Java.
My program has two state for login:
1: User mode
2: Admin mode
In Admin mode login (in my swing GUI window) , there are a button for showing the borrowed books.
Now, I am confusing to how implement it?
Should it display that which users borrowed which books?
Or it should display that which books are borrowed?
I know that it depends on my requirements, But i want know what it should be in general?
This is my borrowed book in Mysql command-line:
Is this correct approach?
Should i display all my records in my JTable and then filter it by UserID ?
Like this?
Underlying IDs, which are database specific, in most cases, are not known to end users. They only feel comfortable referring to and working with readable and easily recognisable data in presentations.
Hence, it would be a better presentation, if you extract related book titles and user names and display them. And a search by partial user name or book name would be more appropriate for end user concerns.
And, dates should be handled using either date, datetime, or timestamp data types on column definitions. Using date functions on these type of columns would be comfortable than on varchar type data.
I think "which books are borrowed?" is better
I ll go with which books are borrowed by which user. And it should be able to sort by user so that I can see at a glance that a how many books a particular user has borrowed? Then I'll also put a limit to it as to a particular user can only borrow at the most 5 Books at a time.
Related
I'm working on a webapp at the moment that will display a list of items. The list is dynamic and can change between users. A great analogy is to think of the objects as books, with the db backing it as the library.
My database for Book will contain a list of all books in the library.
-A user can add a book to their collection.
-If a user wants to add a new book to their collection they will also add it to the library.
-If a user wants to add a new book to their collection and it exists in the library, nothing will be added to the Book database.
Currently my table is incredibly simple: Book(id, name). I am able to access a plethora of information about these books via an API call, such as a front cover, number of pages etc etc. I would like to store a subset of this information, especially the image url.
I think a sensible approach would be to alter my Book table so that it looks like: Book(id, name, imageUrl, otherValue, idOfThisBookInApiCallTable) the idOfThisBookInApiCallTable value will allow me to get other attributes as I need them, however I've two issues with this that I'm not sure on how to proceed.
Firstly is that this Table can easily get out of date with the APITable. I don't expect there to be much change, if any, but the risk is there.
Secondly, the image being stored is my main concern, on a page where there might be 50 books, I'll making a call to the url of the image each time. I think a sensible solution would be download the image locally and then serve it from then on repeated visits but I'm not sure if this is the correct approach.
Might I ask if anyone can see any issues with this approach and/or suggest a better one please? I have limited experience with db/web/app design so a little out of my depth here.
If saving the image locally is the correct approach, is there a 'best' way of doing this?
Thanks in advance for any help/suggestions/advice.
I can share my 2 cents of a plausible design but I think the question is too broad and is mostly opinion-based. Let's address it by taking one thing at a time.
First regarding your Book table. Why not a Library table where you maintain the current state of your library with all the books that the library has at the moment.
Each user can hold a collection (a table etc with a one to many relation like user_id to list of book_ids or whatever) and then each user sort of owns a subset of bookIDs.
When adding a new book via user or via library (library can also add more books even if no particular user brought it in) then always add it to the library and if the user_id is known for the 'owner' of this book, add a relation for this user as well in the collection table
More details of a book can be stored separately in a BookDetails table.
Storage of images on your side is always a nice option and you don't want to get blocked by the API for over-usage when requesting over and over again. You can use some cloud storage like s3 where you can keep the images and then not bother the external api. S3 supports compression and caching so you can save lots of time and not have speed problems.
All the above points are just my opinion based on the information you gave on the question. The situation can of course be different for your use-case.
I'm developing a web application for the deacons in my church. And while I have a good deal of experience coding in several languages, I have yet had to do any serious database modeling until deciding to tackle this need for my organization.
I'm very familiar with writing sql/ddl queries on existing database in (strictly mysql console, Spring MVC, Boot, Java, etc.). But, not since college have I had to consider normalization, 2nf, 3nf, 1:1, 1: many, etc... It's been a humbling experience, to say the least, trying to refresh my memory with the database theories learned years before and attempting to apply the concepts.
I created a model that seems, at least to me, to fit the needs of the users
My specific question is about locked accounts. I did read several posts about it, which only confused me more about how to approach this concept with my given data model? I really would appreciate any other suggestions and/or critiques; I definitely understand the concept and power of learning by failure.... Thanks.
Use Case :
1. Users holding office in a particular year can sign into the web
application, and view their information *(Name, Account Status,
Ordained, Team number, Calendar of their assigned duty days)*.
They can only update their personal info (name, address,
phone). Note: The account will be created for users.
2. Director, Asst. Director and System admin can log into the web
application (admin dashboard) and see a data table of all users,
w/ all relevant fields(view). This group has full read-write
privileges.
I have a locked table in the model, but not sure if that is the correct way to handle updating a user's status from active to inactive. If inactive, he cannot log into the web application. I would also use this if the user attempts to log-in more the x number of times unsuccessfully. Additionally, it would be helpful (reporting and stats) to keep previous users in the database for x number of years, of course with an inactive status.
Sorry for not using diagram (I don't use diagram tools). Here's extremely basic sample with relevant bits for audit table:
CREATE TABLE users (
user_id SERIAL,
-- ...
);
-- ...
CREATE TABLE user_updates_audit (
audit_id SERIAL,
user_id INT NOT NULL,
audit_timestamp TIMESTAMP NOT NULL default now(),
-- just free form text describing applied update (maybe old value, new value, etc)
audit_text VARCHAR(1024) NOT NULL
);
ALTER TABLE user_updates_audit ADD CONSTRAINT user_updates_audit_pk PRIMARY KEY (audit_id);
ALTER TABLE user_updates_audit ADD CONSTRAINT user_updates_audit_user_id_fk FOREIGN KEY (user_id) REFERENCES users;
Sure, you may expand from here, for example, by changing free-form audit_text to some more strict scheme, e.g. foreign key to dictionary of possible update actions (ENABLED, DISABLED, whatever) and actual values being changed. Or some other more elaborate scheme more suitable for your case.
But free-form audit is some starting point.
Main value here is that you can see all modifications history of important entities in your system, not just current state.
So I have a simple android app which is like this: It has a list of Car Manufacturers such as Honda, Ford, Mazda etc.
Then when one of the manufacturer is chosen, I need to display their car models. So if user selects Honda, I would display "Civic, CRV, Odyssey" etc.
And when user selects a specific model, I would display another list with more information.
So what kinda of data structure would be simple and easy to implement in my android app. I was thinking about using nested ArrayLists.
Also, can you please provide a link to an example on how to save the data internally using android studio and get the data when I need to.
Note: The list is dynamic, meaning that the user will have the option to add or delete any item from any of lists.
Thanks :)
This is practically what databases are for (of course I'm talking about SQLite here). I'm assuming you will have loads of data that are interconnected in a way.
I do not know how well you know database design, but you should have a table called Manufacturer which will hold the data about those (think about what data you want to save and therefore create proper columns of the table) and a table called CarModel which will have a foreign key which connects it to the Manufacturer (called manufacturer_id). These two tables need to have Many-To-One relationship -> Each manufacturer can have Many models, but each model can be produced by only One manufacturer.
This is just a basic idea which you can still improve to your own liking, but this should cover everything that you asked for very easily. For example, to get a list of Manufacturers, you'd simply Select * from Manufacturer. When you click a particular manufacturer and wanna display it's models, you'd just write a quite simple query Select * from CarModel where manufacturer_id = id (id being the parameter you pass to some function, the id of the manufacturer you want the models for. The models you select can have arbitrary amount of data like additional information about that model.
If you're not that good with raw queries, there are useful query builder which can make your life a whole lot easier.
I think that the most approaches to implement data in Android is based on SQLite. If you don't have enough experience with it i strongly recommend to investigate following tutorials with content provider:
Content-provider basics
Content-provider creating
You are right that it is very time consuming (even for experienced developers) just because this approach needs to specify entire database scheme using simple strings. But there are a few ORM-solutions you can use, such as ORMLite, but it still demanding task to investigate.
In addition i would reccomend Realm, that significantly simpler to implement, but, in my opinion, has many features you should consider (such as multithreading work)
Hope, it'll help.
I need to build a recommendation system and I want to build it from scratch to practice and get more involved with coding and learning languages. I want to be able to collect user data from a website when user click on links and send that information into a table in the database that would return a set of suggestions according to the links chosen during a given session. Is it even possible to do such thing? For example, say I have a E-store that sells all type of different bikes and gear:
Bikes
Mountain Bikes
BMX Bikes
Triathlon bicycles
Etc...
Gear
Mountain helmets
BMX Helmets
Triathlon Helmets
Etc...
Now let's give those categories some ID'S 1,2,3,4,5 & 6 then create a table named recommendation_system that would be connected to the category_table.
According to the input inserted into recommendation_system the Servlet will call the appropriate category from the category_table and return a set of products.
The system would make precise guesses with user input.
For instance, there are very good probabilities that a user that picks id(2) BMX Bikes as first category will be interested to see suggestions from id(4) BMX Helmets and so on. Its all about directing the user up to the next same product's "family".
So is it possible to collect those given id's, send them to a database and then display suggestions according to the id that was previously pick? Do I need to use some kind of a form or only handle HTTP requests?
First you cannot know if a user has clicked on one link. All you know is that during a session, a client has sent a request for a URL, possibly through a link but maybe from its history, directly on address bar, or even through another window of same browser. IMHO a filter could perform that task, or depending of the technology, interceptors (for Spring MVC or Struts2), or aspects on relevant controllers (for any MVC2 solution).
I need some of your inputs in deciding a right approach in following case.
I am currently working on a ecommerce application ( An online shopping website).
Here, on homepage of application, I have to display a list of products available in shop.
The end user has a facility of applying a filter to products list so that only the products satisfying the applied filter will be displayed.( Filter like display products with selected company,price range and so on ).
So, my question is regarding the logic for applying the filter.
I have following ideas in mind to implement this requirement.
As user selects different criterias on page, generate SQL query dynamically( By appending a string with required where clauses) and fire the generated SQL on each request.
Set up all possible combinations of SQLs in database already ( say in a stored procedure ). As user changes the criteria, select the appropriate SQL in stored procedure to run.
Can anyone please guide me, if there is any better way to handle this requirement ?
Any input is highly appreaciated.
Please let me know if more information is required in this context.
Thanks.
I would do the first one, but you've got to be wary of SQL injection attacks.
I don't like your second option because stored procedures are usually written in a language that I consider worse than java. That's pure opinion, but that's my opinion. They also aren't database agnostic.
Alternatively, you can use JPA for this. For example, there are Hibernate Filters.
Something that works well for sites like yours is to not change the query to retrieve different items to offer for sale but, instead, to offer the all the same items but to change the order they appear on the site.
So, if the user wants items priced $100-$500, you still show the items under $100 and over $500 but the ones in that range appear first, then the ones outside the range in some sort of random order. Or, if there are multiple criteria, you may show items meeting all but one of the criteria.
This also solves the problem of the user asking for coffee mugs over $500. If there are no matches, you don't give the user 0 items to select from but you give them some of the other items with preference to coffee mugs of any price. Presenting the user with no items to purchase is a lost chance that they might see something they want.
You can implement this in either of the ways you mentioned except you are varying the "order by" clause.
My personal preference is to NOT use stored procedures.
But, if you are working with a large group with experts in database use in the group that can optimize the database usage and keep the stored procedures in top shape, that might be an option.
If its a single person or small team of java developers, don't expect them to be experts in Java and SQL/Database as well. Play to your teams strengths.