+ All Categories
Home > Documents > No Relational Db

No Relational Db

Date post: 12-Nov-2015
Category:
Upload: cristian-david
View: 18 times
Download: 8 times
Share this document with a friend
Description:
Db
15
Bibliography • Plugge, E., Membrey, P., The definitive guide to MongoDB. Ed. Apress http://docs.mongodb.org /
Transcript

Presentacin de PowerPoint

BibliographyPlugge, E., Membrey, P., The definitive guide to MongoDB. Ed. Apresshttp://docs.mongodb.org/

Objetivos:Explicar el modelo de datos de una bd No sqlComparar bd Nosql and sql

1SQL DBe.g., My SQL,Oracle,DerbyNo SQL DBE.g., MongoDB,DynamoDB

TableColectionRowDocumentUn documento es como la fila de un esquema que no tiene esquema ni FKs2Example: GymA user practices a sport and has multiple addressesFunctional requirementsGet the details of a userGet the list of sports

SportSportSport {ID:Name:.}

Name: Birthday: Kind-of JSON DocumentSQL:No SQL:4

MongoDB supports ACID operations in a single document , but not support multi-document transactionsAtomicity: The database transaction must completely succeed or completely fail. Partial success is not allowed.Consistency: During the database transaction, the RDBMS progresses from one valid state to another. The state is never invalid.Isolation: The clients database transaction must occur in isolation from other clients attempting to transact with the RDBMS.Durability: The data operation that was part of the transaction must be reflected in nonvolatile storage (computer memory that can retrieve stored information even when not powered like a hard disk) and persist after the transaction successfully completes. Transaction failures cannot leave the data in a partially committed state.Certain use cases for RDBMSs, like online transaction processing, depend on ACID-compliant transactions between the client and the RDBMS for the system to function properly. A great example of an ACID-compliant transaction is a transfer of funds from one bank account to another.This breaks down into two database transactions, where the originating account shows a withdrawal, and the destination account shows a deposit. Obviously, these two transactions have to be tied together in order to be valid so that if either of them fail, the whole operation must fail to ensure both balances remain valid.

AtomicidadMongoDB provee operaciones atmicas en un mismo documento, uno puede embeber datos en un array o subdocumentos en un mismo documento. Esto permite actualizar un mismo documento en una operacin individual.

ConsistenciaMDB modifica cada documento aisladamente, clientes nunca ven los documentos en estados intermedios. No hay aislamiento para multi-documentos

AislamientoCundo y como los cambios hechos por una operacin son visibles a los clientesMDB permite a los clientes leer documentos insertados o modificados (es decir antes de retornar de un write) antes de un commit en disco.

DurabilidadSi hubo un retorno de la operacin write es por que los datos estarn disponibles cuando se reinicie la bd.

Concerned about consistency and partition tolerance(CP) Such a database system stores data in the distributed nodes, but also ensure the consistency of these data, but support not good enough for the availability.

5JoinsJDBC and SQL DBResultSet rs = stmt.executeQuery(SELECTu.name, u.birthDate, s.nameFROMSport sINNERJOINUser uONs.id=u.sport_id);JPA and SQL DBQuery q = entityManager.createQuery("select u from User u);JPA and Non SQL DBQuery q = entityManager.createQuery("select u from User u);What do I code?

JSONWhat do I code?At the service level, the code is the same for JPA SQL and JPA No SQL

What do I Code?There are changes at the persistence level: the persistence unit changes as well as the entities

@Embedded@NoSql@EntityJPA No SQL@EntityJPA SQL

@OneToOne (fetch=FetchType.EAGER)JPA performs an inner joinWhat do I code?At disk level, the data representation is different

No SQL_IdWinnerCellphoneTelephone Surname54DC369AFalse30023454367659675GomezCompetitorCompetitor_IdUpdated_atModelyearCreated_atPlatebrand54DC369ANull345NullTRE-465BMWVehicleSQLIs it possible to scale out a SQL DB?Yes, but it is expensiveYou buy a bigger, faster server (vertical scaling)If there is not a bigger server to buy, the solution is to spread out to two or more servers (horizontal scaling)buy a active/active application cluster (e.g., Oracle one)

