SlideShare a Scribd company logo
Creating a Facebook Clone - Part XVIII
All media objects e.g. images, videos etc. are stored in the `Media` `Entity`.

This is pretty convenient as it lets us store media files in the database under a separate database table (which would be better for performance).
© Codename One 2017 all rights reserved
Pros Con
Clustering Large Database
Reasonable Performance Performance Could be Challenging
Simple Simple unless we scale
There are pros and cons for storing media in a database

A pro would be that it works with clustering as data is in the database and not on a specific server file.

However, it might make the database too large and harder to back up.

Performance is more complicated. It should be reasonable as long as table is separate. Historically performance of blob's in the database was pretty bad and there might
be issues in some deployments or some database types. So this might be challenging

Both approaches would be simple unless scaling is involved in which case we’d need to store files somewhere…

There is a common alternative of using a service dedicated to hosting files either home grown or in the cloud (e.g. S3). Since the Media object is separate it makes sense
to have it anyway and if we choose to use such a service we can include the file key for the cloud object instead of the actual media file.
@Entity
public class Media {
@Id
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
@ManyToOne
private User owner;
@Lob
private byte[] data;
public Media() {
id = UUID.randomUUID().toString();
}
public MediaDAO getDAO() {
Media
The Media object itself is pretty simple.

Just like the User object we use a UUID to represent a Media object
@Entity
public class Media {
@Id
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
@ManyToOne
private User owner;
@Lob
private byte[] data;
public Media() {
id = UUID.randomUUID().toString();
}
public MediaDAO getDAO() {
Media
This is the file name used when uploading which might be relevant if we let the user browse the files he uploaded in the future
@Entity
public class Media {
@Id
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
@ManyToOne
private User owner;
@Lob
private byte[] data;
public Media() {
id = UUID.randomUUID().toString();
}
public MediaDAO getDAO() {
Media
The time stamp when the media was uploaded, using long makes this simpler to work with although date might be more convenient in a database
@Entity
public class Media {
@Id
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
@ManyToOne
private User owner;
@Lob
private byte[] data;
public Media() {
id = UUID.randomUUID().toString();
}
public MediaDAO getDAO() {
Media
Role can be used to indicate the purpose of the image e.g. it can be avatar to indicate the image serves as an avatar
@Entity
public class Media {
@Id
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
@ManyToOne
private User owner;
@Lob
private byte[] data;
public Media() {
id = UUID.randomUUID().toString();
}
public MediaDAO getDAO() {
Media
Visibility is the privacy scope of the image e.g. friends would indicate only friends can see the image whereas public would indicate it's visible to everyone
@Entity
public class Media {
@Id
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
@ManyToOne
private User owner;
@Lob
private byte[] data;
public Media() {
id = UUID.randomUUID().toString();
}
public MediaDAO getDAO() {
Media
This is the user that uploaded this media object
@Entity
public class Media {
@Id
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
@ManyToOne
private User owner;
@Lob
private byte[] data;
public Media() {
id = UUID.randomUUID().toString();
}
public MediaDAO getDAO() {
Media
The data is marked as a Lob which lets us store relatively large objects. Notice that there is still a limit on file upload size enforced by the webservice support in spring
boot
@ManyToOne
private User owner;
@Lob
private byte[] data;
public Media() {
id = UUID.randomUUID().toString();
}
public MediaDAO getDAO() {
return new MediaDAO(id, filename, date, role, mimeType, visibility,
owner.getDAO(), data);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
Media
The media object has a DAO as well, it lets us pass the media data back and forth through the service layer
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
public String getVisibility() {
return visibility;
}
public void setVisibility(String visibility) {
this.visibility = visibility;
}
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
}
Media
As you can see the rest of the code is only getters and setters, nothing much.

The object is relatively simple and only contains one small dependency: MediaDAO. We could potentially enhance it with additional data such as description, tagging and
even auto-generated content based on image recognition. But for now that’s enough.
public interface MediaRepository extends CrudRepository<Media, String> {
}
MediaRepository
Before we go into the MediaDAO we also need to mention the CrudRepository interface for this class. It's simple as we don't need any queries at this point.
public class MediaDAO {
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
private UserDAO owner;
private byte[] data;
public MediaDAO() {
}
public MediaDAO(String id, String filename, long date, String role,
String mimeType, String visibility, UserDAO owner,
byte[] data) {
this.id = id;
this.filename = filename;
this.date = date;
this.role = role;
this.mimeType = mimeType;
this.visibility = visibility;
MediaDAO
Now that we got this out of the way we can look at the DAO, it's trivial too.

The fields map directly to the fields of the Media class in this case
public class MediaDAO {
private String id;
private String filename;
private long date;
private String role;
private String mimeType;
private String visibility;
private UserDAO owner;
private byte[] data;
public MediaDAO() {
}
public MediaDAO(String id, String filename, long date, String role,
String mimeType, String visibility, UserDAO owner,
byte[] data) {
this.id = id;
this.filename = filename;
this.date = date;
this.role = role;
this.mimeType = mimeType;
this.visibility = visibility;
MediaDAO
The one obvious exception is the UserDAO object which uses the DAO type instead of the User type
private String mimeType;
private String visibility;
private UserDAO owner;
private byte[] data;
public MediaDAO() {
}
public MediaDAO(String id, String filename, long date, String role,
String mimeType, String visibility, UserDAO owner,
byte[] data) {
this.id = id;
this.filename = filename;
this.date = date;
this.role = role;
this.mimeType = mimeType;
this.visibility = visibility;
this.owner = owner;
this.data = data;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
MediaDAO
As we did with the User object we have a default constructor and a convenience constructor. Both of these were generated by the IDE’s completion suggestion.
}
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public String getVisibility() {
return visibility;
}
public void setVisibility(String visibility) {
this.visibility = visibility;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
public UserDAO getOwner() {
return owner;
}
public void setOwner(UserDAO owner) {
this.owner = owner;
}
MediaDAO
The rest of the code is just auto-generated getters & setters. Nothing else. And with that we conclude the media object/entity.

More Related Content

Similar to Creating a Facebook Clone - Part XVIII - Transcript.pdf

Digital Object Identifiers for EOSDIS data
Digital Object Identifiers for EOSDIS dataDigital Object Identifiers for EOSDIS data
Digital Object Identifiers for EOSDIS data
The HDF-EOS Tools and Information Center
 
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Neo4j
 
PrismTech Vortex Tutorial Part 1
PrismTech Vortex Tutorial Part 1PrismTech Vortex Tutorial Part 1
PrismTech Vortex Tutorial Part 1
ADLINK Technology IoT
 
Vortex Tutorial -- Part I
Vortex Tutorial -- Part IVortex Tutorial -- Part I
Vortex Tutorial -- Part I
Angelo Corsaro
 
Creating a Facebook Clone - Part XXXVIII.pdf
Creating a Facebook Clone - Part XXXVIII.pdfCreating a Facebook Clone - Part XXXVIII.pdf
Creating a Facebook Clone - Part XXXVIII.pdf
ShaiAlmog1
 
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docxQuestion- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
HarryXQjCampbellz
 
DDS-PSM-Cxx and simd-cxx
DDS-PSM-Cxx and simd-cxxDDS-PSM-Cxx and simd-cxx
DDS-PSM-Cxx and simd-cxx
Angelo Corsaro
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
Dr. Ramkumar Lakshminarayanan
 
Metadata For Preservation Delos
Metadata For Preservation DelosMetadata For Preservation Delos
Metadata For Preservation Delos
DigitalPreservationEurope
 
Targeted Marketing: How Marketing Companies can use Big Data to Target Custom...
Targeted Marketing: How Marketing Companies can use Big Data to Target Custom...Targeted Marketing: How Marketing Companies can use Big Data to Target Custom...
Targeted Marketing: How Marketing Companies can use Big Data to Target Custom...
Ray Février
 
Apache Kite
Apache KiteApache Kite
Apache Kite
Alwin James
 
Green dao 3.0
Green dao 3.0Green dao 3.0
Green dao 3.0
彥彬 洪
 
20090701 Climate Data Staging
20090701 Climate Data Staging20090701 Climate Data Staging
20090701 Climate Data Staging
Henning Bergmeyer
 
Introduction To Dojo
Introduction To DojoIntroduction To Dojo
Introduction To Dojo
yoavrubin
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.com
phanleson
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
Staples
 
Creating a Whatsapp Clone - Part XII.pdf
Creating a Whatsapp Clone - Part XII.pdfCreating a Whatsapp Clone - Part XII.pdf
Creating a Whatsapp Clone - Part XII.pdf
ShaiAlmog1
 
OOP programming for engineering students
OOP programming for engineering studentsOOP programming for engineering students
OOP programming for engineering students
iaeronlineexm
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
uEngine Solutions
 
Android Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, VonageAndroid Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, Vonage
DroidConTLV
 

Similar to Creating a Facebook Clone - Part XVIII - Transcript.pdf (20)

Digital Object Identifiers for EOSDIS data
Digital Object Identifiers for EOSDIS dataDigital Object Identifiers for EOSDIS data
Digital Object Identifiers for EOSDIS data
 
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
 
PrismTech Vortex Tutorial Part 1
PrismTech Vortex Tutorial Part 1PrismTech Vortex Tutorial Part 1
PrismTech Vortex Tutorial Part 1
 
Vortex Tutorial -- Part I
Vortex Tutorial -- Part IVortex Tutorial -- Part I
Vortex Tutorial -- Part I
 
Creating a Facebook Clone - Part XXXVIII.pdf
Creating a Facebook Clone - Part XXXVIII.pdfCreating a Facebook Clone - Part XXXVIII.pdf
Creating a Facebook Clone - Part XXXVIII.pdf
 
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docxQuestion- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
 
DDS-PSM-Cxx and simd-cxx
DDS-PSM-Cxx and simd-cxxDDS-PSM-Cxx and simd-cxx
DDS-PSM-Cxx and simd-cxx
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
 
Metadata For Preservation Delos
Metadata For Preservation DelosMetadata For Preservation Delos
Metadata For Preservation Delos
 
Targeted Marketing: How Marketing Companies can use Big Data to Target Custom...
Targeted Marketing: How Marketing Companies can use Big Data to Target Custom...Targeted Marketing: How Marketing Companies can use Big Data to Target Custom...
Targeted Marketing: How Marketing Companies can use Big Data to Target Custom...
 
Apache Kite
Apache KiteApache Kite
Apache Kite
 
Green dao 3.0
Green dao 3.0Green dao 3.0
Green dao 3.0
 
20090701 Climate Data Staging
20090701 Climate Data Staging20090701 Climate Data Staging
20090701 Climate Data Staging
 
Introduction To Dojo
Introduction To DojoIntroduction To Dojo
Introduction To Dojo
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.com
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
 
Creating a Whatsapp Clone - Part XII.pdf
Creating a Whatsapp Clone - Part XII.pdfCreating a Whatsapp Clone - Part XII.pdf
Creating a Whatsapp Clone - Part XII.pdf
 
OOP programming for engineering students
OOP programming for engineering studentsOOP programming for engineering students
OOP programming for engineering students
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
 
Android Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, VonageAndroid Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, Vonage
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
ShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
ShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
 

Recently uploaded

June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 

Recently uploaded (20)

June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 

Creating a Facebook Clone - Part XVIII - Transcript.pdf

  • 1. Creating a Facebook Clone - Part XVIII All media objects e.g. images, videos etc. are stored in the `Media` `Entity`. This is pretty convenient as it lets us store media files in the database under a separate database table (which would be better for performance).
  • 2. © Codename One 2017 all rights reserved Pros Con Clustering Large Database Reasonable Performance Performance Could be Challenging Simple Simple unless we scale There are pros and cons for storing media in a database A pro would be that it works with clustering as data is in the database and not on a specific server file. However, it might make the database too large and harder to back up. Performance is more complicated. It should be reasonable as long as table is separate. Historically performance of blob's in the database was pretty bad and there might be issues in some deployments or some database types. So this might be challenging Both approaches would be simple unless scaling is involved in which case we’d need to store files somewhere…
 There is a common alternative of using a service dedicated to hosting files either home grown or in the cloud (e.g. S3). Since the Media object is separate it makes sense to have it anyway and if we choose to use such a service we can include the file key for the cloud object instead of the actual media file.
  • 3. @Entity public class Media { @Id private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; @ManyToOne private User owner; @Lob private byte[] data; public Media() { id = UUID.randomUUID().toString(); } public MediaDAO getDAO() { Media The Media object itself is pretty simple. Just like the User object we use a UUID to represent a Media object
  • 4. @Entity public class Media { @Id private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; @ManyToOne private User owner; @Lob private byte[] data; public Media() { id = UUID.randomUUID().toString(); } public MediaDAO getDAO() { Media This is the file name used when uploading which might be relevant if we let the user browse the files he uploaded in the future
  • 5. @Entity public class Media { @Id private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; @ManyToOne private User owner; @Lob private byte[] data; public Media() { id = UUID.randomUUID().toString(); } public MediaDAO getDAO() { Media The time stamp when the media was uploaded, using long makes this simpler to work with although date might be more convenient in a database
  • 6. @Entity public class Media { @Id private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; @ManyToOne private User owner; @Lob private byte[] data; public Media() { id = UUID.randomUUID().toString(); } public MediaDAO getDAO() { Media Role can be used to indicate the purpose of the image e.g. it can be avatar to indicate the image serves as an avatar
  • 7. @Entity public class Media { @Id private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; @ManyToOne private User owner; @Lob private byte[] data; public Media() { id = UUID.randomUUID().toString(); } public MediaDAO getDAO() { Media Visibility is the privacy scope of the image e.g. friends would indicate only friends can see the image whereas public would indicate it's visible to everyone
  • 8. @Entity public class Media { @Id private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; @ManyToOne private User owner; @Lob private byte[] data; public Media() { id = UUID.randomUUID().toString(); } public MediaDAO getDAO() { Media This is the user that uploaded this media object
  • 9. @Entity public class Media { @Id private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; @ManyToOne private User owner; @Lob private byte[] data; public Media() { id = UUID.randomUUID().toString(); } public MediaDAO getDAO() { Media The data is marked as a Lob which lets us store relatively large objects. Notice that there is still a limit on file upload size enforced by the webservice support in spring boot
  • 10. @ManyToOne private User owner; @Lob private byte[] data; public Media() { id = UUID.randomUUID().toString(); } public MediaDAO getDAO() { return new MediaDAO(id, filename, date, role, mimeType, visibility, owner.getDAO(), data); } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getFilename() { return filename; } public void setFilename(String filename) { Media The media object has a DAO as well, it lets us pass the media data back and forth through the service layer
  • 11. return mimeType; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public byte[] getData() { return data; } public void setData(byte[] data) { this.data = data; } public String getVisibility() { return visibility; } public void setVisibility(String visibility) { this.visibility = visibility; } public User getOwner() { return owner; } public void setOwner(User owner) { this.owner = owner; } } Media As you can see the rest of the code is only getters and setters, nothing much. The object is relatively simple and only contains one small dependency: MediaDAO. We could potentially enhance it with additional data such as description, tagging and even auto-generated content based on image recognition. But for now that’s enough.
  • 12. public interface MediaRepository extends CrudRepository<Media, String> { } MediaRepository Before we go into the MediaDAO we also need to mention the CrudRepository interface for this class. It's simple as we don't need any queries at this point.
  • 13. public class MediaDAO { private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; private UserDAO owner; private byte[] data; public MediaDAO() { } public MediaDAO(String id, String filename, long date, String role, String mimeType, String visibility, UserDAO owner, byte[] data) { this.id = id; this.filename = filename; this.date = date; this.role = role; this.mimeType = mimeType; this.visibility = visibility; MediaDAO Now that we got this out of the way we can look at the DAO, it's trivial too. The fields map directly to the fields of the Media class in this case
  • 14. public class MediaDAO { private String id; private String filename; private long date; private String role; private String mimeType; private String visibility; private UserDAO owner; private byte[] data; public MediaDAO() { } public MediaDAO(String id, String filename, long date, String role, String mimeType, String visibility, UserDAO owner, byte[] data) { this.id = id; this.filename = filename; this.date = date; this.role = role; this.mimeType = mimeType; this.visibility = visibility; MediaDAO The one obvious exception is the UserDAO object which uses the DAO type instead of the User type
  • 15. private String mimeType; private String visibility; private UserDAO owner; private byte[] data; public MediaDAO() { } public MediaDAO(String id, String filename, long date, String role, String mimeType, String visibility, UserDAO owner, byte[] data) { this.id = id; this.filename = filename; this.date = date; this.role = role; this.mimeType = mimeType; this.visibility = visibility; this.owner = owner; this.data = data; } public String getId() { return id; } public void setId(String id) { this.id = id; } MediaDAO As we did with the User object we have a default constructor and a convenience constructor. Both of these were generated by the IDE’s completion suggestion.
  • 16. } public String getMimeType() { return mimeType; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public String getVisibility() { return visibility; } public void setVisibility(String visibility) { this.visibility = visibility; } public byte[] getData() { return data; } public void setData(byte[] data) { this.data = data; } public UserDAO getOwner() { return owner; } public void setOwner(UserDAO owner) { this.owner = owner; } MediaDAO The rest of the code is just auto-generated getters & setters. Nothing else. And with that we conclude the media object/entity.