-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunM.java
More file actions
115 lines (92 loc) · 3.96 KB
/
funM.java
File metadata and controls
115 lines (92 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main;
import java.sql.*;
import java.util.List;
import java.util.Map;
import main.App.*;
//this class mainly provides functionality of all the adding of data related to the media
// into the MediaArchive database
public class funM {
//this method adds media file to the database using the fileLocation
FileIdentifier addMediaFile( String fileLocation ){
try {
DbConnection db = new DbConnection();
Connection conn= db.createDBConnection();
Statement st= conn.createStatement();
//this query adds media file row to the database using the fileLocation
st.execute("insert into MediaArchive (Name )values('"+fileLocation+"')");
ResultSet rs= st.executeQuery("SELECT MediaId FROM MediaArchive WHERE MediaId=(SELECT max(MediaId) FROM MediaArchive)");
rs.next();
//creation of new object from the resultset
FileIdentifier fi = new FileIdentifier(Integer.parseInt(rs.getString(1)));
conn.close();
return fi;
} catch (Exception e) {
return null;
}
}
//this function is used to delete all the current data from the database
void DeleteRows() throws SQLException{
DbConnection db = new DbConnection();
Connection conn= db.createDBConnection();
Statement st= conn.createStatement();
//delete queries//
st.execute("Delete from MediaArchive");
}
//this function records media file attributes
Boolean recordMediaAttributes( FileIdentifier fileIdentifier, Map<String, String> attributes ){
try {
int name= fileIdentifier.FileId;
DbConnection db = new DbConnection();
Connection conn= db.createDBConnection();
//the data will be taken from the map
for(Map.Entry<String, String> entry : attributes.entrySet()){
Statement st= conn.createStatement();
String key= entry.getKey();
String val= entry.getValue();
//if the key equals to the Year
if(key.equals("Year")){
st.execute("UPDATE MediaArchive SET Date = '"+val+"' WHERE MediaId = '"+name+"'");
}
//if the key equals to the City
if(key.equals("City")){
st.execute("UPDATE MediaArchive SET Location = '"+val+"' WHERE MediaId = '"+name+"'");
}
st.close();
}
conn.close();
return true;
} catch (Exception e) {
return false;
}
}
//this function adds the people into the media
Boolean peopleInMedia( FileIdentifier fileIdentifier, List<PersonIdentity> people ){
try {
int mediaID= fileIdentifier.FileId;
DbConnection db = new DbConnection();
Connection conn= db.createDBConnection();
Statement st= conn.createStatement();
//adding all the people into the database query
for(int i=0;i<people.size();i++){
st.execute("Insert into peopleInMedia(PersonId,MediaId) values('"+people.get(i).PersonId+"','"+mediaID+"')");
}
return true;
} catch (Exception e) {
return false;
}
}
//this will add tags to the media file
Boolean tagMedia( FileIdentifier fileIdentifier, String tag ){
try {
DbConnection db = new DbConnection();
Connection conn= db.createDBConnection();
Statement st= conn.createStatement();
int name= fileIdentifier.FileId;
//this query will update the tag and add tag on appropriate place
st.execute("UPDATE MediaArchive SET Tags = '"+tag+"' WHERE MediaId = '"+name+"'");
return true;
} catch (Exception e) {
return false;
}
}
}