

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{Voyage}
\subtitle{NoSQL Object Database}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W4S11}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Goal}

\begin{itemize}
\item To let you build a real little application
\item Show you a nice way to store objects
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{MongoDB}

\begin{itemize}
\item Document oriented, open-source NoSQL database
\item Powerful query language
\item Most popular document database so far 
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{What is Voyage?}

\begin{itemize}
\item Object-Document Mapper for MongoDB
\item Think on Hibernate for MongoDB
\item For Pharo, obviously ;)
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Voyage Feature}

\begin{itemize}
\item Simple
\item Ensure object identity
\item Provide error-handling
\item Implement a connection pool
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Setting a Connexion}

\begin{listing}{}
| repository |
repository := VOMongoRepository
    host: 'localhost'
    database: 'demo'.
repository enableSingleton.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Setting a In Memory Connexion}

\begin{listing}{}
| repository |
repository := VOMemoryRepository new.
repository enableSingleton.
\end{listing}

\begin{itemize}
\item Really nice to prototype 
\item Then can easily switch to a MongoDB
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{A Simple Model}


\begin{center}
\includegraphics[width=0.9\textwidth]{figures/SuperHeroesModel.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{A Simpler Model}


\begin{center}
\includegraphics[width=0.9\textwidth]{figures/SuperHeroesModelSimpler.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{A Simpler Model}

\begin{listing}{}
Object subclass: #Hero
	instanceVariableNames: 'name level powers'
	classVariableNames: ''
	package: 'SuperHeroes'

Hero >> name
    ^ name
Hero >> name: aString    
    name := aString
Hero >> level
    ^ level
Hero >> level: anObject    
    level := anObject
Hero >> powers
    ^ powers ifNil: [ powers := Set new ]
Hero >> addPower: aPower
    self powers add: aPower
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{A Simpler Model}

\begin{listing}{}
Object subclass: #Power
	instanceVariableNames: 'name'
	classVariableNames: ''
	package: 'SuperHeroes'.

Power>>name
    ^ name
Power>>name: aString    
    name := aString
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Root Classes}

\begin{itemize}
\item Entry-point for our database
\item Can be any class in the system
\item Marked as root by \code{isVoyageRoot} class method
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Root Classes}

\begin{listing}{}
Hero class >> isVoyageRoot
    ^ true
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Some Heroes}

\begin{listing}{}
Hero new 
    name: 'Spiderman';
    level: #epic;
    addPower: (Power new name: 'Super-strength');
    addPower: (Power new name: 'Wall-climbing');
    addPower: (Power new name: 'Spider instinct');
    save.

Hero new 
    name: 'Wolverine';
    level: #epic;
    addPower: (Power new name: 'Regeneration');
    addPower: (Power new name: 'Adamantium claws');
    save.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{In DB}

\begin{listing}{}
> db.Hero.find()[0]
{
	"_id" : ObjectId("d847065c56d0ad09b4000001"),
	"#version" : 688076276,
	"#instanceOf" : "Hero",
	"level" : "epic",
	"name" : "Spiderman",
	"powers" : [
		{
			"#instanceOf" : "Power",
			"name" : "Spider instinct"
		},
		{
			"#instanceOf" : "Power",
			"name" : "Super-strength"
		},
		{
			"#instanceOf" : "Power",
			"name" : "Wall-climbing"
		}
	]
}
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Querying}

\begin{listing}{}
Hero selectAll.
> an OrderedCollection(a Hero, a Hero)
\end{listing}

\begin{listing}{}
Hero selectOne: [ :each | each name = 'Spiderman' ].
> a Hero
\end{listing}

\begin{listing}{}
Hero selectMany: [ :each | each level = #epic ]. 
> an OrderedCollection(a Hero, a Hero)
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Querying 2}

\begin{listing}{}
Hero selectOne: { #name -> 'Spiderman' } asDictionary.
> a Hero
\end{listing}

\begin{listing}{}
Hero selectMany: { #level -> #epic } asDictionary. 
> an OrderedCollection(a Hero, a Hero)
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Querying 3}

\begin{listing}{}
Hero
    selectMany: { #level -> #epic } asDictionary
    sortBy: { #name -> VOOrder ascending }
    limit: 10
    offset: 0. 
> an OrderedCollection(a Hero, a Hero)
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Some Operations}

\begin{listing}{}
Hero count.
> 2
\end{listing}

\begin{listing}{}
Hero count: [ :each | each name = 'Spiderman' ]
> 1.
\end{listing}

\begin{listing}{}
Hero removeAll. "Beware of this!"
> Hero class
\end{listing}

\begin{listing}{}
hero := Hero selectAll anyOne.
hero remove.
> a Hero
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Defining Document Roots}

\begin{itemize}
\item If you want to query them
\item If you want to share objects between roots
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Defining Document Roots}

\begin{itemize}
\item Yes, Hero is a root on the example
\item Power can be a root too (you can “share” powers between heroes)
\item Any class can be declared as root, Voyage will manage it automatically
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Defining Document Roots}

\begin{listing}{}
Power class >> isVoyageRoot
  ^ true
\end{listing}

\begin{listing}{}
Power new name: 'Fly'; save.
Power new name: 'Super-strength'; save.
\end{listing}

\begin{listing}{}
fly := Power selectOne: [ :each | each name = 'Fly'].
superStrength := Power selectOne: [ :each | each name = 'Super-strength']. 
Hero new 
    name: 'Superman';
    level: #epic;
    addPower: fly;
    addPower: superStrength;
    save.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Important}

Reset repository when changing the schema

\begin{listing}{}
VORepository current reset.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{In DB}

\begin{listing}{}
> db.Hero.find()[0]
{
	"_id" : ObjectId("d8474983421aa909b4000008"),
	"#version" : NumberLong("3874503784"),
	"#instanceOf" : "Hero",
	"level" : "epic",
	"name" : "Superman",
	"powers" : [
		{
			"#collection" : "Power",
			"#instanceOf" : "Power",
			"__id" : ObjectId("d84745dd421aa909b4000005")
		},
		{
			"#collection" : "Power",
			"#instanceOf" : "Power",
			"__id" : ObjectId("d84745dd421aa909b4000006")
		}
	]
}
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Relationships}

\begin{itemize}
\item Root references (kind of “foreign keys”)
\item Voyage handles cyclic references of root objects 
\item Beware, Voyage does not support cyclic references of embedded objects (yet)
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Conclusion}

\begin{itemize}
\item We can easily save objects in MongoDB
\item More information in \textbf{Entreprise Pharo: a Web Perspective}
\end{itemize}
\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
