2009年6月23日星期二

android源码编译

I was devastated by Android these days
let me organize some noticeable points here
(ubuntu 8.10 is used)

1. download Android source code (cupcake)

create home:
:mkdir AndroidHome

install Git:
:sudo apt-get install git-core

install Repo:
:curl http://android.git.kernel.org/repo > ~/AndroidHome/bin/repo
:chmod a+x ~/AndroidHome/bin/repo

install Python:
:sudo apt-get install python

install JDK 1.6:
:cd ~/AndroidHome/downloads
:chmode a+x jdk-6u11-linux-i586.bin
:.jdk-6u11-linux-i586.bin
:cp -R jdk1.6.0_11/ /usr/local/jdk1.6.0_11/
add followings to ~/.bashrc:
:export PATH=/usr/local/jdk1.6.0_11/bin:$PATH
:export JAVA_HOME=/usr/local/jdk1.6.0_11
:export ANDROID_JAVA_HOME=$JAVA_HOME

start to download:

:cd ~/AndroidHome/
:repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
(or :repo init -u git://android.git.kernel.org/platform/manifest.git -b release-1.0 for older version)
:repo sync

2. make Android source code

:make

The following error occurs

external/qemu/sockets.c: In function ?sock_address_init_resolve?:
external/qemu/sockets.c:637: error: ?EAI_NODATA? undeclared (first use
in this function)
external/qemu/sockets.c:637: error: (Each undeclared identifier is
reported only once
external/qemu/sockets.c:637: error: for each function it appears in.)

solution:

add “#if …” and “

2009年6月21日星期日

cygwin下载android源码经常断

google了一把,用cygwin下载android源码,速度还行,至少比我win7里安装个ubuntu下载来的快!但是不好的就是老断,整个自动重连的sh比较合适:
 
#!/bin/bash
echo "======start repo sync======"
python ./bin/repo sync
while [ $? = 1 ]; do
        echo "======sync failed, re-sync again======"
        sleep 3
        python ./bin/repo sync
done

windows下用Cygwin下载android源代码

如果/home目录没有创建,可以如下操作:1.在D:\cygwin安装目录下新建目录:home,2.在windows高级属性增加HOME变量,HOME=D:\cygwin\home,3.拷贝文件,打开D:\cygwin\etc\skel目录,拷贝下面三个文件到D:\cygwin\home,这样在cygwin终端执行,echo $HOME 查看即可

首先下载cygwin,cygwin是一个类linux平台。即在windows环境下模拟linux终端。比起运行linux虚拟机,是一个轻量 的解决办法。除了本文用来下载android源码,你当然可以用它来学习linux。cygwin的中文网是http://www.cygwin.cn /,建议从这下载cygwin,这是国内最快的镜像站点。严格按网站的说明安装:http://www.cygwin.cn/site/install /,最后注意的是在安装说明的下一步操作是选择需要下载的工具库,缺省是是default,鼠标点 击default,会把安装类别切换成install,这样才能安装下载android源码需要的所有工具。当然,如果你熟悉所有情况,你可以手工在工具 库里选择你要安装的库(库是很多的,安装程序又没有提供全部选择或者全部取消的功能,我奇怪linux有关的程序总是有这种类似的遗漏。)。

  安装晚cygwin后,运行它。会出现一个类linux的环境。输入
  $mkdir /home/android    //创建工作目录
  $cd /home/android
  $mkdir bin

//下载安装repo版本管理工具:
$curl http://android.git.kernel.org/repo> /home/android /bin/repo
$cd bin
$chmod a+x repo
准备下载Android:
$cd /home/android
$python ./bin/repo init -u git://android.git.kernel.org/platform/manifest.git –b cupcake
$git config --global user.email "xxxxx@xxxxxxx"
$git config --global user.name "xxxxxx"
邮箱地址填有效邮箱即可,我试过,其实这步跳过也没有问题。
//下载源码:
$python ./bin/repo sync
­
唯一和linux下不同的地方是该环境似乎没有内嵌支持python,因此需要用命令行python来调用repo脚本。

2009年6月20日星期六

ubuntu 9.04上下载android源码

作为开源手机操作系统,android一经推出,便引来业界极大的关注。Google现在的android源码的版本号已经是1.50r1的。越来越多的爱好者开始加入到android源码的研究中,下面就ubuntu 9.04上如果去获得android最新源码。

1.      安装gitgnupg。输入

$sudo apt-get install git-core gnupg 

2.   安装其它工具

$sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev

3.  安装valgrind工具

$sudo apt-get install valgrind 

4.  安装java sdk

$sudo apt-get install sun-java6-sdk

$sudo apt-get install sun-java5-sdk

$cd /etc/alternatives
$sudo rm javadoc.1.gz javadoc
$sudo ln -s /usr/lib/jvm/java-1.5.0-sun/man/man1/javadoc.1.gz javadoc.1.gz
$sudo ln -s /usr/lib/jvm/java-1.5.0-sun/bin/javadoc javadoc

android仅支持1.5以上版本的java sdk,且1.6版本的java sdk在进行android sdk编译时会出现java doc错误,在这里我的解决办法时先安装java sdk 1.6,接着安装java sdk 1.5,然后将系统的java sdk链接到java sdk 1.6上,仅是将javadocjavadoc.1.gz链接到java sdk 1.5上,这样做的好处是在编译android源码和进行android应用开发时,使用的是java sdk 1.6,仅在编译android sdkdoc时,使用的是java sdk 1.5版本的javadocjavadoc.1gz

5.       下载repo工具

$mkdir  $HOME/bin

$vi  .bashrc

加入

export  PATH=$HOME/bin:$PATH

$source  .bashrc

$ curl  http://android.git.kernel.org/repo > $HOME/bin/repo

$ cd  $HOME/bin

$ chmod  +x  repo 

6.       导出android项目

$ cd

$ mkdir  Android

$ cd  Android

$ repo init -u git://android.git.kernel.org/platform/manifest.git
并完成提示的配置,这样我们建立的目录就已经和Googleandroid源码库建立了链接。

7.       开始下载android platform的源代码

$ repo sync

由于android的源码很大,现在完整的代码已经高达3G以上,所以最分文件夹进行同步下载。如要下载kernel

$repo sync kernel

现在,就可以做别的事,让电脑自动完成源码的下载工作。


转载:http://blog.mcuol.com/User/weishuangbo/article/12338_1.htm

在JavaScript中实现统计文本框Textarea字数

现在流行的Twitter等微博客网站,有一个很好的用户体验,就是在文本框中输入文字的时候,会自动统计输入的字符,并显示用户还能输入的字符,在限制了140个字的微博客中,这样的小提示可以很好的增强用户体验。

  如果实现这种技术呢,我进行了一些研究,发现实现其实挺简单,几行代码就能完成输入字符统计功能,经过实际测试,其对文字的统计与Twitter等微博客的完全相同。

   使用方法是,先增加一个span,用于显示剩余的字数,然后在Textarea中,加入一个onkeydown和onkeyup的事件,调用另一段 JavaScript函数,函数调用的参数为span的id和textarea的id,然后再JavaScript中使用innerHTML返回计算出来 的剩余字数。

  以下是相关的JavaScript代码:

<script language="javascript"> 
function countChar(textareaName,spanName)

 document.getElementById(spanName).innerHTML = 140 - document.getElementById(textareaName).value.length;

</script>

可以输入<span id="counter">140</span>字<br/>
<textarea id="status"  name="status" rows="6" cols="40" onkeydown='countChar("status","counter");' onkeyup='countChar("status","counter");'></textarea>

原创文章如转载,请注明:转载自月光博客 [ http://www.williamlong.info/ ]

本文链接地址:http://www.williamlong.info/archives/1830.html

2009年6月3日星期三

Databases supported by NHibernate


Databases supported by NHibernate

NHibernate is primarily tested on Microsoft SQL Server 2000. It is also known to work on these databases:



Microsoft SQL Server 2005/2000

SQL Server 2005 and 2000 are the primary databases used by the developers of NHibernate.

Configuration example:

<?xml version="1.0" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
   <session-factory>
       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
       <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
       <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
       <property name="connection.connection_string">Server=(local);Initial Catalog=dbname;User Id=user;Password=********</property>
   </session-factory>
</hibernate-configuration>

For SQL Server 2000, change the dialect to NHibernate.Dialect.MsSql2000Dialect.

Issues

SQL Server sometimes ignores columns specified in ORDER BY clause of a query if they are not included in the SELECT clause. This behavior is actually valid according to the SQL standard, but may be surprising. For example, a query like this is not guaranteed to be ordered correctly:

from Person p order by p.Company.Name



Oracle

Oracle 9i and 10g are supported, both using Microsoft driver (System.Data.OracleClient) and using Oracle driver (Oracle.Data.OracleClient).

Issues

Microsoft's driver does not handle long character strings correctly. An error happens in some circumstances when using a string of length 2000-4000 as a parameter value.

Oracle cannot handle empty strings (""), you should use null instead. An IUserType implementation to perform the conversion is contained in Nullables.NHibernate library (part of NHibernateContrib package).



Microsoft Access

Microsoft Access has its own dialect and driver (contributed by Lukas Krejci).

They are currently in a separated library: NHibernate.JetDriver.dll (in NHibernateContrib package).

Here is what your hibernate.cfg.xml file should contain when using a Microsoft Access database:

<?xml version="1.0" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
   <session-factory>
       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
       <property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</property>
       <property name="connection.driver_class">NHibernate.JetDriver.JetDriver, NHibernate.JetDriver</property>
       <property name="connection.connection_string">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=YourDatabaseFilePathHere.mdb</property>
   </session-factory>
</hibernate-configuration>

Issues

There are still few problems with join syntax in queries that use more than one join. This driver passes 93% of NHibernate tests (there are 23 failing tests).

The most complete topic about these issues is here: Using NHibernate with Microsoft Access 2003 / Jet 4.0. JIRA issues NH-124 and NH-437 have some information on problems with implementing Microsoft Access dialect. You can also try searching NHibernate forum for "access jet" (require all words).



Firebird

Firebird is supported since version 1.5.3, though version 2.0.1 is strongly recommended. To work with Firebird, install the latest Firebird .NET Data Provider. If the data provider is installed in the GAC (the standard behavior of its installer), add this section to your application configuration file (App.config or Web.config):

<runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <qualifyAssembly partialName="FirebirdSql.Data.FirebirdClient"
           fullName="FirebirdSql.Data.FirebirdClient, Version=2.0.1.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" />
   </assemblyBinding>
</runtime>

The value of the fullName attribute will depend on the version of the assembly you have installed in the GAC.

Here is what your hibernate.cfg.xml file should contain when using Firebird:

<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
   <session-factory name="NHibernate.Test">
       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
       <property name="connection.driver_class">NHibernate.Driver.FirebirdClientDriver</property>
       <property name="connection.isolation">ReadCommitted</property>
       <property name="connection.connection_string">
           Server=localhost;
           Database=C:\nhibernate.fdb;
           User=SYSDBA;Password=masterkey
       </property>
       <property name="show_sql">false</property>
       <property name="dialect">NHibernate.Dialect.FirebirdDialect</property>
       <property name="use_outer_join">true</property>
       <property name="command_timeout">444</property>
       <property name="query.substitutions">true 1, false 0, yes 1, no 0</property>
   </session-factory>
</hibernate-configuration>

All Firebird 2.0.1 embedded functions are registered in the dialect, as well as user-defined functions from ib_udf2.sql. These functions can be used in HQL queries.



PostgreSQL

PostgreSQL version 7.4 with latest Npgsql works almost perfectly. Later versions should work too.

Configuration example:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
   <session-factory name="NHibernate.Test">
       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
       <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
       <property name="connection.connection_string">
           Server=localhost;initial catalog=nhibernate;User ID=nhibernate;Password=********;
       </property>
       <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
   </session-factory>
</hibernate-configuration>



DB2 UDB

DB2 UDB is supported and reportedly even passes all the tests (see http://nhibernate.sourceforge.net/forum/viewtopic.php?t=73). Example configuration using the ODBC drivers that come with the 'stinger' release of db2:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >

   <session-factory name="session">

       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
       <property name="connection.driver_class">NHibernate.Driver.OdbcDriver</property>
       <property name="connection.connection_string">driver={IBM DB2 ODBC DRIVER};Database=db;hostname=host;port=port;protocol=TCPIP; uid=uid; pwd=pwd</property>
       <property name="show_sql">true</property>
       <property name="dialect">NHibernate.Dialect.DB2Dialect</property>
       <property name="use_outer_join">true</property>

       <mapping resource="..." />

   
   </session-factory>

</hibernate-configuration>



MySQL

All MySQL versions should work, though there are issues with zero dates (see below for details). To connect to your database use Connector/NET (formerly known as ByteFX.Data.MySqlClient).

Configuration example:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
   <session-factory name="NHibernate.Test">
       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
       <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
       <property name="connection.connection_string">
           Database=test;Data Source=someip;User Id=blah;Password=blah
       </property>
       <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
   </session-factory>
</hibernate-configuration>

Issues

MySQL has a unique "feature" of allowing invalid dates in a DATE field, and especially using 0000-00-00 as a default value for DATE NOT NULL columns. When MySQL Connector encounters such a date, it either throws an exception or returns a non-standard MySqlDateTime object (depending on a connection string parameter) which throws an exception when converting itself to a DateTime.

Possible workarounds:

  • avoid zero dates
  • modify Connector/NET source code to round zero dates to DateTime.Min and back (see JIRA issue NH-32 for a patch to an older version of the Connector)
  • create a user type for MySqlDateTime (no known implementations currently)


SQLite

SQLite version 3 works rather well using ADO.NET provider available from http://sourceforge.net/projects/adodotnetsqlite. NHibernate Query Analyzer uses SQLite (see [Related Projects]).

Configuration example:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
   <session-factory name="NHibernate.Test">
       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
       <property name="connection.driver_class">NHibernate.Driver.SQLiteDriver</property>
       <property name="connection.connection_string">
           Data Source=nhibernate.db;Version=3
       </property>
       <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
       <property name="query.substitutions">true=1;false=0</property>
   </session-factory>
</hibernate-configuration>

Issues

SQLite currently fails 17 tests out of approximately 500 in NHibernate test suite. Some of the failures are caused by SQLite being unable to store strings containing NUL characters, other tests fail because of a bug in SQLite ADO.NET provider when using a table with spaces in its name.

  NEW COMMENT


Database 20 Dec 2006, 09:33 dementor
Can i use XML as a database instead of MSSQL or Oracle etc?
if yes, please guide me to do it.
Thanks in advance.
 
Configuration Error hibernate.connection.driver_class 02 Jan 2007, 11:27 vata2999
After following the Quick Start Guide I am getting an ERROR:

The hibernate.connection.driver_class must be specified in the
NHibernate configuration section

I have clearly declare the hibernate.connection.driver_class Key in
app.config file:

<add key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver" />

I am stucked up with this. Kindly help to solve this prob.

Thanks,
 
Re: Configuration Error hibernate.connection.driver_class 13 Mar 2007, 08:58 Wervis
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE PAGE!
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE PAGE!
On 02 Jan 2007 11:27, vata2999 wrote:

>After following the Quick Start Guide I am getting an ERROR:

>The hibernate.connection.driver_class must be specified in the
>NHibernate configuration section

>I have clearly declare the hibernate.connection.driver_class Key in
>app.config file:

> <add key="hibernate.connection.driver_class"
>value="NHibernate.Driver.SqlClientDriver" />

>I am stucked up with this. Kindly help to solve this prob.

>Thanks,


Add following to your app.config and complete connectionstring:

<nhibernate>
<add key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"/>
<add key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>
<add key="hibernate.connection.connection_string" value="Data
Source=yourserver;Initial Catalog=yourdatabase;Persist Security
Info=True;User ID=sa;Password=pass"/>
<add key="hibernate.show_sql" value="true"/>
</nhibernate>
 
Update Sqlite ADO.net driver 22 Mar 2007, 11:40 redinger
There's a note about it on the ADO.net provider page that is referenced,
but it is no longer being actively developed.

A new provider that is ADO.net 2.0 compliant can be found here:
http://sqlite.phxsoftware.com/
 
postgresql connection string example does not work with latest 02 May 2008, 16:59 evarlast
The connection string example for postgresql does not work.

Use databsae= instead of initial catalog=.
 
FoxPro Connection works 15 Jun 2008, 09:56 antoschka
I've managed to connect to FoxPro databases. Even in a complex data
model there I could not encounter any problems. As Dialect I took a
GeneralDialect or MsSql2000Dialect - the Driver I defined as OleDbDriver.

The biggest hurdle was to find out the appropriate generator class for
the various Id-columns of the entities.
Never set autoincrement on the database level. This will not work with
foxpro. Define it as Id or leave the id column as normal column. The
important think is to define the Id Column in entity Mapping file with
<generator class="increment" />
example:
<id name="IdentityEntity" column="IdentityColumn" type="int">
     <generator class="increment" />
   </id>

If you want to assign the ids yourself use <generator class="assigned" />.
 
Bug encountered and solved in the NHibernate.JetDriver assembly 15 Jun 2008, 09:59 antoschka
Hi,

there is a bug in the NHibernate.JetDriver assembly. As soon as you deal
with columns which contain the literals "from" the Driver throws
exceptions at you. I have modified the Driver and now it works. However
I do not know how to contribute the changes.

Bye antoschka
 
Re: FoxPro Connection works 15 Jun 2008, 10:53 antoschka
Just a further note on the FoxPro issue. Through all the hustle I also
tried Access as a Database. However it might be interesting for you how
databases compare speed-wise.
Currently I connect to three DB (all contain the same scheme and
identical data). To startup my application I received the following
speed figures.
- MS-SQL Server: normal start 1.4 seconds ( in in Debug-Mode 21 Seconds)
- Access: normal start 7.5 seconds( in in Debug-Mode 14.5 Seconds)
- FoxPro: normal start 2,6 seconds( in in Debug-Mode 21 Seconds)

Debug Mode means - SQL Command logging:
<add
key="hibernate.show_sql"
value="true"
/>

In case of performance problems with Access-DBs consider using FoxPro.
Similar to Access you also need only access to a (network-)drive instead
of installing a whole database server and dealing with all the overhead
in terms of configuration, maintenance and administration.

Greeting antoschka
 
Configuration example for Oracle 14 Sep 2008, 01:22 mijaved
Where the hell is the Configuration example for Oracle!!!???
 
Re: Configuration example for Oracle 25 Sep 2008, 12:07 wizzsm
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!On 14 Sep 2008 01:22, mijaved wrote:

>Where the hell is the Configuration example for Oracle!!!???

in your .cs the oracle driver info is:

if ("ORACLE" == database)
           {
               cfg.SetProperty(NHibernate.Cfg.Environment.Dialect,
"NHibernate.Dialect.Oracle9Dialect");
             
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver,
"NHibernate.Driver.OracleDataClientDriver");
             
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString,
connectionString);
           }

in assemblyinfo.cs add:
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

in the exe.config use:

                <!-- Select the kind of database to use -->
                <!-- Possible values: MSSQL, MySQL, or ORACLE -->
                <appSettings>
                                 <add key="Database" value="ORACLE" />
                                 <add key="MSSQL.ConnectionString" value="Data Source=(local);Initial
Catalog=nhibernate;Integrated Security=SSPI" />
                                 <add key="MySQL.ConnectionString"
value="Server=localhost;Database=nhibernate;User ID=root;Password=" />
                                 <add key="ORACLE.ConnectionString" value="Data
Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=********.domain.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=*****)));User
ID=****;Password=****" />
                </appSettings>

and copy the following file from oracle into your product:

C:\oracle\product\10.2.0\db_1\BIN\Oracle.DataAccess.dll

Steve.