随笔-75  评论-193  文章-5  trackbacks-0
 

EntityManager的定义

The EntityManager manages the O/R mapping between a fixed set of entity classes and an underlying data source.
It provides APIs for creating queries, finding objects, synchronizing objects, and inserting objects into the database.
It also can provide caching and manage the interaction between an entity and transactional services in a Java EE environment such as JTA.
The EntityManager is tightly integrated with Java EE and EJB but is not limited to this environment; it can be used in plain Java programs.

An EntityManager maps a fixed set of classes to a particular database. This set of classes is called a persistence unit .

In Java SE, entity managers are created using a javax.persistence.EntityManagerFactory
Example:
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("titan", map);
    EntityManager manager = factory.createEntityManager();
在Java SE环境中,使用完EntityManagerFactory后,最好将其关闭,以释放其占有的资源。

和Java SE环境不一样,在Java EE中,一个注入的EntityManagerFactory会被EJB容器自动关闭,实际上,如果你调用EntityManagerFactory的clost()方法时,会抛出IllegalStateException异常。

public interface EntityManager {
   public void persist(Object entity);
   public <T> T find(Class <T> entityClass, Object primaryKey);
   public <T> T getReference(Class <T> entityClass, Object primaryKey);
   public <T> T merge(T entity);
   public void remove(Object entity);
   public void lock(Object entity, LockModeType lockMode);

   public void refresh(Object entity);
   public boolean contains(Object entity);
   public void clear( );

   public void joinTransaction( );
   public void flush( );
   public FlushModeType getFlushMode( );
   public void setFlushMode(FlushModeType type);

   public Query createQuery(String queryString);
   public Query createNamedQuery(String name);
   public Query createNativeQuery(String sqlString);
   public Query createNativeQuery(String sqlString, String resultSetMapping);
   public Query createNativeQuery(String sqlString, Class resultClass);

   public Object getDelegate( );

   public void close( );
   public boolean isOpen( );
}

Persistence context的定义

A persistence context is a set of managed entity object instances.
Persistence contexts are managed by an entity manager.

There are two types of persistence contexts: transaction-scoped and extended persistence contexts.

A persistence context can be created by calling the EntityManagerFactory.createEntityManager( ) method. The returned EntityManager instance represents an extended persistence context. If the EntityManagerFactory is JTA-enabled, then you have to explicitly enlist the EntityManager instance within a transaction by calling the EntityManager.joinTransaction( ) method. If you do not enlist the EntityManager within the JTA transaction, then changes you make to your entities are not synchronized with the database.

FlushModeType的含义

FlushModeType默认为AUTO模式,当为AUTO时,在一个查询被执行前,会自动将变化提交到数据库中,即调用flush()方法。但是调用find()或getreference()方法时,并不会执行自动提交。当为COMMIT模式时,仅仅在事务提交时,会将变化提交到数据库中。

EJB3中的实体注解规范参见如下链接
http://wiki.redsaga.com/confluence/display/HART/Home

posted @ 2007-05-07 23:42 The Matrix 阅读(576) | 评论 (0)编辑 收藏
1、查找数组中的元素可以使用ascb.util.ArrayUtilities中的findMatchIndex()、findLastMatchIndex()、findMatchIndices()方法,具体参考API。

2、使用splice()方法可以移除数组中间的元素,使用pop()方法移除数组的最后一个元素,使用shift()方法移除数组的第一个元素。也可以使用splice()方法向数组中增加元素。

3、将数组转化为String,可以使用join()方法。
例:
var letters:Array = ["a", "b", "c"];
trace(letters.join());   // Displays: a,b,c
posted @ 2007-01-16 22:35 The Matrix 阅读(746) | 评论 (0)编辑 收藏
flash.system.Capabilities类提供了很多静态方法返回运行flash的player、计算机的信息,比如操作系统、语言、声音、视频能力等。
还有一些其它的类比如:
flash.display.Stage和flash.system.Security允许你控制播放器的右键弹出菜单和设置对话框。
flash.display.Stage还可以控制播放器播放的视频的缩放比例和位置。
flash.system.Capabilities.os 返回操作系统信息。代码如下:  

    var os:String = System.capabilities.os.substr(0, 3);
    if (os == "Win") {
        // Windows-specific code goes here
    } else if (os == "Mac") {
        // Mac-specific code goes here
    } else {
        // Must be Unix or Linux
    }

flash.system.Capabilities.playerType   不同的类型包括:
    Browser plug-in that runs in web browsers such as Mozilla or Firefox
    ActiveX Control used by Internet Explorer    
    Standalone player, which plays .swfs outside of the browser     
    External player, which is the player integrated in the Flash IDE   

