[07] Fixed package path
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
40
07/src/de/dis2017/data/Article.java
Normal file
40
07/src/de/dis2017/data/Article.java
Normal file
@ -0,0 +1,40 @@
|
||||
package de.dis2017.data;
|
||||
|
||||
public class Article {
|
||||
private int _articleID;
|
||||
private int _productGroupID;
|
||||
private String _name;
|
||||
private float _price;
|
||||
|
||||
public int get_articleID() {
|
||||
return _articleID;
|
||||
}
|
||||
|
||||
public void set_articleID(int articleID) {
|
||||
_articleID = articleID;
|
||||
}
|
||||
|
||||
public int get_productGroupID() {
|
||||
return _productGroupID;
|
||||
}
|
||||
|
||||
public void set_productGroupID(int productGroupID) {
|
||||
_productGroupID = productGroupID;
|
||||
}
|
||||
|
||||
public String get_name() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public void set_name(String name) {
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public float get_price() {
|
||||
return _price;
|
||||
}
|
||||
|
||||
public void set_price(float price) {
|
||||
_price = price;
|
||||
}
|
||||
}
|
||||
53
07/src/de/dis2017/data/Sale.java
Normal file
53
07/src/de/dis2017/data/Sale.java
Normal file
@ -0,0 +1,53 @@
|
||||
package de.dis2017.data;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Sale {
|
||||
private Date _date;
|
||||
private int _shopID;
|
||||
private int _articleID;
|
||||
private int _sold;
|
||||
private int _earnings;
|
||||
|
||||
|
||||
public Date get_date() {
|
||||
return _date;
|
||||
}
|
||||
|
||||
public void set_date(Date date) {
|
||||
_date = date;
|
||||
}
|
||||
|
||||
public int get_shopID() {
|
||||
return _shopID;
|
||||
}
|
||||
|
||||
public void set_shopID(int shopID) {
|
||||
_shopID = shopID;
|
||||
}
|
||||
|
||||
public int get_articleID() {
|
||||
return _articleID;
|
||||
}
|
||||
|
||||
public void set_articleID(int articleID) {
|
||||
_articleID = articleID;
|
||||
}
|
||||
|
||||
public int get_sold() {
|
||||
return _sold;
|
||||
}
|
||||
|
||||
public void set_sold(int sold) {
|
||||
_sold = sold;
|
||||
}
|
||||
|
||||
public int get_earnings() {
|
||||
return _earnings;
|
||||
}
|
||||
|
||||
public void set_earnings(int earnings) {
|
||||
_earnings = earnings;
|
||||
}
|
||||
}
|
||||
31
07/src/de/dis2017/data/Shop.java
Normal file
31
07/src/de/dis2017/data/Shop.java
Normal file
@ -0,0 +1,31 @@
|
||||
package de.dis2017.data;
|
||||
|
||||
public class Shop {
|
||||
private int _shopID;
|
||||
private int _cityID;
|
||||
private String _name;
|
||||
|
||||
public int get_shopID() {
|
||||
return _shopID;
|
||||
}
|
||||
|
||||
public void set_shopID(int shopID) {
|
||||
_shopID = shopID;
|
||||
}
|
||||
|
||||
public int get_cityID() {
|
||||
return _cityID;
|
||||
}
|
||||
|
||||
public void set_cityID(int cityID) {
|
||||
_cityID = cityID;
|
||||
}
|
||||
|
||||
public String get_name() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public void set_name(String name) {
|
||||
_name = name;
|
||||
}
|
||||
}
|
||||
33
07/src/de/dis2017/data/db/CSVScanner.java
Normal file
33
07/src/de/dis2017/data/db/CSVScanner.java
Normal file
@ -0,0 +1,33 @@
|
||||
package de.dis2017.data.db;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CSVScanner {
|
||||
/**
|
||||
* Scans the sales.csv file.
|
||||
* @return a list of csv entries
|
||||
* @throws FileNotFoundException if file doesn't exist
|
||||
*/
|
||||
public List<List<String>> scan() throws FileNotFoundException {
|
||||
List<List<String>> entries = new ArrayList<>();
|
||||
|
||||
Scanner scanner = new Scanner(new File("sales.csv"));
|
||||
while (scanner.hasNextLine()) {
|
||||
List<String> line = new ArrayList<>();
|
||||
String line_str = scanner.nextLine();
|
||||
Scanner line_scanner = new Scanner(line_str);
|
||||
line_scanner.useDelimiter(";");
|
||||
while (line_scanner.hasNext()) {
|
||||
line.add(line_scanner.next());
|
||||
}
|
||||
entries.add(line);
|
||||
}
|
||||
scanner.close();
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
73
07/src/de/dis2017/data/db/DB2ConnectionManager.java
Normal file
73
07/src/de/dis2017/data/db/DB2ConnectionManager.java
Normal file
@ -0,0 +1,73 @@
|
||||
package de.dis2017.data.db;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Singleton for management of database connections
|
||||
*
|
||||
* @author Michael von Riegen
|
||||
* @version April 2009
|
||||
*/
|
||||
class DB2ConnectionManager {
|
||||
|
||||
// instance of Driver Manager
|
||||
private static DB2ConnectionManager _instance = null;
|
||||
|
||||
// DB2 connection
|
||||
private Connection _con;
|
||||
|
||||
/**
|
||||
* Initializes database connection
|
||||
*/
|
||||
private DB2ConnectionManager() {
|
||||
try {
|
||||
// load properties from db2.properties file
|
||||
Properties properties = new Properties();
|
||||
URL url = ClassLoader.getSystemResource("db2.properties");
|
||||
FileInputStream stream = new FileInputStream(new File(url.toURI()));
|
||||
properties.load(stream);
|
||||
stream.close();
|
||||
|
||||
String jdbcUser = properties.getProperty("jdbc_user");
|
||||
String jdbcPass = properties.getProperty("jdbc_pass");
|
||||
String jdbcUrl = properties.getProperty("jdbc_url");
|
||||
|
||||
// created connection to DB2 database
|
||||
Class.forName("com.ibm.db2.jcc.DB2Driver");
|
||||
_con = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass);
|
||||
|
||||
} catch (IOException | ClassNotFoundException | SQLException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the instance of the connection manager
|
||||
*
|
||||
* @return DB2ConnectionManager
|
||||
*/
|
||||
static DB2ConnectionManager getInstance() {
|
||||
if (_instance == null) {
|
||||
_instance = new DB2ConnectionManager();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the connection to the DB2 database
|
||||
*
|
||||
* @return Connection
|
||||
*/
|
||||
Connection getConnection() {
|
||||
return _con;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user