MDBitz - Matthew Denton
T-SQL
SYBASE Adaptive Server Enterprise (ASE) is a relational model database server, that uses Transact-SQL (T-SQL) as the procedural language for creating, modifying and querying the Databases.
Detailed below is a short overview of how to create tables in an ASE Database Server including auto generating ID SEQUENCES, foreign keys, and unique indexes.
Basic Format
Like other SQL implementations we utilize the create table command to create a new table in the Database:
CREATE TABLE EX_USER (
ID INT not null,
NAME VARCHAR(255) not null,
ACTIVE TINYINT(1) not null,
ROLE_ID INT not null,
USER_NAME VARCHAR(25) not null,
PASSWORD VARCHAR(25) not null
)
How this statement works is that you specify the table name after the create table statement and inside the () you define the various columns in the table with the format of name type identity, null, or not null and optional other modifiers
Identity Columns
When created database tables we often want to create identity columns that are used to designate the row of data. In most cases we also want that column’s value to automatically populate on an insert with its value. In Transact-SQL this is done by the identity keyword. In our example EX_USER table lets modify the ID column to be an identity column by replacing not null with the identity keyword.
ID int identity
Unique Indices
In addition to identifiers to identify the data row in a table we also may want to specify a column to be unique in that every value is only allowed one at a time. This is accomplished by creating a unique constraint. This can be done as a separate statement or appended to the parameters in the create table statement.
CREATE TABLE EX_USER (
ID INT IDENTITY,
NAME VARCHAR(255) not null,
ACTIVE TINYINT(1) not null,
ROLE_ID INT not null,
USER_NAME VARCHAR(25) not null,
PASSWORD VARCHAR(25) not null,
UNIQUE NONCLUSTERED (USER_NAME)
)
The nonclustered part of the statement means do not organize the data in order of the column. If by chance you wanted the data to order itself based on the column you can use the clustered keyword.
Foreign Keys
Foreign Keys are used to define columns whose value is from another table. This guarantees that the value found in the column is a valid value in the other column, and is used for lookup tables as well as for linking data across tables. In our example lets assume that we have a lookup table called EX_RULE that contains all the available user roles. We would have our RULE_ID column link to the table by the use of the references keyword.
RULE_ID INT not null REFERENCES EX_RULE(ID)
References
Adaptive Server Enterprise, SQL, SYBASE, T-SQL, Transact-SQL
MDBitz - Matthew Denton
Java
What is Spring
Spring is an open source framework created with the purpose of enabling developers to build and deliver applications faster. The Framework is available for both the JAVA and .NET platforms. Spring provides a set of core features that can be used for most applications as well as modules that provide additional features.
Sampling of Modules
- Data Access -
The Data Access Module allows for streamline configuration of Relational Database Management Systems (RDBMS)using JDBC and ORM‘s such as Hibernate and ibatis
- Security | Authentication -
Spring Security Module provides advanced authorization and authentication features to your project/application. Some Key Authentication features being:
LDAP, JAAS, Basic Access Authentication, and Digest Access Authentication
- Model View Controller -
The Model View Controller module provides a MVC framework for use in developing Web Applications.
Initializing Spring from within an Application
To initialize Spring from within an application means to instantiate the ApplicationContext by use of a configuration file. I will not go in to the details as to how to set up the configuration file but will assume that you have created such an xml file called applicationContext.xml.
First Within your application import ApplicationContext and FileSystemXMLApplicationContext classes which will be used to instantiate the Application Context.
import org.springframework.context.ApplicationContext;
import org.springframework.context.support
.FileSystemXmlApplicationContext;
Then we Instantiate the Application Context.
ApplicationContext appContext =
new FileSystemXmlApplicationContext( contextFileName );
Last we utilize the beans defined in our xml file.
MyObject obj= appContext.getBean( "ObjectName" );
Resources
Command Line, Spring, Spring Framework, SpringFramework
Overview
The Factory Pattern is a Software Design Pattern that is used to create an object without calling the specific object’s constructor. This pattern allows a end user to call the factory to instantiate a class without having to know how to instantiate the class itself. How it works is by the creation of a Factory object that contains a get method that returns an Object based on the parameters inputted to it.
To illustrate the pattern imagine you have a database that contains rules that need to be run every so often to ensure the integrity of your system. Next less also assume that each Rule could potentially be a different class but they all implement a common interface with the method execute. Using the Factory Pattern would be a good choice to go with as it would enable you to create new rules without having your engine know what it is running.
In Java we can utilize the Class object to make it so that our factory itself would not have to know about every Rule that it could create. This is done by utilizing the forName and newInstance methods. The Class.forName method takes as a parameter the name of a class and returns a Class Object for the specified class, and if it can’t find the class it throws a ClassNotFoundException. Using the Class Object returned from the forName method we can then call newInstance to instantiate the object.
Now to guarantee that you are instantiating a rule object and not just any object you could make use of an interface. This way when you instantiate the class you can cast it as the interface, and if this object doesn’t implement the interface then a ClassCastExeption would be thrown.
Java Example
Rule Intrface
package com.mdbitz
/*
* Import Statements
*/
import java.util.List;
public interface IRule {
/**
* This is a set of init params which will be used
* to seed the rule
*
* @param initParams
*/
public void init(List initParams)
throws IllegalArgumentException;
/**
* This is the main business method of the rule
* @return
*/
public Boolean execute();
}
RuleFactory
package com.mdbitz;
/**
* This class is a factory which instantiates the rules
*
*/
public class RuleFactory{
/**
* Private constructor to enforce that it cannot be
* instantiated
*
*/
private RuleFactory(){
super();
}
/**
* This method initializes a Rule Class
* @param Name of the Class
* @return IRule
*/
public static IRule getRule( String className )
throws ClassNotFoundException,ClassCastException,
IllegalAccessException,InstantiationException{
IRule rule = null;
try{
Class implementationClass = Class.forName(className);
rule = (IRule)implementationClass.newInstance();
if(!implementationClass.isInstance(rule)){
throw new ClassCastException(
rule.getClass().getName()+
" is incompatible with "+className);
}
}catch(ClassNotFoundException cnfe){
throw new ClassNotFoundException(
"In RuleFactory >> "+ruleClassName+
" not found",cnfe );
}catch(ClassCastException cce){
throw new ClassCastException(
"In RuleFactory >>" +ruleClassName+
" does not implement required interface" +
" IRule\n In"+cce.getMessage() );
}
return rule;
}
}
Calling the Factory
RuleFactory.getRule( "com.mdbitz.SpecificRule" );
Class Object, Factory Pattern, Interfaces
MDBitz - Matthew Denton
Flash
When developing in Flash we often find ourselves developing straight code based animations as well as time-line animations. And when creating the time-line based animations we often find ourselves wishing to play the animation in reverse in certain occasions.
Unfortunately Flash does not have reverse capability built in, Yes it has the prevFrame() method which could be used with the onEnterFrame() event to play in reverse but this method is not as straightforward as a developer would wish and is easily prone to bugs do to the amount of state checking.
Luckily for us developers that use a Tweening library such as TweenLite and TweenMax (available at greensock.com ) provides us an easy to use interface for playing our animations forward and reverse to any desired location. To accomplish this we use the Frame and FrameLabel plugins. These plugins allow us to tween to a desired frame or labeled frame respectively.
A quick example of how to use is:
TweenLite.to( moviclip, 1, { frame:40 } );
TweenLite.to( movieclip, 1.5, { frameLabel:"intro" } );
Frame Tweeing, MovieClip Reverse Timeline, TweenLite, TweenMax
MDBitz - Matthew Denton
Flash
In Flash Applications we sometimes find ourselves having to split an image up into slices. To accomplish this simple task we utilize bitmaps to copy data from a section of the main graphic to create bitmaps of the different slices or pieces. Outlined below are the steps and code that are used to complete this task.
How to Slice a Bitmap
Before slicing a bitmap can begin we need to know 3 things:
- image – the bitmap graphic we will be slicing
- numColumns – the number of columns to be sliced from the graphic
- numRows – the number of rows to be sliced from the graphic
Knowing this information we can easily create a grid of bitmaps (2 dimensional array) containing the slices.
- Determine the width and height of the resulting slices
var iWidth:Number = image.width;
var iHeight:Number = image.height;
var pWidth:Number = iWidth / numColumns;
var pHeight:Number = iHeight / numRows;
- initialize the image array that will hold the resulting slices, and some other properties to be used when creating the bitmaps.
var iArray:Array = new Array();
var rectangle:Rectangle();
var bitmap:Bitmap;
var bData:BitmapData;
- Iterate over the number of rows and initialize a new Array at the row Index in the image array
for( var rowIdx:int = 0; rowIdx < numRows; rowIdx++ ) {
iArray[rowIdx] = new Array();
}
- After initializing the 2nd level array for the row index iterate over the number of columns
for( var rowIdx:int = 0; rowIdx < numRows; rowIdx++ ) {
iArray[rowIdx] = new Array();
for( var colIdx:int = 0; colIdx < numColumns; colIdx++ ) {}
}
- Inside the column iterator we know create our bitmap data for that slice
- Initialize a new BitmapData with dimensions set to the width and height calculated in step 1
bData = new BitmapData( pWidth, pHeight, true, 0x00000000 );
- Create a new Rectangle that is positioned by the offset of the current slide and has width and height equal to the value calculated in step 1
rectangle = new Rectangle( colIdx * pWidth, rowIdx * pHeight, pWidth, pHeight );
- Copy the bitmap data of the rectangle from the original graphic which is the data for the current slice
bData.copyPixels( image.bitmapData, rectangle, new Point( 0, 0 ) );
- create a new Bitmap from the bitmap data
bitmap = new Bitmap( bData );
- Add the bitmap to the grid at the current row and column index
iArray[rowIdx][colIdx] = bitmap;
- The resulting grid contains bitmaps of all the slices
The Completed Code
var iWidth:Number = image.width;
var iHeight:Number = image.height;
var pWidth:Number = iWidth / numColumns;
var pHeight:Number = iHeight / numRows;
var iArray:Array = new Array();
var rectangle:Rectangle();
var bitmap:Bitmap;
var bData:BitmapData;
for( var rowIdx:int = 0; rowIdx < numRows; rowIdx++ ) {
iArray[rowIdx] = new Array();
for( var colIdx:int = 0; colIdx < numColumns; colIdx++ ) {
bData = new BitmapData( pWidth, pHeight, true, 0x00000000 );
rectangle = new Rectangle( colIdx * pWidth, rowIdx * pHeight, pWidth, pHeight );
bData.copyPixels( image.bitmapData, rectangle, new Point( 0, 0 ) );
bitmap = new Bitmap( bData );
iArray[rowIdx][colIdx] = bitmap;
}
}
ImageSlicer Utility to Slice Images
To make this process easier for myself and those that find themselves needing to slice an image, I have create the ImageSlicer utility class. This class contains a static method that you pass the graphic, number of columns, and number of rows to and it returns the 2 dimensional array. You can download the ImageSlicer utility here
An example usage is shown below but remember you need to import the class by statement import com.mdbitz.utils.ImageSlicer;
var bitmaps:Array = ImageSlicer.sliceImage( graphic, this._numColumns, this._numRows );
AS3, Bitmaps, Image Slicing, ImageSlicer
|
|