Esto es diferente de tener una bases de datos replicada, es este caso, los datos que estn en una base son lo mismos que estn en la otra11Is it possible to scale out a No SQL DB?Yes, it is cheaper than SQL DB scalingThe documents are separately stored in several servers (horizontal scaling)Ideal for Cloud computing

512GB512GB12ComparisonNo SQLAggregation (favours performance)Scaling cheaper than SQLEncouraged when requirements change from week to week or day to day (sacrifice data integrity)E.g., Free web apps. that need to scale, social networksSQLNormalization (Too structured, little flexibility, affects performance)Expensive to scale outEncouraged when you need to be really uptight about data and high availabilityE.g., bank accounts13De acuerdo con el enunciado, cules son las entidades del negocio MS adecuadas de persistir en una bd No SQL

TodasCliente, amigos y sus gustosCliente y bonosNo relational modelMaterials taken from http://docs.mongodb.org/manual/Who do use non relational model?Facebook/TwitterAmazonGoogle/Yahoo

Motivating example

Issues with the relational model

Data is too structuredLow performanceIn many cases data is tightly related (e.g., post & comments), in despite of this it is separated among tables. Since information is spread among tables, queries/updates/processing impacts performanceLittle flexibilitySometimes new use cases requires extra data. It causes headache to architect because she has to figure out where to stick this data on the db To cope with these issues, it was proposed a non relational model (e.g., mongoDB one)

Concepts behind MongoDBIn relational model, a schema is required beforehandIn MongoDB, schema is flexibledoes not enforce document (record) structure which facilitates mapping of documents to an objectEach document can match the data fields of the represented entity, even if the data has substantial variationDocuments are analogous to JSON objects but exist in the database in a more type-rich format known as BSON

Concepts behind MongoDBReferences from one document to another make it possible to relate data

Embedded dataMongoDB makes it possible to embed document structures as sub-documents in a field or array within a document These denormalized data models allow applications to retrieve and manipulate related data in a single database operation

Atomicity of write operationsNo single write operation can atomically affect more than one document or more than one collectionCollectionsMongoDB stores system information in collectionsBasic operationsdb.Product.find()db.Product.insert( { item: "card", qty: 15 } )Db.Product.find({}, {:item => card})

Using mongoDB in MueblesdelosalpesModifications make it possible to switch between relational and non-relational databasesServicioPersistencia and ServicioPersistenciaNoSqlImplement a Local interfaceHave @EJB annotationExtend MongoConfig

Config.propertieslookup

24DB connection

Modify create method (just for Vendedor)

ComparisonNon relationalFor some queries you have to go through every list and count each loaf individuallyEncouraged when requirements change from week to week or day to day (sacrifice data integrity)E.g., Free web apps. that need to scale RelationalCounting is easier because one has join tables

Encouraged when you need to be really uptight about dataE.g., bank accounts

28What is the meaning of EJB?The @EJB annotation (and @Resource, @WebServiceRef, etc.) serves two purposes:It declares a reference in the component namespace. For example, @EJB(name="myEJB") creates a reference java:comp/env/myEJB. If you annotate a field and do not specify a name, then it creates a reference java:comp/env/com.example.MyClass/myField.If the annotation is declared on a field or setter method, then the container performs injection when the component is created.How the reference is resolved varies, independent of whether the reference is being resolved for a lookup("java:comp/env/myEJB") or due to injection:If EE 6+ is used, the lookup attribute requires a JNDI lookup to resolve the target.Some application servers support mappedName, which is specified to be vendor specific. This is usually implemented by performing a lookup.Application servers support bindings at deployment time. This is usually implemented by performing a lookup.If no other binding information is provided and the bean interface (beanInterface or the field type) is only implemented by a single EJB in the application, then the EJB specification requires that it fall back to that.If no other binding information is provided and #4 cannot work, some application servers will attempt to perform a lookup in the server namespace based on the ref name (for example, java:comp/env/myEJB might cause a lookup of myEJB in the server namespace).


Recommended