Skip to content

Commit c331d1f

Browse files
committed
initial framework
0 parents  commit c331d1f

11 files changed

+481
-0
lines changed

.gitignore

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Created by .gitignore support plugin (hsz.mobi)
2+
### Java template
3+
*.class
4+
5+
# Mobile Tools for Java (J2ME)
6+
.mtj.tmp/
7+
8+
# Package Files #
9+
*.jar
10+
*.war
11+
*.ear
12+
13+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
14+
hs_err_pid*
15+
16+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
17+
18+
*.iml
19+
20+
## Directory-based project format:
21+
.idea/
22+
# if you remove the above rule, at least ignore the following:
23+
24+
# User-specific stuff:
25+
# .idea/workspace.xml
26+
# .idea/tasks.xml
27+
# .idea/dictionaries
28+
29+
# Sensitive or high-churn files:
30+
# .idea/dataSources.ids
31+
# .idea/dataSources.xml
32+
# .idea/sqlDataSources.xml
33+
# .idea/dynamic.xml
34+
# .idea/uiDesigner.xml
35+
36+
# Gradle:
37+
# .idea/gradle.xml
38+
# .idea/libraries
39+
40+
# Mongo Explorer plugin:
41+
# .idea/mongoSettings.xml
42+
43+
## File-based project format:
44+
*.ipr
45+
*.iws
46+
47+
## Plugin-specific files:
48+
49+
# IntelliJ
50+
out/
51+
52+
# mpeltonen/sbt-idea plugin
53+
.idea_modules/
54+
55+
# JIRA plugin
56+
atlassian-ide-plugin.xml
57+
58+
# Crashlytics plugin (for Android Studio and IntelliJ)
59+
com_crashlytics_export_strings.xml
60+
crashlytics.properties
61+
crashlytics-build.properties

keymanager_analysis.uml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Diagram>
3+
<ID>JAVA</ID>
4+
<OriginalElement />
5+
<nodes />
6+
<notes />
7+
<edges />
8+
<settings layout="Hierarchic Group" zoom="1.0" x="0.0" y="0.0" />
9+
<SelectedNodes />
10+
<Categories />
11+
<SCOPE>All</SCOPE>
12+
</Diagram>
13+

pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>nl.bascoder.keymanager</groupId>
8+
<artifactId>licenseKey-manager</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package nl.bascoder.keymanager;
2+
3+
/**
4+
* @author Bas van Marwijk
5+
* @since 9-11-14
6+
* @version 1.0 - creation
7+
*/
8+
public class Application {
9+
10+
public static void main(String args) {
11+
}
12+
}
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package nl.bascoder.keymanager;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.SQLException;
6+
import java.util.logging.Logger;
7+
8+
/**
9+
* @author Bas van Marwijk
10+
* @since 9-11-14
11+
* @version 1.0 - creation
12+
*/
13+
public class DatabaseManager {
14+
private static DatabaseManager instance;
15+
private static final String DATABASE_CONNECTION_DRIVER = "org.sqlite.JDBC";
16+
private static final String CONNECTION_URL = "jdbc:sqlite:keys.db";
17+
18+
private Connection connection;
19+
20+
private DatabaseManager() throws ExceptionInInitializerError{
21+
try {
22+
Class.forName(DATABASE_CONNECTION_DRIVER);
23+
connection = DriverManager.getConnection(CONNECTION_URL);
24+
} catch (ClassNotFoundException e) {
25+
Logger.getGlobal().severe("Database connection driver not found: "
26+
+ DATABASE_CONNECTION_DRIVER);
27+
throw new ExceptionInInitializerError(e);
28+
} catch (SQLException e) {
29+
//TODO filter error for database not existing
30+
Logger.getGlobal().severe("Could not connect with database: "
31+
+ CONNECTION_URL);
32+
}
33+
}
34+
35+
public static DatabaseManager getInstance() {
36+
if(instance == null){
37+
instance = new DatabaseManager();
38+
}
39+
return instance;
40+
}
41+
42+
public synchronized Connection getConnection() {
43+
return connection;
44+
}
45+
46+
public synchronized void closeConnection() {
47+
try {
48+
connection.close();
49+
instance = null;
50+
} catch (SQLException e) {
51+
Logger.getGlobal().severe("Could not close database");
52+
}
53+
}
54+
}
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package nl.bascoder.keymanager;
2+
3+
import java.sql.ResultSetMetaData;
4+
import java.sql.SQLException;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import java.util.logging.Level;
8+
import java.util.logging.Logger;
9+
10+
import javax.swing.SwingWorker;
11+
import javax.swing.table.AbstractTableModel;
12+
13+
/**
14+
* TableModel bound to database.
15+
*
16+
*
17+
*
18+
* @author Bas van Marwijk
19+
* @since 9-11-14
20+
* @version 1.0 - creation
21+
*/
22+
public class DatabaseTableModel extends AbstractTableModel {
23+
24+
private DatabaseManager dbManager;
25+
private ResultSetMetaData resultSetMetaData;
26+
private final List<Row> rows;
27+
28+
public DatabaseTableModel() {
29+
this.dbManager = DatabaseManager.getInstance();
30+
rows = new ArrayList<>();
31+
32+
initResultSet();
33+
34+
new SwingWorker<Void, Row>() {
35+
public Void doInBackground() {
36+
// TODO: Process ResultSet and create Rows. Call publish() for every N rows created.
37+
return null;
38+
}
39+
40+
protected void process(Row... chunks) {
41+
// TODO: Add to ResultSetTableModel List and fire TableEvent.
42+
}
43+
}.execute();
44+
}
45+
46+
private void initResultSet() {
47+
dbManager.getConnection();
48+
}
49+
50+
/**
51+
* Returns the number of rows in the model. A
52+
* <code>JTable</code> uses this method to determine how many rows it
53+
* should display. This method should be quick, as it
54+
* is called frequently during rendering.
55+
*
56+
* @return the number of rows in the model
57+
* @see #getColumnCount
58+
*/
59+
@Override
60+
public int getRowCount() {
61+
return rows.size();
62+
}
63+
64+
/**
65+
* Returns the number of columns in the model. A
66+
* <code>JTable</code> uses this method to determine how many columns it
67+
* should create and display by default.
68+
*
69+
* @return the number of columns in the model
70+
* @see #getRowCount
71+
*/
72+
@Override
73+
public int getColumnCount() {
74+
try {
75+
return resultSetMetaData.getColumnCount();
76+
} catch (SQLException e) {
77+
Logger.getGlobal().log(Level.SEVERE, e.getMessage() + " " + e.getErrorCode(), e);
78+
return 0;
79+
}
80+
}
81+
82+
/**
83+
* Returns the name of the column at <code>columnIndex</code>. This is used
84+
* to initialize the table's column header name. Note: this name does
85+
* not need to be unique; two columns in a table can have the same name.
86+
*
87+
* @param columnIndex the index of the column
88+
* @return the name of the column
89+
*/
90+
@Override
91+
public String getColumnName(int columnIndex) {
92+
try {
93+
return resultSetMetaData.getColumnName(columnIndex - 1);
94+
} catch (SQLException e) {
95+
Logger.getGlobal().log(Level.SEVERE, e.getMessage() + " " + e.getErrorCode(), e);
96+
return null;
97+
}
98+
}
99+
100+
/**
101+
* Returns the most specific superclass for all the cell values
102+
* in the column. This is used by the <code>JTable</code> to set up a
103+
* default renderer and editor for the column.
104+
*
105+
* @param columnIndex the index of the column
106+
* @return the common ancestor class of the object values in the model.
107+
*/
108+
@Override
109+
public Class<?> getColumnClass(int columnIndex) {
110+
// TODO return correct class
111+
return Object.class;
112+
}
113+
114+
/**
115+
* Returns true if the cell at <code>rowIndex</code> and
116+
* <code>columnIndex</code>
117+
* is editable. Otherwise, <code>setValueAt</code> on the cell will not
118+
* change the value of that cell.
119+
*
120+
* @param rowIndex the row whose value to be queried
121+
* @param columnIndex the column whose value to be queried
122+
* @return true if the cell is editable
123+
* @see #setValueAt
124+
*/
125+
@Override
126+
public boolean isCellEditable(int rowIndex, int columnIndex) {
127+
// only id is not editable
128+
return columnIndex != 0;
129+
}
130+
131+
/**
132+
* Returns the value for the cell at <code>columnIndex</code> and
133+
* <code>rowIndex</code>.
134+
*
135+
* @param rowIndex the row whose value is to be queried
136+
* @param columnIndex the column whose value is to be queried
137+
* @return the value Object at the specified cell
138+
*/
139+
@Override
140+
public Object getValueAt(int rowIndex, int columnIndex) {
141+
return rows.get(rowIndex)
142+
.getValue(columnIndex);
143+
}
144+
145+
/**
146+
* Internal used row
147+
*/
148+
private class Row {
149+
private final Object[] values;
150+
151+
public Row(Object[] values) {
152+
this.values = values;
153+
}
154+
155+
public int getSize() {
156+
return values.length;
157+
}
158+
159+
public Object getValue(int i) {
160+
return values[i];
161+
}
162+
}
163+
}
164+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package nl.bascoder.keymanager.entity;
2+
3+
/**
4+
* @author Bas van Marwijk
5+
* @since 9-11-14
6+
* @version 1.0 - creation
7+
*/
8+
public class Device {
9+
private long id;
10+
private String name;
11+
private Owner owner;
12+
}
13+

0 commit comments

Comments
 (0)