Closed plopezgit closed 11 months ago
Debemos crear un programa para gestionar el catálogo de productos de una floristería. En el nivel 1, gestiona la persistencia en un archivo TXT.
Este programa debe cumplir con los siguientes requisitos:
En cuanto a las funcionalidades del Main, como mínimo, debe incluir las siguientes:
OVERVIEW: MVP PROGRAM FILES STRUCTURES:
Entity
App
Exception
Tools
Test
file.properties
OVERVIEW: SHOP MANAGER METHODS:
Stock:
Purchase Order Ticket:
Earn:
Backup:
files on: /Users/pedrolopez/Proyectos/Study
MYSQL CONNECTION CLASS:
import java.sql.Connection; import java.sql.DriverManager; public class Connection_study_db { private Connection dbConnection = null; public Connection_study_db () { } public Connection getConnection () { try { dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/study", "root", ""); } catch (Exception ex) { System.out.println("There is no connection"); ex.printStackTrace(); } return dbConnection; } }
MYSQL ENTITY CRUD:
Insert:
public void addConcept (String titleConcept, Size effortEstimationConcept) { String size= conceptExistOnConceptResultSet(titleConcept); if (size == null) { Connection conexiondb = conceptDbConnection.getConnection(); try { insertConceptOnConceptDB = conexiondb.prepareStatement("INSERT INTO CONCEPTOS (titleConcept, effortEstimationConcept) VALUES(?,?) "); insertConceptOnConceptDB.setString(1, titleConcept); insertConceptOnConceptDB.setString(2, effortEstimationConcept.toString()); insertConceptOnConceptDB.execute(); System.out.println("The " + titleConcept + " was stored!"); conexiondb.close(); incrementItineraryPoints(1); putBadgeItinerary(); } catch (Exception ex) { System.out.println("There is no connection"); ex.printStackTrace(); } } else { System.out.println("The concept " + titleConcept + " already exists!"); } }
public void addNewIdea (String titleIdea, String descriptionIdea) { Connection conexiondb = conceptDbConnection.getConnection(); try { PreparedStatement insertConceptOnConceptDB = conexiondb.prepareStatement("INSERT INTO IDEAS (titleconcept, titleidea, descriptionidea) VALUES(?,?,?) "); insertConceptOnConceptDB.setString(1, titleConcept); insertConceptOnConceptDB.setString(2, titleIdea); insertConceptOnConceptDB.setString(3, descriptionIdea); insertConceptOnConceptDB.execute(); System.out.println("Your idea was stored!"); conexiondb.close(); } catch (Exception ex) { System.out.println("There is no connection"); ex.printStackTrace(); } }
Read:
public String conceptExistOnConceptResultSet (String titleConcept) { String size = null; Connection conexiondb = conceptDbConnection.getConnection(); try { getConceptResultSet = conexiondb.createStatement(); conceptResultSet = getConceptResultSet.executeQuery("SELECT titleConcept, effortEstimationConcept FROM CONCEPTOS"); while (conceptResultSet.next() && size==null) { if (conceptResultSet.getString("titleConcept").equalsIgnoreCase(titleConcept)) { size = conceptResultSet.getString(2); } else { size = null; } } conceptResultSet.close(); conexiondb.close(); } catch (Exception ex) { System.out.println("There is no connection"); ex.printStackTrace(); }
public String parseConceptResultSet () { String result = ""; Connection conexiondb = conceptDbConnection.getConnection(); try { getConceptResultSet = conexiondb.createStatement(); conceptResultSet = getConceptResultSet.executeQuery("SELECT * FROM CONCEPTOS"); while (conceptResultSet.next()) { result += conceptResultSet.getString("titleConcept") + " | " + "Size: " + conceptResultSet.getString("effortEstimationConcept") + " | " + "Notes: " + conceptResultSet.getString("notesConcept") + " | " + "What is it for?: " + conceptResultSet.getString("whatConcept") + " | " + "How is it used?: " + conceptResultSet.getString("howConcept") + " | " + "Why is it used?: " + conceptResultSet.getString("whyConcept") + " | " + "Check in counter: " + conceptResultSet.getString("checkInCounterConcept") + " | " + "\n"; } conceptResultSet.close(); } catch (Exception ex) { System.out.println("There is no connection"); ex.printStackTrace(); } return result; }
public String parseIdeaResultSet () { String result = ""; Connection conexiondb = conceptDbConnection.getConnection(); try { getConceptResultSet = conexiondb.createStatement(); conceptResultSet = getConceptResultSet.executeQuery("SELECT * FROM IDEAS"); while (conceptResultSet.next()) { result += conceptResultSet.getString("ididea") + " | " + "Concept: " + conceptResultSet.getString("titleconcept") + " | " + "Idea: " + conceptResultSet.getString("titleidea") + " | " + "Description: " + conceptResultSet.getString("descriptionidea") + " | " + "\n"; } conceptResultSet.close(); } catch (Exception ex) { System.out.println("There is no connection"); ex.printStackTrace(); } return result; }
Update:
public void takingNotes () { Toolkit.getDefaultToolkit().beep(); Connection conexiondb = conceptDbConnection.getConnection(); try { PreparedStatement updateOnConceptDB = conexiondb.prepareStatement("UPDATE CONCEPTOS SET notesConcept= ? WHERE titleConcept= ?"); updateOnConceptDB.setString(1, notesConcept += Tool.inputString("Ring@~~ Any note so far? ") + " "); updateOnConceptDB.setString(2, titleConcept); updateOnConceptDB.execute(); conexiondb.close(); } catch (Exception ex) { System.out.println("There is no connection"); ex.printStackTrace(); } }
MONGODB CRUD:
try (MongoClient mongoClient = MongoClients.create()) { MongoDatabase opticDb = mongoClient.getDatabase("optic"); MongoCollection<Document> clientCollection = opticDb.getCollection("client"); Document client = new Document ("_id", new ObjectId()); client.append("name", "Tris") .append("phone", "534675345") .append("email", "tri@kio.com"); List <Document> clients = new ArrayList<>(); clients.add(new Document ("_id", new ObjectId()).append("name", "Bull") .append("phone", "35687463") .append("email", "bull@gus.com")); clients.add(new Document ("_id", new ObjectId()).append("name", "Marc") .append("phone", "35344352") .append("email", "marc@is.com")); clients.add(new Document ("_id", new ObjectId()).append("name", "Kyr") .append("phone", "865345435") .append("email", "kir@wer.com")); clientCollection.insertMany(clients, new InsertManyOptions().ordered(false)); }
Delete:
try (MongoClient mongoClient = MongoClients.create()) { MongoDatabase opticDb = mongoClient.getDatabase("optic"); MongoCollection<Document> clientCollection = opticDb.getCollection("client"); Bson filter = eq("phone", "634625424"); DeleteResult result = clientCollection.deleteOne(filter); System.out.println(result); }
try (MongoClient mongoClient = MongoClients.create()) { MongoDatabase opticDb = mongoClient.getDatabase("optic"); MongoCollection<Document> clientCollection = opticDb.getCollection("client"); Consumer<Document> printConsumer = document -> System.out.println(document.toJson()); clientCollection.find(ne("name", "kjhfdjhd")).forEach(printConsumer); }
JsonWriterSettings prettyPrint = JsonWriterSettings.builder().indent(true).build(); try (MongoClient mongoClient = MongoClients.create()) { MongoDatabase opticDb = mongoClient.getDatabase("optic"); MongoCollection<Document> clientCollection = opticDb.getCollection("client"); Bson filter = ne("name", "Ryal"); Bson updateOperation = set("comment", "Ryal is a very frequent client"); UpdateResult updateResult = clientCollection.updateOne(filter, updateOperation); System.out.println(clientCollection.find(filter).first().toJson(prettyPrint)); System.out.println(updateResult); }
@plopezgit https://drive.google.com/file/d/1HGccPeN8PnWKa4C7asYXcVx9HYpdusQM/view?usp=sharing
Latest update 23/11/2023:
Debemos crear un programa para gestionar el catálogo de productos de una floristería. En el nivel 1, gestiona la persistencia en un archivo TXT.
Este programa debe cumplir con los siguientes requisitos:
En cuanto a las funcionalidades del Main, como mínimo, debe incluir las siguientes:
OVERVIEW: MVP PROGRAM FILES STRUCTURES:
Entity
App
Exception
Tools
Test
file.properties
OVERVIEW: SHOP MANAGER METHODS:
Stock:
Purchase Order Ticket:
Earn:
Backup:
files on: /Users/pedrolopez/Proyectos/Study
MYSQL CONNECTION CLASS:
MYSQL ENTITY CRUD:
Insert:
Read:
Read:
Update:
MONGODB CRUD:
Insert:
Delete:
Read:
Update: