之前寫了一篇displayObject轉成bitmap的文章,最近在整理電腦時,將以前做過的測試整理,因此將其轉成工具類別便於日後使用,程式碼如下:
package com.tools.graphics
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
public class LoaderToBitmap
{
/**
*建構式參數使用一個內隱類,避免使用者建立實體,
*因為as3不能使用private給予建構式的關係,
*但是使用者若給予null之後依然會被執行super()的建構式,所以無法避免得很完全。
*/
public function LoaderToBitmap(dontCreate:DontCreate)
{
}
static public function cloneBitmap(display:DisplayObject):Bitmap
{
var bitmap:Bitmap = new Bitmap(cloneBitmapData(display));
return bitmap;
}
static public function cloneBitmapData(display:DisplayObject):BitmapData
{
var bitMapData:BitmapData = new BitmapData(display.width , display.height);
bitMapData.draw(display);
return bitMapData;
}
}
}
class DontCreate
{
public function DontCreate()
{
}
}
//在Flex4 SDK環境下,使用範例
2010年12月31日 星期五
2010年10月8日 星期五
個人學習MongoDB後,對於document的認知
- A document is the basic unit of data for MongoDB, roughly equivalent to a row in a relational database management system (but much more expressive).
- Similarly, a collection can be thought of as the schema-free equivalent of a table.
- A single instance of MongoDB can host multiple independent databases, each of which can have its own collections and permissions.
- MongoDB comes with a simple but powerful JavaScript shell, which is useful for the administration of MongoDB instances and data manipulation.
- Every document has a special key, "_id", that is unique across the document’s collection.
collection很好理解但document就字面上有點難理解,但看完Java Driver運作方式後,對document我的認知如下:
MongoDB的document長像是JSON的格式,document在RDBMS上如同是一個row。
{
"name" : "MongoDB",
"type" : "database",
"count" : 1,
"info" : { x : 203, y : 102 }
}
在mongoDB java Driver使用上要寫入如上JSON格式資料的語法如下:
//建立最外層key:value,此時還不是完整的parent document
BasicDBObject doc = new BasicDBObject();
doc.put("name", "MongoDB");
doc.put("type", "database"); doc.put("count", 1);
//建立info的sub document
BasicDBObject info = new BasicDBObject();
info.put("x", 203);
info.put("y", 102);
//將sub document寫入doc使其成為完整的parent document.
doc.put("info", info);
//將這個完整的parent document插入到collection,這個collection類似RDBMS的table.
coll.insert(doc);
由程式邏輯來理解
我認為由最外層來看這個結構是一個parent document
{
"name" : "MongoDB",
"type" : "database",
"count" : 1,
"info" : { x : 203, y : 102 }
}
//而info的value也是一個document,就是parent document裡再包含了一個sub document.
{ x : 203, y : 102 }
因此整個JSON格式就可以看成是RDBMS裡的一個row,對於想從mongoDB拿資料的程式來說這一個最外層就是一個document,而對於mongoDB自己內部來說內層那個info也是一個document。
從程式邏輯來看能理解MongoDB的資料結構了,但我無法很明白的來敘述這種關係,並且理解也可能有誤解,不過當由程式直接操作來看,document到底是什麼就變得不是那麼重要,有點張無忌學太極拳、劍,最後無招勝有招。
{
"name" : "MongoDB",
"type" : "database",
"count" : 1,
"info" : { x : 203, y : 102 }
}
在mongoDB java Driver使用上要寫入如上JSON格式資料的語法如下:
//建立最外層key:value,此時還不是完整的parent document
BasicDBObject doc = new BasicDBObject();
doc.put("name", "MongoDB");
doc.put("type", "database"); doc.put("count", 1);
//建立info的sub document
BasicDBObject info = new BasicDBObject();
info.put("x", 203);
info.put("y", 102);
//將sub document寫入doc使其成為完整的parent document.
doc.put("info", info);
//將這個完整的parent document插入到collection,這個collection類似RDBMS的table.
coll.insert(doc);
由程式邏輯來理解
我認為由最外層來看這個結構是一個parent document
{
"name" : "MongoDB",
"type" : "database",
"count" : 1,
"info" : { x : 203, y : 102 }
}
//而info的value也是一個document,就是parent document裡再包含了一個sub document.
{ x : 203, y : 102 }
因此整個JSON格式就可以看成是RDBMS裡的一個row,對於想從mongoDB拿資料的程式來說這一個最外層就是一個document,而對於mongoDB自己內部來說內層那個info也是一個document。
從程式邏輯來看能理解MongoDB的資料結構了,但我無法很明白的來敘述這種關係,並且理解也可能有誤解,不過當由程式直接操作來看,document到底是什麼就變得不是那麼重要,有點張無忌學太極拳、劍,最後無招勝有招。
2010年10月7日 星期四
MnogoDB JAVA Driver配置
MongoDB Driver官方頁面
Java Driver下載頁面
本文撰寫時Java Driver最新版本為 Version2.1
Step1.下載MongoDB JAVA Driver
@ubuntu:~/Downloads$ wget http://github.com/downloads/mongodb/mongo-java-driver/mongo-2.1.jar
Java Driver下載頁面
本文撰寫時Java Driver最新版本為 Version2.1
Step1.下載MongoDB JAVA Driver
@ubuntu:~/Downloads$ wget http://github.com/downloads/mongodb/mongo-java-driver/mongo-2.1.jar
Step2.建立目錄mongoDriver
於/opt底下建立一個目錄以放置mongo-2.1.jar
@ubuntu:/opt$ sudo mkdir mongoDriver
Step3.將mongo-2.1.jar移至/opt/mongoDriver底下
@ubuntu:~/Downloads$ sudo mv mongo-2.1.jar /opt/mongoDriver/
Step4.開啟Eclipse,開啟一個Java Project
Step5.Libraries中Add External JARs將mongo-2.1.jar加入
//待續
於/opt底下建立一個目錄以放置mongo-2.1.jar
@ubuntu:/opt$ sudo mkdir mongoDriver
Step3.將mongo-2.1.jar移至/opt/mongoDriver底下
@ubuntu:~/Downloads$ sudo mv mongo-2.1.jar /opt/mongoDriver/
Step4.開啟Eclipse,開啟一個Java Project
Step5.Libraries中Add External JARs將mongo-2.1.jar加入
//待續
Linux上配置Eclipse
Eclipse官方網址http://www.eclipse.org/
本篇將會下載 Eclipse IDE for Java EE Developers Linux 64bit
Step1.下載Eclipse for JavaEE Linux64版本
Step2.解開壓縮
@ubuntu:~/Downloads$ tar xzf eclipse-jee-helios-SR1-linux-gtk-x86_64.tar.gz
Step3.將解開資料夾移到/opt底下
@ubuntu:~/Downloads$ sudo mv eclipse /opt/
Step4.執行eclipse
:~/Downloads$ ./|/opt/eclipse/eclipse
本篇將會下載 Eclipse IDE for Java EE Developers Linux 64bit
Step1.下載Eclipse for JavaEE Linux64版本
Step2.解開壓縮
@ubuntu:~/Downloads$ tar xzf eclipse-jee-helios-SR1-linux-gtk-x86_64.tar.gz
Step3.將解開資料夾移到/opt底下
@ubuntu:~/Downloads$ sudo mv eclipse /opt/
Step4.執行eclipse
:~/Downloads$ ./|/opt/eclipse/eclipse
本篇是強迫自己使用Shell命令操作,但在ubuntu下具有桌面環境,可以如下
Step1.直接用fireFox下載,下載完檔案預設上會存放在home下的Downloads目錄裡。
Step2.打開Downloads目錄點擊下載之檔案即可解壓。
Step3.將解壓後之目錄移至/opt底下。
Step4.在eclipse目錄底下有個eclipse執行檔,直接點擊即可開啟eclipse。
Step5.替eclipse建立捷徑在ubuntu桌面上。
2010年10月5日 星期二
mongoDB與MySQL 指令比較
閱讀紀錄
MySQL Program → Mongo Program
MySQL Statement → Mongo Statement
插入
MySQL Program → Mongo Program
- mysqld → mongod (啟動DB)
- mysql → mongo (DB連線,進入 Shell操作模式)
MySQL Statement → Mongo Statement
插入
- INSERT INTO users VALUES(2,3) →
db.users.insert({a:2,b:3})
搜尋全部
- SELECT * FROM users →
db.users.find()
SELECT0
- SELECT a,b FROM users →
db.users.find({},{a:2,b:3})
SELECT1
- SELECT * FROM users WHERE age=30 →
db.users.find({age:30})
SELECT2
SELECT3
- SELECT * FROM users WHERE age=30 ORDER BY name → db.users.find({age:33}).sort({name:1})
SELECT4
- SELECT * FROM users WHERE age>30 →
db.users.find({'age':{$gt:30}})
SELECT5
- SELECT * FROM users WHERE age<30 →
db.users.find({'age':{<:30}})
SELECT6
- SELECT * FROM users ORDER BY name DESC → db.users.find().sort({name:-1})
建立索引
- CREATE INDEX myindexname ON users(name) → db.users.ensureIndex({name:1})
SELECT命令7
- SELECT * FROM users WHERE a=1 and b='q' → db.users.find({a:1,b:'q'})
SELECT命令8
- SELECT * FROM users LIMIT 10 SKIP 20 → db.users.find.limit(10).skip(20)
SELECT命令9
- SELECT * FROM users LIMIT 1 → db.users.findOne()
SELECT命令10
- EXPLAIN SELECT * FROM users WHERE z=3 → db.users.find({z:3}).explain()
SELECT命令11
- SELECT DISTINCT last_name FROM users → db.users.distinct('last_name')
SELECT命令12
- SELECT COUNT(*y) FROM users → db.users.count()
SELECT命令13
- SELECT COUNT(*) FROM users where AGE > 30 → db.users.find({age:{'>':30}}).count()
SELECT命令14
- SELECT COUNT(AGE) FROM users → db.users.find({age:{'$exists':true}}).count()
SELECT命令15
- UPDATE users SET a=1 WHERE b='q' → db.users.update({b:'q'},{$set:{a:1}},false,true)
MongoDB Shell 下的 基本操作指令
(文章來自mongoDB mongo - The interactive章節)
//以下命令都是進入mongoDB Shell環境下使用
//進入Shell用的Linux命令 ./bin/mongo
Special Command Helpers
//以下命令都是進入mongoDB Shell環境下使用
//進入Shell用的Linux命令 ./bin/mongo
Special Command Helpers
Non-javascript convenience macros:
Show help
顯示最上層的幫助文件
- >help
顯示(資料庫)db系列命令的幫助文件
- >db.help()
Show help on collection methods
顯示(集合)myColl系列命令的幫助文件
- >db.myColl.help()
Print a list of all databases on this server
- >show dbs
Set the db variable to represent usage of dbname on the server
切換資料庫
- >use [db_name]
Print a list of all collections for current database
顯示所有的collections (mongoDB的collection 類似 MySQL的table)
- >show collections
Print a list of users for current database
列出當前資料庫用戶
- >show users
Print most recent profiling operations that took >= 1ms
列出最近的操作?
- >show profile
Basic Shell Javascript Operations
//未完
MongoDB Starting the Shell
啟動mongodb的Shell環境
連接本地端機器上的database。
connects to the [database] on 192.168.11.3
connects to the [database] on [IP Address] on [port number]
指定IP位址與使用Port number。
- ./bin/mongo
連接本地端機器上的database。
- ./mongo [database Name]
- ./mongo testdb
connects to the [database] on 192.168.11.3
指定連接特定位址上的database
- ./mongo [IP Address]/[database]
- ./mongo 192.168.11.3/testdb
connects to the foo database on [domainName]
指定連接domainName上的database。
- ./mongo [domainName]/[database]
- ./mongo dbserver.mydomain.com/testdb
connects to the [database] on [IP Address] on [port number]
指定IP位址與使用Port number。
- ./mongo [IP Address]:[Port Number]/[database]
- ./mongo 192.168.11.3:7000/testbase
訂閱:
文章 (Atom)