flash.system.capabilities.screenResolutionX 和 screenResolutionY获取屏幕分辨率。
stage.scaleMode属性可以设置一个movie如何填充播放器,包括比例等。
有四种模式,以静态常量的方法定义在flash.display.StageScaleMode类中,分别为:EXACT_FIT、NO_BORDER、NO_SCALE、SHOW_ALL。

stage.align属性可以设置一个movie的排列方式,也以静态常量的方式定义在flash.display.StageAlign类中。
    如下:
                              Vertical   Horizontal
   StageAlign.TOP              Top         Center
   StageAlign.BOTTOM           Bottom      Center
   StageAlign.LEFT             Center      Left
   StageAlign.RIGHT            Center      Right
   StageAlign.TOP_LEFT         Top         Left
   StageAlign.TOP_RIGHT        Top         Right
   StageAlign.BOTTOM_LEFT      Bottom      Left
   StageAlign.BOTTOM_RIGHT     Bottom      Right     
   
flash.system.Capabilities的hasAudio和hasMP3属性可以判断flash player所在设备的音频能力。
stage.showDefaultContextMenu属性设为false,可以隐藏掉一些系统默认菜单。
posted @ 2007-01-13 15:42 The Matrix 阅读(666) | 评论 (0)编辑 收藏

事件是实现对象通讯的一个重要手段,对于构建一个灵活的系统来说是非常必要的。在Flash Player 9中,将事件发送机制内建在了flash.events.EventDispatcher类中。所有需要发送事件的类都必须继承EventDispatcher类。
调用EventDispatcher类中的addEventListener( ) and removeEventListener( )方法,就可以注册或者移除事件监听器。EventDispatcher中还定义了dispatchEvent()方法,可以使用该方法发送事件。dispatchEvent()方法至少需要一个参数,即flash.events.Event对象或者它的子类。

原文如下:
Events are an important way for objects to communicate. They are essential for creating flexible systems. Flash Player 9, for example, has a built-in event dispatching mechanism in the flash.events.EventDispatcher class. All classes that dispatch events inherit from EventDispatcher (e.g., NetStream and Sprite). If you want to define a class that dispatches events, you can extend EventDispatcher, as follows:

package {
    import flash.events.EventDispatcher;
    public class Example extends EventDispatcher {

    }
}


The EventDispatcher class has public methods called addEventListener( ) and removeEventListener( ) that you can call from any instance of an EventDispatcher subclass to register event listeners. EventDispatcher also defines a protected method called dispatchEvent( ), which you can call from within a subclass to dispatch an event. The dispatchEvent( ) method requires at least one parameter as a flash.events.Event object or a subclass of Event.

posted @ 2007-01-13 15:09 The Matrix 阅读(441) | 评论 (0)编辑 收藏
Another option is to use implicit getters and setters. Implicit getters and setters are declared as methods, but they look like properties. The syntax for a getter is as follows:

public function get name(  ):Datatype {
}

The syntax for a setter is as follows:

public function set name(value:Datatype):void {
}

这样在代码中调用counter.count=5时相当于调用了set count(5)方法。

Counter类如下:
public class Counter {
    private var _count:uint;
    public function Counter(  ) {
        _count = 0;
    }
    public function get count(  ):uint {
        return _count;
    }
    public function set count(value:uint):void {
        if(value < 100) {
            _count = value;
        }
        else {
            throw Error(  );
        }
    }
}
posted @ 2007-01-13 14:53 The Matrix 阅读(554) | 评论 (0)编辑 收藏
今天在网上看到这么一段,很实用:

如果想要仔细看Hibernate生成的SQL语句,将format_sql设为true可以很大程度地减轻痛苦……
hibernate.format_sql = true
再加上这个的话:
hibernate.use_sql_comments = true
[可读性 + 可定位性]会更好
不过,这两个一起来的话也会造成SQL在console中显示的篇幅很大。
posted @ 2006-11-24 22:24 The Matrix 阅读(8012) | 评论 (1)编辑 收藏
刚用Open Laszlo做了几个项目,受够了其无法调试,只能通过Debug将调试信息打印出来再慢慢研究错在哪里,受够了!
试用了Flex2 Builder,备受其可以Debug的鼓舞,同时也受到了其Chart组件的诱惑,觉得这是一个比较有前途的RIA发展方向,决定研究一番。
posted @ 2006-10-30 22:50 The Matrix 阅读(455) | 评论 (0)编辑 收藏
仅列出标题
共4页: 上一页 1 2 3 4