Leveraging ColdFusion's Java Foundation

īģŋ7/8/08

Types

? Types map to runtime classes

? Struct: java.util.Map: coldfusion.runtime.Struct

Leveraging ColdFusion's Java Foundation

? Array: java.util.List: coldfusion.runtime.Array

? Query: coldfusion.runtime.QueryVector

? List: java.lang.String

Elliott Sprehn

elliott@



? String: java.lang.String

? Number: java.lang.String, java.lang.Integer, java.lang.Double

? Component: coldfusion.runtime.TemplateProxy (more about this later)

? Java Object: coldfusion.runtime.java.JavaProxy

? Casting Handled by coldfusion.runtime.Cast

Structs (java.util.Map)

Specialized Structures

? Can use methods of Map

? TreeMap / LinkedHashMap

? get(key)

? put(key,value)

? putAll( struct )

? Same as structAppend() but without option to not replace

? containsKey( key )

? containsValue( value )

? DoesnĄ¯t work well on complex data types like CFCs

Note: these donĄ¯t enforce string keys!

? Preserve order of inserted keys

? IdentityHashMap

? Uses key identity instead of equality.

? Stack / Queue

? More complex data structures with better performance!

? Not Synchronized!!!

? Unpredictable behavior if methods used across threads.

? Need to use Collections.synchronizedMap() to fix this.

? Not always a good idea to sync it.

? Slower / Loses some methods that may be specific to type

1

7/8/08

How would we (re)implement the Struct type?

Lists (java.util.List)

? Can use methods of List

LetĄ¯s see the code!

StructDo() ?

?

?

?

?

?

?

get(key)

add(value)

addAll( array )

set( index, value )

contains( key )

indexOf( value )

? DoesnĄ¯t work well on complex data types like CFCs

Note: Indexes start at ZERO!

Reference Arrays

Queries (java.sql.ResultSet)

? By default arrays are copied on assignment

? Lots of hidden functions

? Java collection types are NOT copied!

? Improve performance

? Can use this to create an array collection that is passed

around and modified.

? Dangerous in non-trusted code... assumptions.

? What is there?

? java.util.LinkedList

? java.util.ArrayList

? java.util.Vector

? Only synchronized list available.

?

?

?

?

?

?

getColumn()

getString() / getDate() / getInt() ...

wasNull()

isBeforeFirst() / isBeforeLast()

isFirst() / isLast()

first() / last()

? Columns are their own data type!

? Usable like arrays

? bound to parent table

? Support isnĄ¯t totally complete...

? DoesnĄ¯t support a lot of methods

2

7/8/08

The toString() Method

Lets look at some code...

? Returns a joined representation of List and Map

? Awesome for cache keys

? Very very fast.

? Can also use serializeJSON() in CF8.

? CanĄ¯t use ToString() ColdFusion function because it expects

simple values.

? ToString(struct) ERROR!

? struct.toString() OK!

Note: Not useful for queries because output doesnĄ¯t contain column values.

Questions

?

3

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download