diff --git a/.gitignore b/.gitignore index c7de9b3..817f0f2 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,4 @@ /Semester 3/Assignments/mavenproject1/target/ /Semester 3/Assignments/Templates01_CalebFontenot/target/ /Semester 3/Assignments/MaxTask/target/ +/Semester 3/Assignments/MP1_Ajax/target/ diff --git a/Semester 3/Assignments/MP1_Ajax.zip b/Semester 3/Assignments/MP1_Ajax.zip new file mode 100644 index 0000000..7fb8466 Binary files /dev/null and b/Semester 3/Assignments/MP1_Ajax.zip differ diff --git a/Semester 3/Assignments/MP1_Ajax/nb-configuration.xml b/Semester 3/Assignments/MP1_Ajax/nb-configuration.xml new file mode 100644 index 0000000..56fc6cb --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/nb-configuration.xml @@ -0,0 +1,21 @@ + + + + + + 10-web + gfv700ee10 + JSP + JDK_15__System_ + + diff --git a/Semester 3/Assignments/MP1_Ajax/pom.xml b/Semester 3/Assignments/MP1_Ajax/pom.xml new file mode 100644 index 0000000..c5f2f0e --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/pom.xml @@ -0,0 +1,125 @@ + + 4.0.0 + asdv + MP1_Ajax + 1 + war + MP1_Ajax-1 + + + 11 + 11 + ${project.build.directory}/endorsed + UTF-8 + false + 10.0.0 + + + + + jakarta.platform + jakarta.jakartaee-api + ${jakartaee} + provided + + + org.primefaces + primefaces + 13.0.2 + jakarta + + + + + org.eclipse.persistence + org.eclipse.persistence.core + 2.7.12 + + + org.eclipse.persistence + org.eclipse.persistence.asm + 9.4.0 + + + org.eclipse.persistence + org.eclipse.persistence.antlr + 2.7.12 + + + org.eclipse.persistence + org.eclipse.persistence.jpa + 2.7.12 + + + org.eclipse.persistence + org.eclipse.persistence.jpa.jpql + 2.7.12 + + + org.eclipse.persistence + org.eclipse.persistence.moxy + 2.7.12 + + + org.eclipse.persistence + jakarta.persistence + 2.2.3 + + + mysql + mysql-connector-java + 8.0.33 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + 11 + + ${endorsed.dir} + + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + false + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.6 + + + validate + + copy + + + ${endorsed.dir} + true + + + jakarta.platform + jakarta.jakartaee-api + ${jakartaee} + jar + + + + + + + + + \ No newline at end of file diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/Dao.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/Dao.java new file mode 100644 index 0000000..788ccda --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/Dao.java @@ -0,0 +1,25 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template + */ + + +import asdv.mp1_ajax.pojos.Stock; +import java.util.List; + +/** + * + * @author asdv5 + */ +public interface Dao +{ + void create(T t); + void edit(T t); + void remove(T t); + T find(Object id); + List findAll(); + List findRange(int[] range); + int count(); +} + + diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/JakartaRestConfiguration.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/JakartaRestConfiguration.java new file mode 100644 index 0000000..c06b3d1 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/JakartaRestConfiguration.java @@ -0,0 +1,13 @@ +package asdv.mp1_ajax; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +/** + * Configures Jakarta RESTful Web Services for the application. + * @author Juneau + */ +@ApplicationPath("resources") +public class JakartaRestConfiguration extends Application { + +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/ManyToMany.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/ManyToMany.java new file mode 100644 index 0000000..abced83 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/ManyToMany.java @@ -0,0 +1,109 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template + */ +package asdv.mp1_ajax.pojos; + +import java.util.List; +import java.util.Set; + +/** + * + * @author A. V. Markou + * @param + * @param + */ +public interface ManyToMany +{ + /** + * Creates a Many to Many relationship between the parentLeft and the + * childrenRight. Example for ( Many1 a, Many2 1, 2, 3) it creates --> (a 1) + * ( a 2 ) ( a 3 ) and ( 1, a ), ( 2, a ), ( 3, a). No duplicate values of + * Many2 are allowed. + * + * @param parentLeft - exactly one Many1 object. + * @param childrenRight - one or more Many2 objects. + * @return the previous value associated with Many1, or null if there was no + * Many1 with the same "key". + * @throws ClassCastException - if the class of the specified Many1, or + * Many2 or value prevents it from being stored in this map( i,e Many1 is + * String and you pass an object) + * @throws NullPointerException - if the specified Many1 or Many2 is null + * and ManyToMany does not permit nulls as values. + * @throw IllegalArgumentException - if a duplicate exists in childrenRight + * list ( s1 --> p1,p2,p2 is not allowed). + * @return the previous value associated with parentLeft, or null if there + * was no childrenRight for parentLeft. + */ + List add(Many1 parentLeft, Many2... childrenRight); + + /** + * Returns the List of all left children of the parentRight. + * + * @param parentRight a parent at the RHS of the many to many relationship. + * @return the List of all left children of the parentRight. + * @throw IllegalArgumentException if the value of parameter parentRight + * does not exist in the RHS of the many to many relationship. + */ + List getChildrenLeft(Many2 parentRight); + + /** + * Returns the List of all right children of the parentLeft. + * + * @param parentLeft a parent at the LHS of the many to many relationship. + * @return the List of all right children of the parentLeft. + * @throws IllegalArgumentException if the value of parameter parentLeft + * does not exist on the LHS of the many to many relationship. + */ + List getChildrenRight(Many1 parentLeft); + + /** + * Returns a set of the Many1 elements that exist on the LHS of the many to + * many relationship. + * + * @return Set of Many1 + */ + Set getParentsLeft(); + + /** + * Returns a set of the Many2 elements that exist on the RHS of the many to + * many relationship. + * + * @return Set of Many2 + */ + Set getParentsRight(); + + /** + * Removes the many1 parameter from the LHS of the many relationship AND all + * its corresponding values that exist in the RHS of the many to many + * relationship. For example given: ( LHS e1: p1, p2 e2: p2, p3 RHS: p1: e1 + * p2: e1, e2 p3: e2 after removing e1 from the LHS will results into: ( LHS + * e2: p2, p3 RHS: p2: e2 p3: e2 + * + * @param many1 the unique element on the LHS to be removed. + * @throws NullPointerException if parameter many1 is null. + * @return true if the removal occurred, false if many1 does not exist in + * the LHS of the many to many relationship. + */ + boolean removeLeft(Many1 many1); + + /** + * Removes the many1 parameter from the RHS of the many relationship AND all + * its corresponding values that exist in the LHS of the many to many + * relationship. For example given: LHS e2: p2, p3 RHS: p2: e2 p3: e2 after + * removing p2 from the RHS will results into: LHS e2: p3 RHS p3: e2 + * + * + * @param many2 the unique element on the LHS to be removed. + * @throws NullPointerException if parameter many1 is null. + * @return true if the removal occurred, false if many1 does not exist in + * the LHS of the many to many relationship. + */ + boolean removeRight(Many2 many2); + + /** + * Clears all. + * + */ + void clear(); +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/ManyToManyFactory1.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/ManyToManyFactory1.java new file mode 100644 index 0000000..2467e1c --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/ManyToManyFactory1.java @@ -0,0 +1,212 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package asdv.mp1_ajax.pojos; + +import asdv.mp1_ajax.pojos.ManyToMany; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * + * @author asdv5 + */ +public class ManyToManyFactory1 +{ + public static //generic types to be used in the method + ManyToMany< Many1, Many2>//return type + createManyToMany() + { + return new ManyToMany() + { + + private Map left = new HashMap(); + private Map right = new HashMap(); + + @Override + public String toString() + { + return "{" + "left=" + left + ", right=" + right + '}'; + } + + @Override + public List add(Many1 parentLeft, Many2... childrenRight) + { + if (parentLeft==null || childrenRight==null || getParentsLeft().contains(parentLeft)) { + throw new IllegalArgumentException("Invalid input: null arguments or duplicate parent"); + } + + left.put(parentLeft, Arrays.asList(childrenRight)); + + for(Many2 parentRight : childrenRight) + { + + right.put(parentRight, Arrays.asList(parentLeft)); + } + + + return Arrays.asList(childrenRight); + } + + @Override + public List getChildrenLeft(Many2 parentRight) + { + if(right.get(parentRight)==null) + { + throw new IllegalArgumentException(parentRight+" is not a valid R parent"); + } + return (List) right.get(parentRight); + } + + @Override + public List getChildrenRight(Many1 parentLeft) + { + if(left.get(parentLeft)==null) + { + throw new IllegalArgumentException(parentLeft+" is not a valid L parent"); + } + return (List)left.get(parentLeft); + } + + @Override + public Set getParentsLeft() + { + return (Set) left.keySet(); + } + + @Override + public Set getParentsRight() + { + return (Set) right.keySet(); + } + + @Override + public boolean removeLeft(Many1 many1) + { + if(!getParentsLeft().contains(many1)) + { + return false; + } + left.remove(many1); + for(Many2 parentRight : getParentsRight()) + { + right.remove(parentRight, many1); + } + return true; + } + + @Override + public boolean removeRight(Many2 many2) + { + if(!getParentsRight().contains(many2)) + { + return false; + } + right.remove(many2); + for(Many1 parentLeft : getParentsLeft()) + { + left.remove(parentLeft, many2); + } + return true; + } + + @Override + public void clear() + { + left.clear(); + right.clear(); + } + }; + } + + public static void main(String[] args) throws InterruptedException + { + ManyToMany mm = ManyToManyFactory1.createManyToMany(); + //mm.add(1, 1);///will not compile, we have Many1, Many2 as String + System.out.println("add(e1, p1, p2)returns: " + mm.add("e1", "p1", "p2")); + System.out.println("add(e2, p2, p3)returns: " + mm.add("e2", "p2", "p3")); + System.out.println("getParentsLeft returns: " + mm.getParentsLeft()); + System.out.println("getParentsRight returns: " + mm.getParentsRight()); + System.out.println("getChildrenLeft(p2) returns: " + mm.getChildrenLeft("p2")); + System.out.println("getChildrenLeft(p3) returns: " + mm.getChildrenLeft("p3")); + System.out.println("getChildrenRight(e1) returns: " + mm.getChildrenRight("e1")); + System.out.println("getChildrenRight(e2) returns: " + mm.getChildrenRight("e2")); + System.out.println("-----------------------------------------------"); + System.out.println("The internal hash maps of ManyToMany after insertions: " + mm); + + System.out.println("----------AFTER REMOVAL of e1 LEFT----------------------------------------"); + System.out.println("removeLeft(e1) returns: " + mm.removeLeft("e1")); + System.out.println("getParentsLeft returns: " + mm.getParentsLeft()); + System.out.println("getParentsRight returns: " + mm.getParentsRight()); + System.out.println("getChildrenRight(e2) returns: " + mm.getChildrenRight("e2")); + System.out.println("getChildrenLeft(p2) returns: " + mm.getChildrenLeft("p2")); + System.out.println("getChildrenLeft(p3) returns: " + mm.getChildrenLeft("p3")); + System.out.println("The internal hash maps of ManyToMany after removal LEFT: " + mm); + + System.out.println("\n----------AFTER REMOVAL of p2 RIGHT----------------------------------------"); + System.out.println("removeRight(p2) returns: " + mm.removeRight("p2")); + System.out.println("getParentsLeft returns: " + mm.getParentsLeft()); + System.out.println("getParentsRight returns: " + mm.getParentsRight()); + System.out.println("getChildrenRight(e2) returns: " + mm.getChildrenRight("e2")); + System.out.println("getChildrenLeft(p3) returns: " + mm.getChildrenLeft("p3")); + System.out.println("--------------------------------------------------"); + System.out.println("mm.removeLeft(e1) returns: " + mm.removeLeft("e1")); + + System.out.println("The internal hash maps of ManyToMany after removal RIGHT: " + mm); + Thread.sleep(5000, 0); + + System.out.println("---------------CATCHING EXCEPTIONS -----------------------------------"); + try + { + mm.getChildrenRight("e10");//e10 dos not exist + } + catch (RuntimeException e) + { + System.err.println("getChildrenRight for e10 throws exception:" + e); + } + try + { + System.out.println(mm.add("e6", new String[] + { + "value1", null + })); + } + catch (RuntimeException e) + { + System.err.println("add(e6, new String[]{null } ) throws exception: " + e); + } + try + { + System.out.println(mm.add(null, "p1")); + } + catch (RuntimeException e) + { + System.err.println("add(null, p1)returns throws exception: " + e); + } + try + { + System.out.println(mm.getChildrenRight("p1")); + } + catch (RuntimeException e) + { + System.err.println("getChildrenRight(p1) throws exception: " + e); + } + try + { + mm.add((String) new Object(), (String) new Object()); + } + catch (RuntimeException e) + { + System.err.println("add((String) new Object(), (String) new Object()) throws exception: " + e); + } + mm.clear(); + System.out.println("-----------------------------------------------"); + System.out.println("The internal hash maps of ManyToMany after clear: " + mm); + + + } +} \ No newline at end of file diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/Stock.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/Stock.java new file mode 100644 index 0000000..94ce92f --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/Stock.java @@ -0,0 +1,147 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package asdv.mp1_ajax.pojos; + +import java.io.Serializable; +import java.util.Collection; + + +public class Stock implements Serializable +{ + private static final long serialVersionUID = 1L; + + private String stockId; + + private String companyName; + + private double priceCurrent; + + private double priceClosing; + + private long numberOfSharesAvailable; + + private long numberOfSharesSold; + private Collection transactionsCollection; + + public Stock() + { + } + + public Stock(String stockId) + { + this.stockId = stockId; + } + + public Stock(String stockId, String companyName, double priceCurrent, double priceClosing, long numberOfSharesAvailable, long numberOfSharesSold) + { + this.stockId = stockId; + this.companyName = companyName; + this.priceCurrent = priceCurrent; + this.priceClosing = priceClosing; + this.numberOfSharesAvailable = numberOfSharesAvailable; + this.numberOfSharesSold = numberOfSharesSold; + } + + public String getStockId() + { + return stockId; + } + + public void setStockId(String stockId) + { + this.stockId = stockId; + } + + public String getCompanyName() + { + return companyName; + } + + public void setCompanyName(String companyName) + { + this.companyName = companyName; + } + + public double getPriceCurrent() + { + return priceCurrent; + } + + public void setPriceCurrent(double priceCurrent) + { + this.priceCurrent = priceCurrent; + } + + public double getPriceClosing() + { + return priceClosing; + } + + public void setPriceClosing(double priceClosing) + { + this.priceClosing = priceClosing; + } + + public long getNumberOfSharesAvailable() + { + return numberOfSharesAvailable; + } + + public void setNumberOfSharesAvailable(long numberOfSharesAvailable) + { + this.numberOfSharesAvailable = numberOfSharesAvailable; + } + + public long getNumberOfSharesSold() + { + return numberOfSharesSold; + } + + public void setNumberOfSharesSold(long numberOfSharesSold) + { + this.numberOfSharesSold = numberOfSharesSold; + } + + public Collection getTransactionsCollection() + { + return transactionsCollection; + } + + public void setTransactionsCollection(Collection transactionsCollection) + { + this.transactionsCollection = transactionsCollection; + } + + @Override + public int hashCode() + { + int hash = 0; + hash += (stockId != null ? stockId.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) + { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof Stock)) + { + return false; + } + Stock other = (Stock) object; + if ((this.stockId == null && other.stockId != null) || (this.stockId != null && !this.stockId.equals(other.stockId))) + { + return false; + } + return true; + } + + @Override + public String toString() + { + return "asdv.mp1_ajax.entities.Stock[ stockId=" + stockId + " ]"; + } + +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/StockHolder.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/StockHolder.java new file mode 100644 index 0000000..eb79d83 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/StockHolder.java @@ -0,0 +1,98 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package asdv.mp1_ajax.pojos; + +import java.io.Serializable; +import java.util.Collection; + + + +public class StockHolder implements Serializable +{ + private static final long serialVersionUID = 1L; + + private Integer stockHolderId; + + private String name; + + //cascade + private Collection transactionsCollection; + + public StockHolder() + { + } + + public StockHolder(Integer stockHolderId) + { + this.stockHolderId = stockHolderId; + } + + public StockHolder(Integer stockHolderId, String name) + { + this.stockHolderId = stockHolderId; + this.name = name; + } + + public Integer getStockHolderId() + { + return stockHolderId; + } + + public void setStockHolderId(Integer stockHolderId) + { + this.stockHolderId = stockHolderId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Collection getTransactionsCollection() + { + return transactionsCollection; + } + + public void setTransactionsCollection(Collection transactionsCollection) + { + this.transactionsCollection = transactionsCollection; + } + + @Override + public int hashCode() + { + int hash = 0; + hash += (stockHolderId != null ? stockHolderId.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) + { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof StockHolder)) + { + return false; + } + StockHolder other = (StockHolder) object; + if ((this.stockHolderId == null && other.stockHolderId != null) || (this.stockHolderId != null && !this.stockHolderId.equals(other.stockHolderId))) + { + return false; + } + return true; + } + + @Override + public String toString() + { + return "asdv.mp1_ajax.entities.StockHolder[ stockHolderId=" + stockHolderId + " ]"; + } + +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/Transactions.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/Transactions.java new file mode 100644 index 0000000..805d3d5 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/Transactions.java @@ -0,0 +1,112 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package asdv.mp1_ajax.pojos; + +import java.io.Serializable; + + +public class Transactions implements Serializable +{ + private static final long serialVersionUID = 1L; + + protected TransactionsPK transactionsPK; + + private int qty; + + private Stock stock; + + private StockHolder stockHolder; + + public Transactions() + { + } + + public Transactions(TransactionsPK transactionsPK) + { + this.transactionsPK = transactionsPK; + } + + public Transactions(TransactionsPK transactionsPK, int qty) + { + this.transactionsPK = transactionsPK; + this.qty = qty; + } + + public Transactions(int stockHolderId, String stockId) + { + this.transactionsPK = new TransactionsPK(stockHolderId, stockId); + } + + public TransactionsPK getTransactionsPK() + { + return transactionsPK; + } + + public void setTransactionsPK(TransactionsPK transactionsPK) + { + this.transactionsPK = transactionsPK; + } + + public int getQty() + { + return qty; + } + + public void setQty(int qty) + { + this.qty = qty; + } + + public Stock getStock() + { + return stock; + } + + public void setStock(Stock stock) + { + this.stock = stock; + } + + public StockHolder getStockHolder() + { + return stockHolder; + } + + public void setStockHolder(StockHolder stockHolder) + { + this.stockHolder = stockHolder; + } + + @Override + public int hashCode() + { + int hash = 0; + hash += (transactionsPK != null ? transactionsPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) + { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof Transactions)) + { + return false; + } + Transactions other = (Transactions) object; + if ((this.transactionsPK == null && other.transactionsPK != null) || (this.transactionsPK != null && !this.transactionsPK.equals(other.transactionsPK))) + { + return false; + } + return true; + } + + @Override + public String toString() + { + return "asdv.mp1_ajax.entities.Transactions[ transactionsPK=" + transactionsPK + " ]"; + } + +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/TransactionsPK.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/TransactionsPK.java new file mode 100644 index 0000000..0b09f48 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/pojos/TransactionsPK.java @@ -0,0 +1,87 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package asdv.mp1_ajax.pojos; + +import java.io.Serializable; +import jakarta.persistence.Embeddable; + +/** + * + * @author asdv5 + */ +@Embeddable +public class TransactionsPK implements Serializable +{ + + private int stockHolderId; + + private String stockId; + + public TransactionsPK() + { + } + + public TransactionsPK(int stockHolderId, String stockId) + { + this.stockHolderId = stockHolderId; + this.stockId = stockId; + } + + public int getStockHolderId() + { + return stockHolderId; + } + + public void setStockHolderId(int stockHolderId) + { + this.stockHolderId = stockHolderId; + } + + public String getStockId() + { + return stockId; + } + + public void setStockId(String stockId) + { + this.stockId = stockId; + } + + @Override + public int hashCode() + { + int hash = 0; + hash += (int) stockHolderId; + hash += (stockId != null ? stockId.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) + { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof TransactionsPK)) + { + return false; + } + TransactionsPK other = (TransactionsPK) object; + if (this.stockHolderId != other.stockHolderId) + { + return false; + } + if ((this.stockId == null && other.stockId != null) || (this.stockId != null && !this.stockId.equals(other.stockId))) + { + return false; + } + return true; + } + + @Override + public String toString() + { + return "asdv.mp1_ajax.entities.TransactionsPK[ stockHolderId=" + stockHolderId + ", stockId=" + stockId + " ]"; + } + +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/resources/JakartaEE10Resource.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/resources/JakartaEE10Resource.java new file mode 100644 index 0000000..ef65f84 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/asdv/mp1_ajax/resources/JakartaEE10Resource.java @@ -0,0 +1,20 @@ +package asdv.mp1_ajax.resources; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Response; + +/** + * + * @author + */ +@Path("jakartaee10") +public class JakartaEE10Resource { + + @GET + public Response ping(){ + return Response + .ok("ping Jakarta EE") + .build(); + } +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/beans/StockBean.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/beans/StockBean.java new file mode 100644 index 0000000..5d1563f --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/beans/StockBean.java @@ -0,0 +1,36 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template + */ + +package beans; + +import edu.slcc.ajax.bl.StockDB; +import jakarta.enterprise.context.SessionScoped; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import java.io.Serializable; + +/** + * + * @author asdv5 + */ +@Named(value="stockBean") +@SessionScoped +public class StockBean implements Serializable +{ + + @Inject + StockDB stocks; + /** Creates a new instance of StockBean */ + public StockBean() { + } + + public StockDB getStocks() + { + return stocks; + } + + + +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/Dao.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/Dao.java new file mode 100644 index 0000000..e57ab26 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/Dao.java @@ -0,0 +1,28 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template + */ +package edu.slcc.ajax.bl; + +import java.sql.SQLException; +import java.util.List; + +public interface Dao +{ + void create(T t); + + void edit(T t); + + void remove(T t); + + T find(Object id) ; + + + List findAll() + throws SQLException;; + + List findRange(int[] range); + + int count(); + +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/Database.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/Database.java new file mode 100644 index 0000000..bf00493 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/Database.java @@ -0,0 +1,73 @@ + +package edu.slcc.ajax.bl; + +import java.sql.Connection; +import java.util.List; +import java.util.Map; + +/** + * + * @author ASDV2 + */ +public interface Database +{ + + /** + * Returns a Connection to a database or null if no connection is done. + * + * @param databaseName name + * @param userName database user name + * @param password database password + * @param driver driver that connects us to database + * @return Connection the connection to database or null if no connection + */ + public Connection getConnection(String databaseName, String userName, String password, String driver); + + /** + * Selects the projected columns of a table where the AND condition of the + * WHERE clause is true. + * + * @param tableName table name + * @param projectionFields fields if SELECT clause ( projected columns) + * @param whereFieldsNValues fields in WHERE clause, key is the field name( + * LHS ) and value of the field ( RHS ). For example snumber = 's1', status + * > "10". + * @param operators the operators that apply to whereFieldsNValues. They are + * positioned between the LHS and the RHS of the whereFieldsNValues + * parameter. The operators are always the same size as the + * whereFieldsNValues. That is,the first operator applies to the first entry + * of the map, the second operator to the 2nd entry and so on. + * @return the projected columns of a table, after the WHERE clause applies + * by ANDing all entries of the map ( whereFieldsNValues). If an SQL + * exception is thrown return NULL if an error ( exception occurs). + * + */ + public List selectFieldsFromTableWhereFields(String tableName, + List projectionFields, + Map whereFieldsNValues, + List operators + ); + + /** + * Returns the list of all rows of the table "tableName" + * + * @param tableName the name of the table to return + * @return a list with all rows in the the table. + */ + public List selectAllFromTable(String tableName); + + /** + * Returns true if the table exists in the database, false otherwise + * + * @param tableName the name of the table + * @return true if the table exists in the database, false otherwise + */ + boolean isTable(String tableName); + + /** + * Closes a connection + * + * @param c the connection to close + */ + public void closeConnection(Connection c); +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/StockDB.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/StockDB.java new file mode 100644 index 0000000..a7011ae --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/StockDB.java @@ -0,0 +1,129 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package edu.slcc.ajax.bl; + + +import asdv.mp1_ajax.pojos.Stock; +import java.io.Serializable; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +/** + * + * @author asdv5 + */ +public class StockDB + implements Dao, Serializable +{ + @Override + public List findAll() + throws SQLException + { + // test exception code + //if ( true) + // throw new SQLException(); + + List tableStocks = new ArrayList(); + String databaseName = "nyse"; + String userName = "java"; + String password = "dA^vTFd8&JDvt8HjiNVahgSj"; + String URL2 = "com.mysql.jdbc.Driver"; + Connection con = new UtilitiesDatabase().connection( + databaseName, userName, password, URL2); + PreparedStatement ps = null; + try + { + if (con == null) + { + throw new RuntimeException("cannot connect to database"); + } + String table = ""; + ResultSet rs = null; + String sqlStr = "SELECT * FROM stock"; + //prepare statement + ps = con.prepareStatement(sqlStr); + //execute + rs = ps.executeQuery(); + while (rs.next()) + { + String stockId = rs.getString(1); + String companyName = rs.getString(2); + double priceCurrent = rs.getDouble(3); + double priceClosing = rs.getDouble(4); + long numberOfSharesAvailable = rs.getLong(5); + long numberOfSharesSold = rs.getLong(6); + Stock stock = new Stock(stockId, companyName, priceCurrent, priceClosing, numberOfSharesAvailable, numberOfSharesSold); + tableStocks.add(stock); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + throw ex; + } + finally + { + try + { + new UtilitiesDatabase().closeDatabaseConnection(con); + // close the resources + if (ps != null) + { + ps.close(); + } + } + catch (SQLException sqle) + { + System.out.println(sqle); + sqle.printStackTrace(); + throw sqle; + } + } + return tableStocks; + } + + @Override + public void create(Stock t) + { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public void edit(Stock t) + { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public void remove(Stock t) + { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public Stock find(Object id) + { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public List findRange(int[] range) + { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public int count() + { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/UtilitiesDatabase.java b/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/UtilitiesDatabase.java new file mode 100644 index 0000000..ac96b51 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/UtilitiesDatabase.java @@ -0,0 +1,103 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package edu.slcc.ajax.bl; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; + +/** + * + * @author asdv5 + */ +public class UtilitiesDatabase +{ + public Connection connection( + String databaseName, + String userName, + String password, + String URL2 + + ) //throws InstantiationException, IllegalAccessException + { +/* + String databaseName = "suppliers_parts_23"; + String userName = "root"; + String password = "root"; + String URL2 = "com.mysql.jdbc.Driver"; + Connection con = null; +*/ + Connection con; + try + {// Load Sun's jdbc driver + Class.forName(URL2).newInstance(); + System.out.println("JDBC Driver loaded!"); + } + catch (Exception e) // driver not found + { + System.err.println("Unable to load database driver"); + System.err.println("Details : " + e); + return null; + } + String ip = "localhost"; //internet connection + String url = "jdbc:mysql://" + ip + ":3306/" + databaseName + "?allowPublicKeyRetrieval=true&useSSL=false"; + try + { + con = DriverManager.getConnection(url, userName, password); + con.setReadOnly(false); + } + catch (Exception e) + { + System.err.println(e.toString()); + return null; + } + System.out.println("connection successfull"); + return con; + } + + + public void closeDatabaseConnection( Connection con) + { + try + { + if (con != null) + { + con.close(); + } + } + catch (SQLException e) + { + System.out.println(e); + e.printStackTrace(); + } + } + + + +public static java.sql.Date stringDateToSqlDate(String sDate) + { + java.util.Date date = null; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + try + { + date = sdf.parse(sDate); + } + catch (ParseException e) + { + e.printStackTrace(); + } + return new java.sql.Date( date.getTime() ); + + } + + +public static java.util.Date stringDateToJavaUtilitiesDate(String sDate) + { + java.sql.Date sqldate = stringDateToSqlDate(sDate); + return new java.util.Date(sqldate.getTime() ); + } +} diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/resources/META-INF/persistence.xml b/Semester 3/Assignments/MP1_Ajax/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..93c708b --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,8 @@ + + + + java:app/nyse + false + + + diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/beans.xml b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..9dfae34 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/glassfish-resources.xml b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/glassfish-resources.xml new file mode 100644 index 0000000..674afe0 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/glassfish-resources.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/glassfish-web.xml b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..673cc06 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/glassfish-web.xml @@ -0,0 +1,25 @@ + + + + + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/web.xml b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..fcfcd54 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + jakarta.faces.PROJECT_STAGE + Development + + + Faces Servlet + jakarta.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + + 30 + + + + faces/index.xhtml + + diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/webapp/index.xhtml b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/index.xhtml new file mode 100644 index 0000000..8fc397d --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/index.xhtml @@ -0,0 +1,49 @@ + + + + + MP1 Ajax + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/webapp/resources/8.zip b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/resources/8.zip new file mode 100644 index 0000000..843fb7b Binary files /dev/null and b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/resources/8.zip differ diff --git a/Semester 3/Assignments/MP1_Ajax/src/main/webapp/resources/css/styles.css b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/resources/css/styles.css new file mode 100644 index 0000000..cc3b207 --- /dev/null +++ b/Semester 3/Assignments/MP1_Ajax/src/main/webapp/resources/css/styles.css @@ -0,0 +1,45 @@ +/* +Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license +Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/CascadeStyleSheet.css to edit this template +*/ +/* + Created on : Jan 13, 2024, 9:50:00 AM + Author : asdv5 +*/ + + +.grandParent{ + margin:0 auto; + float:left; + min-width:100px; + max-width:120px; + height:150px; + position:relative; + border-left: 1px solid #000000; + border-right: 1px solid #000000; + background:#cccccc; + font-size:11px; + cursor:pointer; +} +.theColumn{ + width:100%; + + padding: 20px; + background-color: blue; +} + + +.elementsOfTheColumn{ + width:60%; + margin-left: 10px; + display:inline-table; + position:relative; +} + +.elementsOfTheColumnButton{ + width:30%; + margin-left: 10px; + display:inline-table; + position:relative; +} + diff --git a/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/Factorial.java b/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/Factorial.java new file mode 100644 index 0000000..60c864a --- /dev/null +++ b/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/Factorial.java @@ -0,0 +1,44 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package edu.slcc.asdv.caleb.maxtask; + +import java.math.BigInteger; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.RecursiveTask; + +/** + * + * @author caleb + */ +public class Factorial extends RecursiveTask +{ + final int n; + + Factorial(int n) + { + this.n = n; + } + + @Override + protected Integer compute() + { + if (n == 1 || n <= 1) + { + return n; + } + Factorial fact = new Factorial(n - 1); + fact.fork(); + + return n * fact.join(); + } + + public static void main(String[] args) + { + RecursiveTask task = new Factorial(4); + ForkJoinPool pool = new ForkJoinPool(); + int fact = pool.invoke(task); + System.out.println(fact); + } +} diff --git a/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/FactorialBig.java b/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/FactorialBig.java new file mode 100644 index 0000000..d5b087e --- /dev/null +++ b/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/FactorialBig.java @@ -0,0 +1,58 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package edu.slcc.asdv.caleb.maxtask; + +/** + * + * @author caleb + */ +import java.math.BigInteger; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.RecursiveTask; + +public class FactorialBig extends RecursiveTask +{ + final int THRESHOLD = 50; + public static void main(String[] args) + { + RecursiveTask task = new FactorialBig( new BigInteger( "1060")); + ForkJoinPool pool = new ForkJoinPool(); + BigInteger fact = pool.invoke(task); + System.out.println(fact); + } + final BigInteger n; + + FactorialBig(BigInteger n) + { + this.n = n; + } + + @Override + protected BigInteger compute() + { + if (this.n.compareTo(new BigInteger(String.valueOf(THRESHOLD))) < 0) + { + if (n == BigInteger.ONE || n == BigInteger.ZERO) + return BigInteger.ONE; + long fact = 1; + //compare factorial with loop + for (int i = 2; i < THRESHOLD; ++i) + { + fact *= i; + } + return new BigInteger(String.valueOf(fact)); + } + else { + //compute factorial in parallel + FactorialBig factBig = new FactorialBig(n.subtract(BigInteger.ONE)); + factBig.fork(); + + return n.multiply(factBig.join()); + } + } +} + + + diff --git a/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/Fibonacci.java b/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/Fibonacci.java new file mode 100644 index 0000000..d7941be --- /dev/null +++ b/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/Fibonacci.java @@ -0,0 +1,50 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package edu.slcc.asdv.caleb.maxtask; + +/** + * + * @author caleb + */ +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.RecursiveTask; + +public class Fibonacci extends RecursiveTask +{ + + final int n; + + Fibonacci(int n) + { + this.n = n; + } + + @Override + protected Integer compute() + { + if (n <= 1) + { + return n; + } + Fibonacci f1 = new Fibonacci(n - 1); + f1.fork(); + Fibonacci f2 = new Fibonacci(n - 2); + return f2.compute() + f1.join(); + } + public static void main(String[] args) + { + RecursiveTask task = new Fibonacci(8); + ForkJoinPool pool = new ForkJoinPool(); + int fib = pool.invoke(task); + System.out.println(fib); + } +} + +class Test +{ + + +} + diff --git a/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/ParallelMax.java b/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/ParallelMax.java index 101efe4..f4e02d9 100644 --- a/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/ParallelMax.java +++ b/Semester 3/Assignments/MaxTask/src/main/java/edu/slcc/asdv/caleb/maxtask/ParallelMax.java @@ -14,7 +14,7 @@ public class ParallelMax public static void main(String[] args) { // Create a list - final int N = 20; + final int N = 999999999; int[] list = new int[N]; for (int i = 0; i < list.length; i++) list[i] = i; @@ -75,21 +75,21 @@ public class ParallelMax for (int i = low; i < high; i++) if (list[i] > max) max = list[i]; - return new Integer(max); + return max; } else { int mid = (low + high) / 2; RecursiveTask left = new MaxTask(list, low, mid); - System.out.println("left: " + low +", " + high); + //System.out.println("left: " + low +", " + high); RecursiveTask right = new MaxTask(list, mid+1, high); - System.out.println("right: " + (mid + 1) +", " + high); - System.out.println("fork right"); + //System.out.println("right: " + (mid + 1) +", " + high); + //System.out.println("fork right"); right.fork(); - System.out.println("fork left"); + //System.out.println("fork left"); left.fork(); - return new Integer(Math.max( left.join().intValue(), - right.join().intValue()) + return Math.max( left.join().intValue(), + right.join().intValue() ); } } diff --git a/Semester 3/Assignments/nyse.sql b/Semester 3/Assignments/nyse.sql new file mode 100644 index 0000000..3ff7325 --- /dev/null +++ b/Semester 3/Assignments/nyse.sql @@ -0,0 +1,106 @@ +-- phpMyAdmin SQL Dump +-- version 5.2.0 +-- https://www.phpmyadmin.net/ +-- +-- Host: localhost:8889 +-- Generation Time: Feb 20, 2024 at 06:27 PM +-- Server version: 5.7.39 +-- PHP Version: 7.4.33 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `nyse` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `stock` +-- + +CREATE TABLE `stock` ( + `stock_id` varchar(4) NOT NULL, + `company_name` varchar(100) NOT NULL, + `price_current` double NOT NULL, + `price_closing` double NOT NULL, + `number_of_shares_available` bigint(20) NOT NULL, + `number_of_shares_sold` bigint(20) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `stock` +-- + +INSERT INTO `stock` (`stock_id`, `company_name`, `price_current`, `price_closing`, `number_of_shares_available`, `number_of_shares_sold`) VALUES +('PLCE', 'Children\'s Place, Inc.', 14.515, 13.515, 10000000, 5000000); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `stock_holder` +-- + +CREATE TABLE `stock_holder` ( + `stock_holder_id` int(11) NOT NULL, + `name` varchar(50) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `transactions` +-- + +CREATE TABLE `transactions` ( + `stock_holder_id` int(11) NOT NULL, + `stock_id` varchar(4) NOT NULL, + `qty` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `stock` +-- +ALTER TABLE `stock` + ADD PRIMARY KEY (`stock_id`); + +-- +-- Indexes for table `stock_holder` +-- +ALTER TABLE `stock_holder` + ADD PRIMARY KEY (`stock_holder_id`); + +-- +-- Indexes for table `transactions` +-- +ALTER TABLE `transactions` + ADD PRIMARY KEY (`stock_holder_id`,`stock_id`), + ADD KEY `stock_id` (`stock_id`); + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `transactions` +-- +ALTER TABLE `transactions` + ADD CONSTRAINT `transactions_ibfk_1` FOREIGN KEY (`stock_id`) REFERENCES `stock` (`stock_id`) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT `transactions_ibfk_2` FOREIGN KEY (`stock_holder_id`) REFERENCES `stock_holder` (`stock_holder_id`) ON DELETE CASCADE ON UPDATE CASCADE; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;