SideNail. Martín Schonaker, Santiago Martínez

Similar documents
Course Announcements. Bacon is due next Monday. Next lab is about drawing UIs. Today s lecture will help thinking about your DB interface.

Position and Displacement

!t + U " #Q. Solving Physical Problems: Pitfalls, Guidelines, and Advice

ST-Links. SpatialKit. Version 3.0.x. For ArcMap. ArcMap Extension for Directly Connecting to Spatial Databases. ST-Links Corporation.

D2D SALES WITH SURVEY123, OP DASHBOARD, AND MICROSOFT SSAS

Basic matrix operations

Quadratic Equations Part I

Welcome! Power BI User Group (PUG) Copenhagen

Relational Algebra and Calculus

Programming Assignment 4: Image Completion using Mixture of Bernoullis

Practical Data Processing With Haskell

The File Geodatabase API. Dave Sousa, Lance Shipman

MA554 Assessment 1 Cosets and Lagrange s theorem

Properties of Arithmetic

Chapter 4. Solving Systems of Equations. Chapter 4

The picture of an atom that you may have in your mind that of a nucleus

I started to think that maybe I could just distribute the log so that I get:

VELA. Getting started with the VELA Versatile Laboratory Aid. Paul Vernon

Preptests 55 Answers and Explanations (By Ivy Global) Section 4 Logic Games

Sub-Queries in SQL SQL. 3 Types of Sub-Queries. 3 Types of Sub-Queries. Scalar Sub-Query Example. Scalar Sub-Query Example

I started to think that maybe I could just distribute the log so that I get:

Counting in the Twilight Zone

Designing Information Devices and Systems I Fall 2018 Lecture Notes Note Positioning Sytems: Trilateration and Correlation

Databases 2011 The Relational Algebra

Announcements. CS 188: Artificial Intelligence Fall Causality? Example: Traffic. Topology Limits Distributions. Example: Reverse Traffic

Databases Exam HT2016 Solution

8. TRANSFORMING TOOL #1 (the Addition Property of Equality)

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

Introduction to ArcGIS Server Development

Lab 4. Current, Voltage, and the Circuit Construction Kit

CS1800: Mathematical Induction. Professor Kevin Gold

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014

EXAM 2 REVIEW DAVID SEAL

Linear Algebra Handout

Matrix Inverses. November 19, 2014

Confidence Intervals. - simply, an interval for which we have a certain confidence.

A Few Examples of Limit Proofs

Database Systems SQL. A.R. Hurson 323 CS Building

Designing Information Devices and Systems I Fall 2018 Lecture Notes Note Positioning Sytems: Trilateration and Correlation

You separate binary numbers into columns in a similar fashion. 2 5 = 32

Homework 6: Image Completion using Mixture of Bernoullis

Cosets and Lagrange s theorem

Math 5a Reading Assignments for Sections

Arguments and Proofs. 1. A set of sentences (the premises) 2. A sentence (the conclusion)

POLYNOMIAL EXPRESSIONS PART 1

2 Systems of Linear Equations

Event Operators: Formalization, Algorithms, and Implementation Using Interval- Based Semantics

Relational Algebra & Calculus

Gauss Law. In this chapter, we return to the problem of finding the electric field for various distributions of charge.

Note that we are looking at the true mean, μ, not y. The problem for us is that we need to find the endpoints of our interval (a, b).

Geographical Databases: PostGIS. Introduction. Creating a new database. References

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20

30. TRANSFORMING TOOL #1 (the Addition Property of Equality)

CS429: Computer Organization and Architecture

At the start of the term, we saw the following formula for computing the sum of the first n integers:

On the Concept of Enumerability Of Infinite Sets Charlie Obimbo Dept. of Computing and Information Science University of Guelph

Homework Assignment 2. Due Date: October 17th, CS425 - Database Organization Results

Coping with disk crashes

LECTURE 15: SIMPLE LINEAR REGRESSION I

CS 188: Artificial Intelligence Spring Announcements

Algebra 1B notes and problems March 12, 2009 Factoring page 1

Final Review Sheet. B = (1, 1 + 3x, 1 + x 2 ) then 2 + 3x + 6x 2

Spatial analysis in XML/GML/SVG based WebGIS

Note that we are looking at the true mean, μ, not y. The problem for us is that we need to find the endpoints of our interval (a, b).

Getting Started with Communications Engineering

2 Discrete Dynamical Systems (DDS)

Free Pre-Algebra Lesson 15! page 1

