Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jaysan1292/COMP2121-Assignment-2
base: 36bb9ee633
...
head fork: jaysan1292/COMP2121-Assignment-2
compare: d3490616a5
  • 5 commits
  • 19 files changed
  • 0 commit comments
  • 1 contributor
View
4 .gitignore
@@ -1,5 +1,5 @@
-build*
-nbproject*
+build/*
+nbproject/*
*.class
View
BIN  build/classes/com/assign2/Main.class
Binary file not shown
View
BIN  build/classes/com/assign2/business/Category.class
Binary file not shown
View
BIN  build/classes/com/assign2/business/Customer.class
Binary file not shown
View
BIN  build/classes/com/assign2/business/Item.class
Binary file not shown
View
BIN  build/classes/com/assign2/business/Order.class
Binary file not shown
View
BIN  build/classes/com/assign2/business/OrderLine.class
Binary file not shown
View
9 src/com/assign2/Main.java
@@ -4,6 +4,8 @@
*/
package com.assign2;
+import com.assign2.data.CustomerAccess;
+
/**
*
* @author Jason Recillo
@@ -13,6 +15,11 @@
* @param args the command line arguments
*/
public static void main(String[] args) {
- //
+ try {
+ CustomerAccess.updateCustomer(14, CustomerAccess.FIRST_NAME, "newname");
+ } catch (Exception ex) {
+ Utils.log_error(ex.getMessage());
+ ex.printStackTrace();
+ }
}
}
View
40 src/com/assign2/business/Category.java
@@ -11,6 +11,42 @@
public class Category {
private int categoryId;
private String categoryName;
- private int parentCategoryId;
+ private Category parentCategory;
+
+ /**
+ * @return the categoryId
+ */
+ public int getCategoryId() {
+ return categoryId;
+ }
+
+ /**
+ * @param categoryId the categoryId to set
+ */
+ public void setCategoryId(int categoryId) {
+ this.categoryId = categoryId;
+ }
+
+ /**
+ * @return the categoryName
+ */
+ public String getCategoryName() {
+ return categoryName;
+ }
+
+ /**
+ * @param categoryName the categoryName to set
+ */
+ public void setCategoryName(String categoryName) {
+ this.categoryName = categoryName;
+ }
+
+ public Category getParentCategory() {
+ return parentCategory;
+ }
+
+ public void setParentCategory(Category parentCategory) {
+ this.parentCategory = parentCategory;
+ }
-}
+}
View
2  src/com/assign2/business/Customer.java
@@ -4,8 +4,6 @@
*/
package com.assign2.business;
-import com.assign2.data.CustomerAccess;
-import java.sql.SQLException;
import java.util.regex.*;
/**
View
106 src/com/assign2/business/Item.java
@@ -4,6 +4,8 @@
*/
package com.assign2.business;
+import java.awt.Image;
+
/**
*
* @author janjong
@@ -11,11 +13,107 @@
public class Item {
private int itemId;
private String name;
- private String category;
+ private Category category;
private double price;
private String description;
- private String Image;
+ private Image image;
private int qtyInStock;
-
-
+
+ /**
+ * @return the itemId
+ */
+ public int getItemId() {
+ return itemId;
+ }
+
+ /**
+ * @param itemId the itemId to set
+ */
+ public void setItemId(int itemId) {
+ this.itemId = itemId;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the category
+ */
+ public Category getCategory() {
+ return category;
+ }
+
+ /**
+ * @param category the category to set
+ */
+ public void setCategory(Category category) {
+ this.category = category;
+ }
+
+ /**
+ * @return the price
+ */
+ public double getPrice() {
+ return price;
+ }
+
+ /**
+ * @param price the price to set
+ */
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ /**
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @param description the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * @return the Image
+ */
+ public Image getImage() {
+ return image;
+ }
+
+ /**
+ * @param image the Image to set
+ */
+ public void setImage(Image image) {
+ this.image = image;
+ }
+
+ /**
+ * @return the qtyInStock
+ */
+ public int getQtyInStock() {
+ return qtyInStock;
+ }
+
+ /**
+ * @param qtyInStock the qtyInStock to set
+ */
+ public void setQtyInStock(int qtyInStock) {
+ this.qtyInStock = qtyInStock;
+ }
}
View
51 src/com/assign2/business/Order.java
@@ -4,6 +4,8 @@
*/
package com.assign2.business;
+import java.util.Date;
+
/**
*
* @author janjong
@@ -11,5 +13,50 @@
public class Order {
private int orderId;
private int customerId;
- private String date;
-}
+ private Date date;
+
+ public Order() {
+ }
+
+ /**
+ * @return the orderId
+ */
+ public int getOrderId() {
+ return orderId;
+ }
+
+ /**
+ * @param orderId the orderId to set
+ */
+ public void setOrderId(int orderId) {
+ this.orderId = orderId;
+ }
+
+ /**
+ * @return the customerId
+ */
+ public int getCustomerId() {
+ return customerId;
+ }
+
+ /**
+ * @param customerId the customerId to set
+ */
+ public void setCustomerId(int customerId) {
+ this.customerId = customerId;
+ }
+
+ /**
+ * @return the date
+ */
+ public Date getDate() {
+ return date;
+ }
+
+ /**
+ * @param date the date to set
+ */
+ public void setDate(Date date) {
+ this.date = date;
+ }
+}
View
64 src/com/assign2/business/OrderLine.java
@@ -13,4 +13,66 @@
private int itemId;
private int quantity;
private double total;
-}
+
+ public OrderLine(int oId, int iID, int qty, double _total) {
+ Order orderObj = new Order();
+ Item itemObj = new Item();
+ orderId = orderObj.getOrderId();
+ itemId = itemObj.getItemId();
+ quantity = qty;
+ total = _total;
+ }
+
+ public int getOrderId() {
+ return orderId;
+ }
+
+ /**
+ * @param orderId the orderId to set
+ */
+ public void setOrderId(int orderId) {
+ this.orderId = orderId;
+ }
+
+ /**
+ * @return the itemId
+ */
+ public int getItemId() {
+ return itemId;
+ }
+
+ /**
+ * @param itemId the itemId to set
+ */
+ public void setItemId(int itemId) {
+ this.itemId = itemId;
+ }
+
+ /**
+ * @return the quantity
+ */
+ public int getQuantity() {
+ return quantity;
+ }
+
+ /**
+ * @param quantity the quantity to set
+ */
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+
+ /**
+ * @return the total
+ */
+ public double getTotal() {
+ return total;
+ }
+
+ /**
+ * @param total the total to set
+ */
+ public void setTotal(double total) {
+ this.total = total;
+ }
+}
View
61 src/com/assign2/data/CategoryAccess.java
@@ -0,0 +1,61 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.assign2.data;
+
+import com.assign2.Utils;
+import com.assign2.business.Category;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Date;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+/**
+ *
+ * @author Jason Recillo
+ */
+public class CategoryAccess extends CommonAccess {
+ public static final String CATEGORY_ID="category_id";
+ public static final String CATEGORY_NAME="category_name";
+ public static final String PARENT_CATEGORY_ID="parent_category_id";
+
+ public void addNewCategory(int categoryId, String categoryName, Category parentCategory){
+ throw new NotImplementedException();
+ }
+
+ public void deleteCategory(int categoryId){
+ throw new NotImplementedException();
+ }
+
+ public static Category findCategory(String column, String value) throws SQLException {
+
+ Connection conn = dbConnect();
+ Statement sqlStatement = conn.createStatement();
+
+ String query = String.format("SELECT * FROM category WHERE %s='%s';", column, value);
+ Utils.log_info("Executing SQL query: %s", query);
+ ResultSet resultSet = sqlStatement.executeQuery(query);
+
+ if (!(resultSet.first())) {
+ throw new SQLException("Result set returned no data.");
+ }
+
+ Category category = new Category();
+ category.setCategoryId(resultSet.getInt(CATEGORY_ID));
+ category.setCategoryName(resultSet.getString(CATEGORY_NAME));
+ try {
+ category.setParentCategory(findCategory(CATEGORY_ID, resultSet.getString(PARENT_CATEGORY_ID)));
+ } catch (SQLException ex) {
+ category.setParentCategory(null);
+ }
+
+ return category;
+ }
+
+ public void updateCategory(int categoryId, String column, String newValue){
+ throw new NotImplementedException();
+ }
+}
View
13 src/com/assign2/data/CommonAccess.java
@@ -14,19 +14,26 @@
* @author Jason Recillo
*/
public abstract class CommonAccess {
+ static Connection connection = null;
+
public CommonAccess() {
}
- public static Connection dbConnect() {
+ private static void _dbConnect() {
try {
+ Utils.log_info("Connecting to database...");
String host = "jdbc:mysql://jaysan1292.com:3306/jrecillo_school";
String user = "jrecillo";
String pass = "parallelline";
Connection conn = DriverManager.getConnection(host, user, pass);
- return conn;
+ connection = conn;
} catch (SQLException ex) {
Utils.log_error(ex.getMessage());
- return null;
}
}
+
+ public static Connection dbConnect(){
+ if(connection == null) _dbConnect();
+ return connection;
+ }
}
View
33 src/com/assign2/data/CustomerAccess.java
@@ -10,7 +10,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
/**
*
@@ -36,7 +35,6 @@ private CustomerAccess() {
* @throws SQLException if the specified customer was not found in the database.
*/
public static Customer findCustomer(String column, String value) throws SQLException {
- Utils.log_info("Connecting to database...");
Connection conn = dbConnect();
Statement sqlStatement = conn.createStatement();
@@ -49,11 +47,11 @@ public static Customer findCustomer(String column, String value) throws SQLExcep
}
Customer customer = new Customer();
- customer.setCustomerId(resultSet.getInt("customer_id"));
- customer.setFirstName(resultSet.getString("first_name"));
- customer.setLastName(resultSet.getString("last_name"));
- customer.setAddress(resultSet.getString("address"));
- customer.setPhoneNumber(resultSet.getString("phone_number"));
+ customer.setCustomerId(resultSet.getInt(CUSTOMER_ID));
+ customer.setFirstName(resultSet.getString(FIRST_NAME));
+ customer.setLastName(resultSet.getString(LAST_NAME));
+ customer.setAddress(resultSet.getString(ADDRESS));
+ customer.setPhoneNumber(resultSet.getString(PHONE_NUMBER));
Utils.log_info("Returned customer information:\n\t\tFirst name: %s\n\t\tLast name: %s", customer.getFirstName(), customer.getLastName());
@@ -61,7 +59,6 @@ public static Customer findCustomer(String column, String value) throws SQLExcep
}
public static void addNewCustomer(String firstName, String lastName, String address, String phoneNumber) throws SQLException {
- Utils.log_info("Connecting to database...");
Connection conn = dbConnect();
Statement sqlStatement = conn.createStatement();
@@ -73,23 +70,23 @@ public static void addNewCustomer(String firstName, String lastName, String addr
sqlStatement.executeUpdate(query);
}
- public static boolean deleteCustomer(int customerId) throws SQLException {
- Utils.log_info("Connecting to database...");
+ public static void deleteCustomer(int customerId) throws SQLException {
Connection conn = dbConnect();
Statement sqlStatement = conn.createStatement();
String query = String.format("DELETE FROM customer WHERE customer_id='%s';", customerId);
Utils.log_info("Executing SQL query: %s", query);
- try {
- sqlStatement.executeUpdate(query);
- } catch (SQLException ex) {
- return false;
- }
- return true;
+ sqlStatement.executeUpdate(query);
}
- public static void updateCustomer(String column, String customerId, String newValue) throws SQLException {
- throw new NotImplementedException();
+ public static void updateCustomer(int customerId, String column, String newValue) throws SQLException {
+ Connection conn = dbConnect();
+ Statement sqlStatement = conn.createStatement();
+
+ String query = String.format("UPDATE customer SET %s='%s' WHERE customer_id=%s", column, newValue, customerId);
+ Utils.log_info("Executing SQL query: %s", query);
+
+ sqlStatement.executeUpdate(query);
}
}
View
23 src/com/assign2/data/ItemAccess.java
@@ -5,11 +5,14 @@
package com.assign2.data;
import com.assign2.Utils;
+import com.assign2.business.Category;
import com.assign2.business.Item;
+import java.awt.Image;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
/**
*
@@ -23,8 +26,7 @@
public static final String DESCRIPTION = "price";
public static final String IMAGE = "image";
- public Item findItem(String column, String value) throws SQLException {
- Utils.log_info("Connecting to database...");
+ public static Item findItem(String column, String value) throws SQLException {
Connection conn = dbConnect();
Statement sqlStatement = conn.createStatement();
@@ -37,10 +39,25 @@ public Item findItem(String column, String value) throws SQLException {
}
Item item = new Item();
+ item.setItemId(resultSet.getInt(ITEM_ID));
+ item.setName(resultSet.getString(NAME));
+ item.setCategory(CategoryAccess.findCategory(CategoryAccess.CATEGORY_ID, resultSet.getString(CATEGORY)));
+ item.setPrice(resultSet.getDouble(PRICE));
+ item.setDescription(resultSet.getString(DESCRIPTION));
+ // TODO: retrieve image from database and set it in code
return item;
}
- public void addNewItem() {
+ public void addNewItem(int itemId, String name, Category category,double price,String description,Image image, int qtyInStock){
+ throw new NotImplementedException();
+ }
+
+ public void deleteItem(int itemId){
+ throw new NotImplementedException();
+ }
+
+ public void updateItem(int itemId, String column, String value){
+ throw new NotImplementedException();
}
}
View
21 src/com/assign2/data/OrderAccess.java
@@ -4,10 +4,31 @@
*/
package com.assign2.data;
+import java.util.Date;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
/**
*
* @author Jason Recillo
*/
public class OrderAccess extends CommonAccess {
public static final String ORDER_ID = "order_id";
+ public static final String CUSTOMER_ID = "customer_id";
+ public static final String ORDER_DATE = "order_date";
+
+ public void addNewOrder(int orderId, int customerId, Date date){
+ throw new NotImplementedException();
+ }
+
+ public void deleteOrder(int orderId){
+ throw new NotImplementedException();
+ }
+
+ public void findOrder(String column, String value){
+ throw new NotImplementedException();
+ }
+
+ public void updateOrder(int orderId, String column, String newValue){
+ throw new NotImplementedException();
+ }
}
View
34 src/com/assign2/data/OrderLineAccess.java
@@ -0,0 +1,34 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.assign2.data;
+
+import com.assign2.business.OrderLine;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+/**
+ *
+ * @author Jason Recillo
+ */
+public class OrderLineAccess extends CommonAccess {
+ public static final String ORDER_ID="order_id";
+ public static final String ITEM_ID="item_id";
+ public static final String QUANTITY="quantity";
+ public static final String TOTAL="total";
+
+ public static void addNewOrderLine(int orderId, int itemId, int quantity, double total){
+ throw new NotImplementedException();
+ }
+ public static void deleteOrderLine(int orderLineId){
+ throw new NotImplementedException();
+ }
+
+ public static OrderLine findOrderLine(String column, String value){
+ throw new NotImplementedException();
+ }
+
+ public static void updateOrderLine(int orderLineId, String column, String newValue){
+ throw new NotImplementedException();
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.