Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wp20ws_DragandDropToolSSH
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
softwarepraktikum
wp20ws_DragandDropToolSSH
Merge requests
!17
Resolve "Implement database operations"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Implement database operations"
19-implement-database-operations
into
master
Overview
5
Commits
3
Pipelines
0
Changes
13
All threads resolved!
Hide all comments
Merged
Ghost User
requested to merge
19-implement-database-operations
into
master
4 years ago
Overview
5
Commits
3
Pipelines
0
Changes
13
All threads resolved!
Hide all comments
Expand
Closes
#19 (closed)
Edited
4 years ago
by
Ghost User
0
0
Merge request reports
Compare
master
version 1
003e5b8b
4 years ago
master (base)
and
latest version
latest version
7e2a51c1
3 commits,
4 years ago
version 1
003e5b8b
1 commit,
4 years ago
13 files
+
272
−
269
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
13
Search (e.g. *.vue) (Ctrl+P)
development/database/src/main/java/de/uniwue/swp/sshtool/database/DBAccess.java deleted
100644 → 0
+
0
−
163
Options
package
de.uniwue.swp.sshtool.database
;
import
com.zaxxer.hikari.HikariDataSource
;
import
de.uniwue.swp.sshtool.database.utils.FileStatus
;
import
de.uniwue.swp.sshtool.database.utils.SessionStatus
;
import
de.uniwue.swp.sshtool.database.utils.TransactionType
;
import
javax.sql.DataSource
;
import
java.sql.*
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Klasse gerade nur für Kopieren im Gebrauch, danach gelöscht
*/
public
class
DBAccess
{
/*
private final DataSource dataSource;
private static DBAccess instance;
private DBAccess(DataSource dataSource) {
this.dataSource = dataSource;
}
public static DBAccess login(String username, String password, String url) {
if(instance==null){
HikariDataSource ds=new HikariDataSource();
ds.setJdbcUrl(url);
ds.setUsername(username);
ds.setPassword(password);
return new DBAccess(ds);
}
return instance;
}
@Override
public List<File> getFilesInTransaction(int transaction_id) throws SQLException {
Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement("");
statement.setInt(1, transaction_id);
ResultSet rs = statement.executeQuery();
ArrayList<File> files = new ArrayList<>();
while (rs.next()) {
int id = rs.getInt("file_id");
String localPath = rs.getString("localPath");
String remotePath = rs.getString("remotePath");
FileStatus status = FileStatus.values()[rs.getInt("status")];
files.add(new File(id, localPath, remotePath, status, transaction_id));
}
return files;
}
@Override
public List<Transaction> getIncompleteTransactions(String username) throws SQLException {
Connection connection = dataSource.getConnection();
PreparedStatement stmt = connection.prepareStatement("");
stmt.setString(1, username);
ResultSet rs;
rs = stmt.executeQuery();
ArrayList<Transaction> transactions = new ArrayList<>();
while (rs.next()) {
int id = rs.getInt("transaction_id");
LocalDateTime start = rs.getTimestamp("start_timestamp").toLocalDateTime();
LocalDateTime end = rs.getTimestamp("end_timestamp").toLocalDateTime();
String user = rs.getString("user");
TransactionType type = TransactionType.values()[rs.getInt("type")];
transactions.add(new Transaction(id, start, end, user, type, getFilesInTransaction(id)));
}
return transactions;
}
@Override
public void cancelTransaction(int transaction_id) throws SQLException {
Connection connection = dataSource.getConnection();
PreparedStatement st = connection.prepareStatement("");
st.setInt(1, FileStatus.CANCELLED.i);
st.setInt(2, transaction_id);
st.executeUpdate();
}
@Override
public void startTransaction(Transaction transaction) throws SQLException {
Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement("");
statement.setInt(1, transaction.getTransactionType().i);
statement.setTimestamp(2, Timestamp.valueOf(transaction.getStarting_time()));
statement.setTimestamp(3, Timestamp.valueOf(transaction.getFinishing_time()));
statement.setString(4, transaction.getUser());
statement.executeUpdate();
statement = connection.prepareStatement("select last_insert_id()");
ResultSet rs = statement.executeQuery();
rs.next();
int transaction_id = rs.getInt("transaction_id");
for (File file : transaction.getFiles()) {
statement = connection.prepareStatement("");
statement.setString(1, file.getLocalPath());
statement.setString(2, file.getRemotePath());
statement.setInt(3, file.getFileStatus().i);
statement.setInt(4, transaction_id);
statement.executeUpdate();
}
}
@Override
public void updateFilesStatus(List<File> files) throws SQLException {
Connection connection = dataSource.getConnection();
for (File file : files) {
PreparedStatement st = connection.prepareStatement("");
st.setInt(1, FileStatus.FINISHED.i);
st.setInt(2, file.getFile_id());
st.executeUpdate();
}
}
@Override
public List<Session> getSessions() throws SQLException {
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("");
ArrayList<Session> sessions = new ArrayList<>();
while (rs.next()) {
int id = rs.getInt("session_id");
LocalDateTime start = rs.getTimestamp("start_timestamp").toLocalDateTime();
LocalDateTime end = rs.getTimestamp("end_timestamp").toLocalDateTime();
String user = rs.getString("user");
String ssh_hostname = rs.getString("ssh_hostname");
int ssh_port = rs.getInt("ssh_port");
SessionStatus status = SessionStatus.values()[rs.getInt("status")];
sessions.add(new Session(id, start, end, user, ssh_hostname, ssh_port, status));
}
return sessions;
}
@Override
public List<Transaction> getTransactionForSession(int sessionId) throws SQLException {
Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement("");
statement.setInt(1, sessionId);
ResultSet rs = statement.executeQuery();
ArrayList<Transaction> transactions = new ArrayList<>();
while (rs.next()) {
int id = rs.getInt("transaction_id");
TransactionType type = TransactionType.values()[rs.getInt("type")];
LocalDateTime start = rs.getTimestamp("start_timestamp").toLocalDateTime();
LocalDateTime end = rs.getTimestamp("end_timestamp").toLocalDateTime();
String user = rs.getString("user");
transactions.add(new Transaction(id, start, end, user, type, getFilesInTransaction(id)));
}
return transactions;
}
@Override
public List<Session> getSessionsForTransaction(int transactionId) {
throw new UnsupportedOperationException();
}*/
}
Loading