MATH240: Linear Algebra Review for exam #1 6/10/2015 Page 1

The Pumping Lemma: limitations of regular languages

Build an Atom Webquest

Solving with Absolute Value

Active loads in amplifier circuits

Math 31 Lesson Plan. Day 5: Intro to Groups. Elizabeth Gillaspy. September 28, 2011

Techniques of Java Programming

Finite Automata Part One

Finite Automata Part One

PEANO AXIOMS FOR THE NATURAL NUMBERS AND PROOFS BY INDUCTION. The Peano axioms

highlights proof by contradiction what about the real numbers?

The Derivative of a Function

Python. Tutorial. Jan Pöschko. March 22, Graz University of Technology

L435/L555. Dept. of Linguistics, Indiana University Fall 2016

One-to-one functions and onto functions

MATH 341 MIDTERM 2. (a) [5 pts] Demonstrate that A and B are row equivalent by providing a sequence of row operations leading from A to B.

Bay Area Scientists in Schools Presentation Plan

Lesson 8: Graphs of Simple Non Linear Functions

Isomorphisms and Well-definedness

Math 31 Lesson Plan. Day 16: Review; Start Section 8. Elizabeth Gillaspy. October 18, Supplies needed: homework. Colored chalk. Quizzes!

Preface.

Mining Data Streams. The Stream Model. The Stream Model Sliding Windows Counting 1 s

Solution to Proof Questions from September 1st

Please note that, as always, these notes are really not complete without diagrams. I have included a few, but the others are up to you.

Convolutional Coding LECTURE Overview

Introduction to ecosystem modelling Stages of the modelling process

Math 416, Spring 2010 The algebra of determinants March 16, 2010 THE ALGEBRA OF DETERMINANTS. 1. Determinants

Chapter 1. Making algebra orderly with the order of operations and other properties Enlisting rules of exponents Focusing on factoring

Proof Techniques (Review of Math 271)

Basic Linear Algebra in MATLAB

Supplementary Material

4.5 Integration of Rational Functions by Partial Fractions

Introducing GIS analysis

Transcription:

SideNail Martín Schonaker, Santiago Martínez March 24, 2010

2

Chapter 1 Quickstart 1.1 Hello, World! Listing 1.1 shows the simplest mapping example one can build with SideNail. The example shows how to query the complete student table. The contents of the table are dynamically mapped as the students list. // Obtain a database connection. // java. s q l. Connection connection =... // S t a r t t he S i d e N a i l s e s s i o n. S i d e N a i l. s t a r t ( ) ; // Set t he c u r r e n t connection ( can s w i t c h at any p o i n t ). S i d e N a i l. setconnection ( connection ) ; // Query. List <?> s tudents = S i d e N a i l. map( s e l e c t from student ) ; // Do something r e f l e c t i v e with s t u d e n t s... // Finish t he S i d e N a i l Session. S i d e N a i l. end ( ) ; Listing 1.1: Simple mapping example. In the listing, the first (commented) part states that you need a database connection (java.sql.connection) to start. It doesn t matter (from the SideNail point of view) if you obtain it through driver manager java.sql.drivermanager or through a datasource javax.sql.datasource. Once you ve obtained a connection you re almost ready to perform the mapping. But before you need to tell SideNail what will be the scope of the 3

4 CHAPTER 1. QUICKSTART dynamic objects you are creating. To do so, you need to invoke methods SideNail#start() and SideNail#end(). With the scope already declared, you can now map database queries (not only tables). It is quite probable that you always perform like in the above example: query the database (SideNail#map(String)) and do something with the gather data. Since the classes SideNail creates are not known until runtime, you ll have to perform something with the Java reflection API. Here s the explanation of what s really happening. SideNail will create a prepared statement with the text you introduced for the query. Will execute the query in the given connection. Once the result has arrived, SideNail will create, compile, and load a class for it. A unique class only known at runtime, since you re query is only known at runtime. For each row in the result, SideNail will create an object and fill a collection with them. Benefits? lesser boilerplate code. Drawbacks? you can only access the objects through reflection, since their class is not known at compile-time 1. 1.2 Accessing Results The classes created for the queries results are standard Javabeans. This means that you will be able to use several reflection-based APIs used for them, such as JSP with EL, Velocity, Flexjson, XMLEncoder, etc, etc, etc. just to mention a few. However for the simpler tasks, SideNail provides two helpful methods: SideNail#set(Object, String, Object) and SideNail#get(Object, String). 1.3 Querying The listing 1.3 show how to use arguments to prevent SQL-injection. Arguments are varargs so for every parameter in the query (indicated with? ) you should put an argument with the value. Objects to use depend on the types de database driver can handle. They are just like in java.sql.preparedstatement. // Returns the s t u d e n t s whose name c o n t a i n s A. List <?> s tudents = S i d e N a i l. map( s e l e c t from student where name l i k e?, %A% ) ; Listing 1.2: Querying with arguments. There are a few more handy methods when querying. SideNail#scalar(String) (and its parameterized counterpart SideNail#scalar(String, Object...)) allows to query a scalar value from the database, just like in listing 1.3. 1 But keep reading there s also typed mapping in SideNail.

