Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Group8
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EC504 Spring 2024 Group Projects
Group8
Commits
59a5b83a
Commit
59a5b83a
authored
1 year ago
by
Sanford Jonathan Edelist
Browse files
Options
Downloads
Patches
Plain Diff
Delete DatabaseUpdater.java
parent
95726b93
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DatabaseUpdater.java
+0
-66
0 additions, 66 deletions
DatabaseUpdater.java
with
0 additions
and
66 deletions
DatabaseUpdater.java
deleted
100644 → 0
+
0
−
66
View file @
95726b93
package
org.group8
;
import
com.mongodb.client.MongoClients
;
import
com.mongodb.client.MongoClient
;
import
com.mongodb.client.MongoDatabase
;
import
com.mongodb.client.MongoCollection
;
import
com.mongodb.client.model.Filters
;
import
com.mongodb.client.model.ReplaceOptions
;
import
org.bson.Document
;
import
object_detection.types.ObjectSet
;
import
object_detection.types.PointSet
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
DatabaseUpdater
{
private
MongoClient
mongoClient
;
private
MongoDatabase
database
;
private
MongoCollection
<
Document
>
collection
;
public
DatabaseUpdater
()
{
String
uri
=
"mongodb+srv://Cluster03790:dlVzT2Z2bEh9@cluster03790.tk4cwyy.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
;
mongoClient
=
MongoClients
.
create
(
uri
);
database
=
mongoClient
.
getDatabase
(
"Objects"
);
collection
=
database
.
getCollection
(
"objectSets"
);
}
/**
* Updates the MongoDB with an ObjectSet.
*
* @param objSet The ObjectSet to update in the database.
* @return true if the update was successful, false otherwise.
*/
public
boolean
updateDB
(
ObjectSet
objSet
)
{
try
{
for
(
PointSet
pointSet
:
ObjectSet
.
objects
)
{
Document
doc
=
pointSetToDocument
(
String
.
valueOf
(
pointSet
.
hashCode
()),
pointSet
);
ReplaceOptions
options
=
new
ReplaceOptions
().
upsert
(
true
);
collection
.
replaceOne
(
Filters
.
eq
(
"setId"
,
String
.
valueOf
(
pointSet
.
hashCode
())),
doc
,
options
);
}
return
true
;
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"An error occurred while updating the database: "
+
e
);
return
false
;
}
}
private
Document
pointSetToDocument
(
String
setId
,
PointSet
pointSet
)
{
List
<
Document
>
pointsList
=
new
ArrayList
<>();
for
(
Point
p
:
pointSet
.
getPoints
())
{
pointsList
.
add
(
new
Document
(
"x"
,
p
.
getX
())
.
append
(
"y"
,
p
.
getY
())
.
append
(
"z"
,
p
.
getZ
()));
}
return
new
Document
(
"setId"
,
setId
)
.
append
(
"points"
,
pointsList
);
}
public
static
void
main
(
String
[]
args
)
{
DatabaseUpdater
updater
=
new
DatabaseUpdater
();
ObjectSet
objectSet
=
new
ObjectSet
();
// Assume this is populated
boolean
success
=
updater
.
updateDB
(
objectSet
);
System
.
out
.
println
(
"Update successful: "
+
success
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment