Skip to main content

Posts

Showing posts from November, 2012

Oracle Materialized Views

In the time I was feeling tired of writing blog(you know, no comments, no click), someone clicked my ads and I actually earned about $2 today. I hope you find something fun and for whatever reason, thank you. You gave me the power to continue my blog :)

I've being using Oracle for about 10 years, I never realized there is something called Materialized Views until I chat with my supervisor today.

So, what is Materialized Views?
From the help center: A materialized view is a database object that contains the results of a query. The FROM clause of the query can name tables, views, and other materialized views. Collectively these objects are called master tables (a replication term) or detail tables (a data warehousing term). This reference uses "master tables" for consistency. The databases containing the master tables are called the master databases.
In my understanding, it's a just a snapshot at the time people run the query statement.

I also noticed other item called…

Learning Dojo: Scripting Widgets

What Exactly is a Widget?
Dijit components are handy encapsulations or user interface functionality. That's what made Visual Basic's component based technology so appealing twenty years ago.

Widgets are components in the abstract sense, but what are they from a coding standpoint?
So far, we have a vague idea, at least for the declarative case, that a widget is a snippet of HTML with a dojoType, like this:

<div dojoType="dijit.layout.ContentPane" href="http://localhost/too/many/slashes.html" ></div>

There are four main ways to get a widget refrence:

You can set the jsId= attribute in the tag, which creates a global JavaScript variable with that nameYou can use dijit.byId(id). This is sueful if you had set the id= attribute on your widgetYou can use dijit.byNode(nodeVariable) when you don't have the id attribute but you have the DOM node itself. You can usually get the node with dojo.querySimilarly, dijit.getEnclosingWidge(nodeVariable)  will g…

Learning Dojo: Compression

By default, build compresses any packaged resources and does not compress any other resources. Both of these behaviros can be controlled by the command-line options layerOptimize( for packaged resources) and optimize( for all other resources). The possible values for these options are as follows.


"" Don't compressshrinksafe: Use Dojo-Rhino to delete whitespace and comments and shorten variable namesshrinksafe.keeplines: Same as shrinksafe, but keep newlines.packer: Use the Dean Edwards packer. Whenever build compresses a resource, it writes both an uncompressed version to module-name.js.uncompressed.js and a compressed version to module-name.js
Compressing javaScript Resources with Dojo-Rhino Dojo-Rhino walks a Rhino-generated parse tree and dumps compressed JavaScript code. The compression function can be called from the command line to compress an individual file. This technique for compressing JavaScript is both powerful and safe. Since the  routines that execute the c…

Learning Dojo: Defining Classes with dojo.declare

JavaScript doesn't explicitly include the concept of classes, yet the core language can be used to build object systems that work similarly to those found in languages that include native support for object-oriented programming(Java, Ruby and the rest).

Building a calss definition system is a lot of work. Fortunately, Dojo does this for you. dojo.declare defines class definition machinery, complete with single-inheritance, mixins, two-phase construction, and several other features.

Since javaScript is a dynamic language, it can generate code on the fly that can be consumed immediately.

The way using in JavaScript:
 A good understanding of core JavaScript language concepts is required to use Dojo's class definition machinery effectively. Let's review a few concepts before start.

Prototypes and prototypal Inheritance.

Every object in JavaScript includes a reference to anther object termed the first object's prototype. Since the prototype is another object itself, it also …

Learning Dojo: Dojo Remote Scripting

Native Remote Scripting
There are three well-known methods to implement native remote scripting:

Using an XMLHttpRequest(XHR) objectDynamically loading an iframe elementDynamically loading a script element


XHR (XmlHttpRequest)

XHR is easy to use naively but hard to use correctly. Some of its many weirdisms include the following:

An unfamiliar syntax. Many developers simply copied and pasted XHR code snippets but had no idea what the code was doing. That makes debugging... ehhhh, not so fun.Poor handling of content types. Though XHR is supposed to speak XML fluently, you colud hand back valid XML from the server and still get a head-scratching " Not valid XML" message from XHR.No help in creating the parameter string. You had to do all the URL encoding yourself, or perhaps you didn't do it at all.. and the first & in a textbox broke your application. Dojo's remote scripting facilities enable a client-side script to communicate with a server without a page reload. Ther…

Learning Dojo: Improved Form Controls

Validating Fields
Client-side data validation is win-win: it helps you by keeping the data clean and helps the user by giving immediate, targeted feedback.

We need some data cleaning, so let's start with the fields on the Personal Data tab. First start with a regular <input> or <textarea> tag.

Add a dojoType= arrtibute of dijit.form.ValidationTextBox. Then add validations and filed-cleansing attributes:

<label for="first_name">First Name:</label>
<input type="text" name="first_name" id="first_name" dojoType="dijit.form.ValidationTextBox" trim="true"
propercase="true" required="true" size="30" missingMessage="You must enter your first name" /><br/>

And don't forget to add dojo.require to the header:
dojo.require("dijit.form.ValidationTextBox" );

These extra attributes do an incredible amount of work:

required="true" makes the…

Learning Dojo: Laying Out the Form

Let's take tab for example:


<script>
dojo.require("dojo.parser" );
dojo.require("dijit.layout.ContentPane" );
dojo.require("dijit.layout.TabContainer" );
</script>
</head>

The two components we need, again, are as follows:

A dijit.layout.ContentPane, which holds one "tabful" of data. Each ContentPane has a lable that appears on the tab. A dijit.layout.TabContainer, which holds a group of ContentPanes.


<div dojoType="dijit.layout.ContentPane" title="Personal Data">
<label for="first_name">First Name:</label>
<input type="text" name="first_name" id="first_name" size="30" /><br/>
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" id="last_name" size="30" /><br/>
<label for="middle_initial">Middle Initial:</label&…

Learning Dojo: Add Dojo and Dijit to a page

Step 1: Add the standard Dojo Headers
<style type="text/css">
@import "/dojoroot/dijit/themes/tundra/tundra.css" ;
@import "/dojoroot/dojo/resources/dojo.css"
</style>

<script type="text/javascript" src="/dojoroot/dojo/dojo.js"
djConfig="parseOnLoad: true" ></script>

In Dijit Terminology, a them is a set of fonts, colors, and sizing settings for components so they look good together. Three themes come prepackaged with Dijit - Tunra, Sorta, and Nihilo - and you can develop your own themes as well.

The <script> tag pulls the Dojo code from your server. The djConfig="parseOnLoad:true" attribute is required to use Dojo elements decoratively.

Step 2: Set the Class of the Body
</head>
<body class="tundra">

The class name will match the theme name in lowercase: tundra, soria ornihilo.

Step 3: Add dojo.require Statements.

<script type="text/javascript">
do…

Learning iBATIS - Using the Spring DAO

The Spring framework supports iBATIS using a template pattern for the data access objects, meanig that you start with an existing Spring class(SqlMapClient Template) and extend it for your DAO. using this technique, our AccountDao implementation would look like below example using Spring.


public class AccountDaoImplSpring extends SqlMapClientTemplate implements AccountDao
{
public Integer insert(Account account) {
return (Integer) insert("Account.insert", account);

}
public int update(Account account) {
return update("Account.update", account);
}
public int delete(Account account) {
return delete(account.getAccountId());
}
public int delete(Integer accountId) {
return delete("Account.delete", accountId);
}
public List<Account> getAccountListByExample(
Account account) {
return queryForList("Account.getAccountListByExample", account);
}
public List<Map<String, Object>>
getMapListByExample(Account account) {
return queryForList(&…

Learning iBATIS - Data Access Objects

Applications often need to access data from mulitple data sources(e.g. database, web service,ldap). Each of the data stores has a different API to access the underlying storage mechanism, along with a whole set of idiosyncrasies.

The DAO pattern is used to hide the unique implementation quirks of these APIs. It provides a simple and common API for application developers so that the consumers of the data can be free of the complexities of the data access APIs.

A simple example of using iBATIS
#1 Dao.xml
The DaoManager class is configured using the Dao.xml configuration file(as below)



<daoConfig>
 <context id="example">
  <transactionManager type="SQLMAP">
    <property name="SqlMapConfigResource"
    value="examples/SqlMapConfig.xml"/>
  </transactionManager>
   <dao interface="examples.dao.AccountDao"
implementation="examples.dao.impl.AccountDao"/>
  </context>
</daoConfig>

#2 Java…

Learning iBATIS - Using Dynamic SQL

In SQL, an equal sign(=) cannot be used to compare null equalities. The IS keyword is needed to successfully test for the equality with a NULL. Since we want to use the same SQL statement to handle both NULL and non-NULL comparisons, we will use Dynamic SQL to accomplish this with one mapped statement. For example,
<select id="getChildCaategories" parameterClass="Category" resultClass="Category">
   select * from category
  <dynamic prepend=" Where ">
     <isNull property="parentCategoryId">
       parentCategoryID is NULL
     </isNull>
    <isNotNull property="parentCategoryId">
      parentCategoryId=#parentCategoryId#
    </isNotNull>
  </dynamic>
</select>

# The <dynamic> tag
prepend(optional): This value is used to prepend to the tag's resulting body content. The prepend value will not be prepended when the tag's resulting body content is empty
open(optional) :…

Learning iBATIS - Transactions

Transactions are one of the most important concepts to understand when working with a relational database.

What is a transaction?
In the simplest terms, a transaction is a unit of work usually involving a number of steps that must succeed or fail as a group. Should any step in the transaction fail, all steps are rolled back so that the data is left in a consistent state.

Transaction can be very small and basic, perhaps consisting of only a couple of SQL statements that change data in a single table of a single database. However, transaction can also become very large and complext. A business-to-business transaction could even leave the realm of computers and require physical interaction with human beings(e.g. a signature). The topic of transactons could easily fill a book of its won, so we'll only consider four scopes of transactions that iBATIS supports:
 #1 Automatic - For simple, single statements that don't require an explicitly demarcated transaction.
 #2 Local - A simple…

Learning iBATIS - Complex collections

Normally, we only worked with a single object type in the results, even when joining multiple tables. If you have more complex objects, you can also use iBATIS to load them.

This capability is useful if you like to have your application's model look like your data model. It is possible to use iBATIS to define your data model in terms of related objects, and have iBATIS load them all at once. For example, if you have a database in which Account records have related Order records that have related Orderitem records, those relationships can be set up so that when you request an Account, you also get all of the Order objects and all of the OrderItem objects as well.


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Ch6">

<!-- Part 1 -->
<resultMap id="ResultAccountInfoMap" class…

Learning iBATIS -Using XML with iBATIS

Sometimes, you may need to work with XML-based data. The iBATIS framework will allow you to use XML when passing parameters into a query, and also for returning results from them. In both cases, it probably does not add much value to use XML where you do not need to - using a plain old Java Object(POJO) instead is much more efficient in most cases.

XML parameters
Using XML to pass parameters into a mapped statement can be accomplished with either a STring value or a DOM object, both of which use the exact same structure. For example:
<parameter><accountId>3</accountId></parameter>


<select id="getByXmlId" resultClass="Account" parameterClass="xml">
select
accountId,
username,
password,

firstName,
lastName,
address1,
address2,
city,
state,
postalCode,
country
from Account
where accountId = #accountId#
</select>

Java Codes:
String parameter = "<parameter><accountId>3</accountId></parameter>"…

Dojo & jQuery side by side. Part 2: Animation

Posted by Christopher Imrie in Code 2 Comments This is the second part of our Dojo and jQuery side by side series. If you’re not following allowing with the series, do be sure to check out Part 1: Dom Basics. As mentioned in the previous article, the aim here is to provide a simple unbiased side by side comparison of common jQuery operations and how they are achieved in Dojo. Today, we’re looking at animation and as a quick reminder you should assume that all the calls below are called when the DOM is ready.  If you’re not sure how to do this, checkout Part 1. Lets go! Fading elements in and out This tends to be the workhorse for many beginner javascript programmers.  Simply select the element you want and then the javascript library will do the rest.  jQuery is more succinct here since it assumes you want the animation to start straight away whereas dojo assumes you will want to trigger it later using the play method.  Dojo can be told to start automatically by providing the “auto” …

Dojo & jQuery side by side. Part 1: DOM Basics

February 9th 2012 Posted by Christopher Imrie in Code Dojo is a fantastic toolkit that we have used on many projects here at moresoda.  Although we still love and use jQuery nearly everyday, we use Dojo on projects where the front end requirements are more complicated than your average DOM manipulation and HTML5 shims. This article isnt about preaching Dojos benefits though.  If you have a read of the features and benefits of Dojo you can make up your own mind.  That being said, Dojo can be harder to get into since is it a much larger than jQuery. Hence my aim here is to provide a simple, unbiased side by side comparison of common jQuery operations and how they are achieved in Dojo. Lets go! Loading the script from the Google CDN Both can be loaded from the Google CDN.  If you use any components of Dojo that are not part of Dojo Base (the file being loaded by the script tag below), they will be dynamically pulled from the CDN as well. //jQuery <script src="http://ajax.googleapis…