1.4. TYPED MAPPING 5 // Returns the s t u d e n t s whose name c o n t a i n s A. Long count = ( Long ) S i d e N a i l. s c a l a r ( s e l e c t count ( ) from student where name l i k e?, %A% ) ; Listing 1.3: Querying scalars. SideNailexecute(String) (and its parameterized counterpart SideNail#execute(String, Object...)) allows you to execute update queries, like DDL queries, updates, insertions, deletions, etc. This is when you don t expect any result, the execution is just enough. 1.4 Typed Mapping When you need strong-type checking, just tell SideNail what class you need to use (check listing 1.4). Then you can access the beans properties without having to exclusively use a reflective API. // Obtain a database connection. // java. s q l. Connection connection =... // S t a r t t he S i d e N a i l s e s s i o n. S i d e N a i l. s t a r t ( ) ; // Set t he c u r r e n t connection ( can s w i t c h at any p o i n t ). S i d e N a i l. setconnection ( connection ) ; List <Country> c o u n t r i e s = S i d e N a i l. map( Country. class, s e l e c t l i m i t 0 3 from country order by code ) ; // Do something not n e c e s s a r i l y r e f l e c t i v e with c o u n t r i e s... // Finish t he S i d e N a i l Session. S i d e N a i l. end ( ) ; Listing 1.4: Simple typed mapping example. 1.5 CRUD Since version 0.3, SideNail is able to perform simple CRUD operations. Here s an example. Not much to comment. Object country = S i d e N a i l. c r e a t e ( COUNTRY ) ;

6 CHAPTER 1. QUICKSTART S i d e N a i l. s e t ( country, name, SideLand ) ; S i d e N a i l. s e t ( country, code, SL ) ; S i d e N a i l. s e t ( country, area, I n t e g e r. valueof (20) ) ; S i d e N a i l. s e t ( country, province, SideLand ) ; S i d e N a i l. s e t ( country, population, I n t e g e r. valueof ( 2 ) ) ; S i d e N a i l. s e t ( country, c a p i t a l, Orm ) ; S i d e N a i l. i n s e r t ( country ) ; Long count = ( Long ) S i d e N a i l. s c a l a r ( s e l e c t count ( ) from COUNTRY where CODE =? and NAME =?, SL, SideLand ) ; a s s e r t 1L == count. longvalue ( ) ; S i d e N a i l. s e t ( country, name, SideNailLand ) ; S i d e N a i l. update ( country ) ; count = ( Long ) S i d e N a i l. s c a l a r ( s e l e c t count ( ) from COUNTRY where CODE =? and NAME =?, SL, SideNailLand ) ; a s s e r t 1L == count. longvalue ( ) ; count = ( Long ) S i d e N a i l. s c a l a r ( s e l e c t count ( ) from COUNTRY where CODE =? and NAME =?, SL, SideLand ) ; a s s e r t 0L == count. longvalue ( ) ; S i d e N a i l. d e l e t e ( country ) ; count = ( Long ) S i d e N a i l. s c a l a r ( s e l e c t count ( ) from COUNTRY where CODE =? and NAME =?, SL, SideNailLand ) ; a s s e r t 0L == count. longvalue ( ) ; Listing 1.5: CRUD operations.

Chapter 2 Advanced Features 2.1 Collection Reuse 2.2 Structured Mapping 2.2.1 Simple Structured Mapping 2.2.2 Typed Structured Mapping 2.2.3 Hybrid Structured Mapping 2.3 Class-Definition Manipulation 2.3.1 Adding, Removing and Modifying Properties 7

8 CHAPTER 2. ADVANCED FEATURES 2.4 Relationship Mapping 2.4.1 One-To-One Mapping 2.4.2 One-To-Many Mapping 2.4.3 Inheritance Mapping

Chapter 3 Experimental Features 3.1 Join Mapping 3.2 One-shot Paging 9