ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久www免费人成黑人精品,亚洲国产天堂久久综合,91精品观看http://www.aygfsteel.com/stingh711/category/329.htmlPretend to be happy when you feel blue, that is not very hard to do.zh-cnThu, 17 Jan 2008 15:54:55 GMTThu, 17 Jan 2008 15:54:55 GMT60用hibernate mapping collections of component class,é‡åˆ°ä¸€ä¸ªå¥‡æ€ªçš„问题http://www.aygfsteel.com/stingh711/archive/2008/01/17/176048.htmldjangodjangoThu, 17 Jan 2008 11:48:00 GMThttp://www.aygfsteel.com/stingh711/archive/2008/01/17/176048.htmlhttp://www.aygfsteel.com/stingh711/comments/176048.htmlhttp://www.aygfsteel.com/stingh711/archive/2008/01/17/176048.html#Feedback0http://www.aygfsteel.com/stingh711/comments/commentRss/176048.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/176048.htmlpublic class CustomService {
  
private long id;
  
private List<WebSite> trustedSites;
  
private List<WebSite> blockedSites;
  
  
public CustomService() {
    
this.trustedSites = new ArrayList<WebSite>();
    
this.blockedSites = new ArrayList<WebSite>();
  }

  
public List<WebSite> getBlockedSites() {
    
return blockedSites;
  }

  
public void setBlockedSites(List<WebSite> blockedSites) {
    
this.blockedSites = blockedSites;
  }

  
public long getId() {
    
return id;
  }

  
public void setId(long id) {
    
this.id = id;
  }

  
public List<WebSite> getTrustedSites() {
    
return trustedSites;
  }

  
public void setTrustedSites(List<WebSite> trustedSites) {
    
this.trustedSites = trustedSites;
  }
  
  
public void addTrustedSites(String site, boolean isNewData) {
    
this.trustedSites.add(new WebSite(site, isNewData));
  }
  
  
public void addBlockedSites(String site, boolean isNewData) {
    
this.blockedSites.add(new WebSite(site, isNewData));
  }
}
public class WebSite {
  
private String website;
  
private boolean isNewData;
  
  
public WebSite() {
    
  }

  
public WebSite(String website) {
    
this.website = website;
  }

  
public WebSite(String website, boolean isNewData) {
    
this.website = website;
    
this.isNewData = isNewData;
  }

  
public boolean isIsNewData() {
    
return isNewData;
  }

  
public void setIsNewData(boolean isNewData) {
    
this.isNewData = isNewData;
  }

  
public String getWebsite() {
    
return website;
  }

  
public void setWebsite(String website) {
    
this.website = website;
  }

  @Override
  
public boolean equals(Object obj) {
    
if (this == obj) {
      
return true;
    }
    
if (obj == null) {
      
return false;
    }
    
if (getClass() != obj.getClass()) {
      
return false;
    }
    
final WebSite other = (WebSite) obj;
    
if (this.website == null || !this.website.equals(other.website)) {
      
return false;
    }
    
if (this.isNewData != other.isNewData) {
      
return false;
    }
    
return true;
  }

  @Override
  
public int hashCode() {
    
int hash = 7;
    hash 
= 13 * hash + (this.website != null ? this.website.hashCode() : 0);
    hash 
= 13 * hash + (this.isNewData ? 1 : 0);
    
return hash;
  }
  
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<hibernate-mapping package="model.cnm.cf">
  
<class name="CustomService" table="custom_services">
    
<id name="id" column="id" type="long">
      
<generator class="native"/>
    
</id>
    
<list name="trustedSites" table="cf_trusted_sites" cascade="all">
      
<key column="service_id"/>
      
<list-index column="pos"/>
      
<composite-element class="WebSite">
        
<property name="website" column="site" type="string"/>
        
<property name="isNewData" column="isNewData" type="boolean"/>
      
</composite-element>
    
</list>
    
<list name="blockedSites" table="cf_blocked_sites">
      
<key column="service_id"/>
      
<index column="pos"/>
      
<composite-element class="WebSite">
        
<property name="website" column="site" type="string"/>
        
<property name="isNewData" column="isNewData" type="boolean"/>
      
</composite-element>
    
</list>
  
</class>
</hibernate-mapping>
CustomService有两个WebSiteçš„list,mapåˆîC¸åŒçš„è¡?æŽ¥ä¸‹æ¥æ˜¯‹¹‹è¯•代ç .
 1 public class CustomServiceTest extends BaseDaoTestCase {
 2   private CustomService service;
 3   private long id;
 4   
 5   @Test
 6   public void save() {
 7     session = HibernateUtil.getSession();
 8     service = new CustomService();
 9     service.addBlockedSites("www.whitehouse.com", true);
10     service.addBlockedSites("www.whitehouse.com", false);
11     
12     service.addTrustedSites("www.google.cn", true);
13     service.addTrustedSites("www.google.cn", false);
14     
15     
16     session.save(service);
17     id = service.getId();
18     session.flush();
19     session.close();
20     
21     session = HibernateUtil.getSession();
22     Transaction tr = null;
23     try {
24       tr = session.beginTransaction();
25       session.save(service);
26     } catch (Exception e) {
27       if (tr != null) {
28         tr.commit();
29       }
30     } finally {
31       session.close();
32     }
33     
34     session = HibernateUtil.getSession();
35     service = getService();
36     assertEquals(2, service.getBlockedSites().size());
37     assertEquals(2, service.getTrustedSites().size());
38   }
39   
40   private CustomService getService() {
41     return (CustomService) session.get(CustomService.class, id);
42   }
43     
44 
45 }
˜q™æ ·å†™æµ‹è¯•是å¯ä»¥˜q‡å¾—,但如果从22è¡?32行改æˆä¸‹é¢çš„æ ·å­,service.getBlockedSites().size()å’?/span>service.getTrustedSites().size()é€šé€šéƒ½å˜æˆäº?.
1 session = HibernateUtil.getSession();
2 session.save(service);
3 session.flush();
4 session.close();
真的是很奇æ€?è²Œä¼¼åªæœ‰½W¬äºŒ‹Æ¡save的时候的æäº¤æ–¹å¼ä¸ä¸€æ ?
åˆç»™CustomService加了一个name字段,¾l“果表明,在直接用session.flush()å’Œsession.close()的时å€?æ ÒŽœ¬ž®±æ²¡æœ‰æäº?ä¸è¿‡å¥‡æ€ªçš„æ˜?½W¬ä¸€‹Æ¡è¿™æ ·åšæ€Žä¹ˆä¼šæäº¤äº†.


]]>
netbeans6.0 vs eclipse3.3http://www.aygfsteel.com/stingh711/archive/2007/12/26/170654.htmldjangodjangoWed, 26 Dec 2007 09:48:00 GMThttp://www.aygfsteel.com/stingh711/archive/2007/12/26/170654.htmlhttp://www.aygfsteel.com/stingh711/comments/170654.htmlhttp://www.aygfsteel.com/stingh711/archive/2007/12/26/170654.html#Feedback2http://www.aygfsteel.com/stingh711/comments/commentRss/170654.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/170654.html½Ž€å•çš„å¯Òޝ”一下å§ã€?br />先说¾~ºç‚¹å§ï¼š
  1. 速度慢。有时候editor最大化è¦ç‚¹å¥½å‡ ‹Æ¡æ‰work。如果打开大的projectåQŒeclipse虽然慢但˜q˜å¯ä»¥workåQŒnetbeans基本上就æ­Õdœ¨é‚£å„¿äº†ã€?/li>
  2. 今天å‘现有时候键盘会失去å“应ã€?/li>
  3. Junit teståQŒå¦‚果测试failçš„è¯åQŒæ¯”如说assertNull("xxx should be null", "string")åQŒfail掉以åŽï¼Œmessage “xxx should be null"需è¦åˆ°outputçš„çª—å£æ‰å¯ä»¥çœ‹åˆ°åQŒeclipseæ•´åˆåˆîC¸€ä¸ªçª—å£äº†ã€?/li>
  4. æ’äšgåå°‘åQŒæ¯”如说hibernateçš„æ’ä»Óž¼Œgroovyçš„æ’ä»¶ã€?/li>
  5. 在我的linux下,错误æç¤ºéƒ½æ˜¯ä¹Þq ...
优点åQ?br />
  1. For ruby和rails的版本还蛮好用的�/li>
  2. 觉得最好用的就是code templateåQŒeclipse上ä¸èƒ½ç”¨tabé”®triggeråQŒè€Œä¸”eclipse里é¢å…许é‡åçš„templateåQŒæ‰€ä»¥è¿˜è¦é€‰ï¼Œå“ªæ€•åªæœ‰ä¸€ä¸ªtemplate。而且åQŒeclipse里templateåªèƒ½åœ¨ç¼–辑java里ä‹É用ã€?br />


django 2007-12-26 17:48 å‘表评论
]]>
AJAX on java FAQ (zt)http://www.aygfsteel.com/stingh711/archive/2007/10/16/153247.htmldjangodjangoTue, 16 Oct 2007 05:46:00 GMThttp://www.aygfsteel.com/stingh711/archive/2007/10/16/153247.htmlhttp://www.aygfsteel.com/stingh711/comments/153247.htmlhttp://www.aygfsteel.com/stingh711/archive/2007/10/16/153247.html#Feedback0http://www.aygfsteel.com/stingh711/comments/commentRss/153247.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/153247.htmlhttps://blueprints.dev.java.net/ajax-faq-zh.html#ajax

Blogged with Flock

Tags: ,



django 2007-10-16 13:46 å‘表评论
]]>
½Ž€å•çš„‹¹è§ˆäº†ä¸€ä¸‹MANIFEST.MF的用é€?/title><link>http://www.aygfsteel.com/stingh711/archive/2007/10/10/151659.html</link><dc:creator>django</dc:creator><author>django</author><pubDate>Wed, 10 Oct 2007 03:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/stingh711/archive/2007/10/10/151659.html</guid><wfw:comment>http://www.aygfsteel.com/stingh711/comments/151659.html</wfw:comment><comments>http://www.aygfsteel.com/stingh711/archive/2007/10/10/151659.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stingh711/comments/commentRss/151659.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stingh711/services/trackbacks/151659.html</trackback:ping><description><![CDATA[å¯ä»¥ç”¨çš„上的有: <ol><li>Main-Class 指定½E‹åºçš„å…¥å£ï¼Œ˜q™æ ·å¯ä»¥ç›´æŽ¥ç”¨java -jar xxx.jaræ¥è¿è¡Œç¨‹åºã€?/li><li>Class-Path 指定jar包的ä¾èµ–关系åQŒclass loaderä¼šä¾æ®è¿™ä¸ªèµ\å¾„æ¥æœçƒ¦classã€?/li></ol>å’ŒversioningåQŒsealæœ‰å…³çš„ï¼Œçœ‹å¾—æ‡‚ä»€ä¹ˆæ„æ€ï¼Œä½†æ˜¯ä¸çŸ¥é“会怎样被用到。惭æ„?..有äh知é“么? <p style="text-align: right; font-size: 8px">Blogged with <a title="Flock" target="_new">Flock</a></p><!-- technorati tags begin --><p style="font-size:10px;text-align:right;">Tags: <a rel="tag">java</a></p><!-- technorati tags end --><img src ="http://www.aygfsteel.com/stingh711/aggbug/151659.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stingh711/" target="_blank">django</a> 2007-10-10 11:10 <a href="http://www.aygfsteel.com/stingh711/archive/2007/10/10/151659.html#Feedback" target="_blank" style="text-decoration:none;">å‘表评论</a></div>]]></description></item><item><title>解决2000下设¾|®classpath时报the input line is too longhttp://www.aygfsteel.com/stingh711/archive/2007/10/08/151182.htmldjangodjangoMon, 08 Oct 2007 14:45:00 GMThttp://www.aygfsteel.com/stingh711/archive/2007/10/08/151182.htmlhttp://www.aygfsteel.com/stingh711/comments/151182.htmlhttp://www.aygfsteel.com/stingh711/archive/2007/10/08/151182.html#Feedback3http://www.aygfsteel.com/stingh711/comments/commentRss/151182.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/151182.html最½W¨çš„办法ž®±æ˜¯æŠŠç”¨åˆ°çš„jaråŒ…é‡æ–°å†æ‰“一ä¸?打æˆä¸€ä¸?åŽæ¥åœ¨ç½‘上看åˆîC¸€½‹‡è®²manifest.mf的文ç«?了解到manifest.mf里é¢å¯ä»¥é€šè¿‡Class-Pathæ¥è®¾¾|®jar包所ä¾èµ–的包.试了一ä¸?˜q˜çœŸçš„ok.åªè¦åœ¨build自己½E‹åºçš„jar包的时å€?在manifest.mf里é¢åŠ ä¸Šä¾èµ–çš„jaråŒ?˜q™æ ·åœ¨ç”¨batèµïL¨‹åºçš„æ—¶å€?ž®×ƒ¸ç”¨å†åœ¨classpath里é¢åŠ è¿™äº›jar包了.ä¸è¿‡build.xml会å˜å¾—å˜æ€ä¸€ç‚?比以å‰ç¨å¾®éš¾¾l´æŠ¤ä¸€ç‚?有一炚wœ€è¦æ³¨æ„çš„ž®±æ˜¯,manifest.mf里é¢Class-Pathçš„èµ\径是相对其所在的jar包的.比如说这个manifest.mf是包å«åœ¨test.jarçš?那么Class-Path里指定的jar包都是相对于test.jar所在的路径.
有空学习一下manifest的其他的用�

Blogged with Flock

Tags:



django 2007-10-08 22:45 å‘表评论
]]>
Jetty, a lightweight java web server?http://www.aygfsteel.com/stingh711/archive/2007/09/29/149639.htmldjangodjangoSat, 29 Sep 2007 09:34:00 GMThttp://www.aygfsteel.com/stingh711/archive/2007/09/29/149639.htmlhttp://www.aygfsteel.com/stingh711/comments/149639.htmlhttp://www.aygfsteel.com/stingh711/archive/2007/09/29/149639.html#Feedback2http://www.aygfsteel.com/stingh711/comments/commentRss/149639.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/149639.htmlBlogged with Flock

Tags:



django 2007-09-29 17:34 å‘表评论
]]>
A Hibernate util written by groovyhttp://www.aygfsteel.com/stingh711/archive/2006/12/20/89159.htmldjangodjangoWed, 20 Dec 2006 14:54:00 GMThttp://www.aygfsteel.com/stingh711/archive/2006/12/20/89159.htmlhttp://www.aygfsteel.com/stingh711/comments/89159.htmlhttp://www.aygfsteel.com/stingh711/archive/2006/12/20/89159.html#Feedback0http://www.aygfsteel.com/stingh711/comments/commentRss/89159.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/89159.html Hibernate.groovy


import  org.hibernate.cfg.Configuration
import  org.hibernate.Session
import  org.hibernate.SessionFactory
import  org.hibernate.Transaction
import  org.hibernate.tool.hbm2ddl.SchemaUpdate

class  Hibernate {
    def 
static  sessionFactory
   
static  { 
       
try  { 
            Configuration cfg 
=   new  Configuration()
            cfg.configure()            
           
new  SchemaUpdate(cfg).execute( true ,  true )      
            sessionFactory 
=  cfg.buildSessionFactory()    
        } 
catch  (Exception e) {     
            e.printStackTrace()      
        }    
    }    

    Hibernate() {}   

    
private  Session getSession() {    
        
return  sessionFactory.openSession()    
    }    

    Object execute(closure) {       
        def s 
=  getSession()        
            def tr 
=   null         
            def result 
=   null         
            
try  {            
                tr 
=  s.beginTransaction()          
                    result 
=  closure.call(s)       
                    tr.commit()      
            } 
catch  (Exception e) {     
                e.printStackTrace()      
                    
if  (tr  !=   null ) {     
                        tr.rollback()    
                    }        
            } 
finally  {     
                s.close()   
            }        
        
return  result   
    }    

    
void  saveOrUpdate(obj) {
        def saveClosure 
=  { s  ->  s.saveOrUpdate(obj) }      
        execute(saveClosure)    
    }    

    List executeQuery(hql) {     
        execute({ s 
->  s.createQuery(hql).list() })   
    }    

    List executeQuery(hql, parameters) {    
        def query 
=  { s  ->         
            def q 
=  s.createQuery(hql)        
                
if  (parameters  !=   null ) {         
                    
for  (i in  0 ..parameters.size() - 1 ) {       
                        q.setParameter(i, parameters[i])       
                    }            
                }            
            q.list()       
        }        
        execute(query)    
    }    

    def get(clazz, id) {    
        
return  execute({ s  ->  s.get(clazz, id) })   
    }    

    
void  delete(obj) {       
        execute({ s 
->  s.delete(obj) })   
    }
}

Instead of interface, I use Closure for callback

Blogged with Flock

Tags:



django 2006-12-20 22:54 å‘表评论
]]>
使用httpclientå‘é€soap messagehttp://www.aygfsteel.com/stingh711/archive/2006/12/18/88657.htmldjangodjangoMon, 18 Dec 2006 15:30:00 GMThttp://www.aygfsteel.com/stingh711/archive/2006/12/18/88657.htmlhttp://www.aygfsteel.com/stingh711/comments/88657.htmlhttp://www.aygfsteel.com/stingh711/archive/2006/12/18/88657.html#Feedback0http://www.aygfsteel.com/stingh711/comments/commentRss/88657.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/88657.html˜q™ä¸¤å¤©åœ¨å†™ä¸€ä¸ªtr069çš„simulator,原ç†å¾ˆç®€å•啦,用httpclient模拟tr069çš„clientç«?å‘é€soap message到我们的acs server.

å‘é€soap message的代ç å¦‚ä¸?

public class MessageSender {
/**
* Logger for this class
*/
private static final Log logger = LogFactory.getLog(MessageSender.class);

private HttpClient httpClient;
private PostMethod postMethod;
private MessageFactory messageFactory;
private String url;
private NameValuePair sessionId;

public MessageSender(String ip){
this.httpClient = new HttpClient();

try {
this.messageFactory = MessageFactory.newInstance();
} catch (SOAPException e) {
logger.error(e.getMessage());
}

this.url = generateRequestUrl(ip);
}

private String generateRequestUrl(String ip) {
return "http://" + ip + ":8080/vantage/TR069";
}

public SOAPMessage sendMessage(SOAPMessage input) throws IOException, SOAPException {
this.postMethod = new PostMethod(this.url);
byte[] dataAsBytes = null;

if (input == null) {
logger.debug("Send a empty post");
dataAsBytes = new byte[0];
} else {

ByteArrayOutputStream data = new ByteArrayOutputStream();
input.writeTo(data);
dataAsBytes = data.toByteArray();
}

RequestEntity entity = new ByteArrayRequestEntity(dataAsBytes);
this.postMethod.setRequestEntity(entity);

if (this.sessionId != null) {
this.postMethod.addParameter(this.sessionId);
}

this.httpClient.executeMethod(this.postMethod);

sessionId = this.postMethod.getParameter("SessionID");

InputStream in = this.postMethod.getResponseBodyAsStream();

if (null == in) {
return null;
}

return this.messageFactory.createMessage(null, in);
}
}

最åˆçš„code里é¢,åªæœ‰ä¸€ä¸ªPostMethod,˜q™æ ·æ¯æ¬¡ä¼šä¸€ç›´keep一个http˜qžæŽ¥.å› äØ“åœ¨serverç«?åªç›´æŽ¥ç”¨http sessionæ¥ä¿å­˜server的状æ€çš„,所以必™å»è¦æ˜¯ä¿æŒæ˜¯ä¸€ä¸ªsession.用一个PostMethodå¯ä»¥åšåˆ°˜q™ç‚¹.ä¸è¿‡å¥‡æ€ªçš„æ˜?在命W¬äºŒ‹Æ¡è¯·æ±‚的时å€?怎么都拿ä¸åˆ°http connection.也ä¸çŸ¥é“æ˜¯ä¸æ˜¯httpclientçš„bug.åŽæ¥æ‰æ¯‹Æ¡è°ƒç”¨éƒ½é‡æ–°create一个PostMethod,但是把第一‹Æ¡å¾—到的sessionID add˜q›åŽ».



django 2006-12-18 23:30 å‘表评论
]]>
inverse tip on hibernatehttp://www.aygfsteel.com/stingh711/archive/2006/12/11/87085.htmldjangodjangoMon, 11 Dec 2006 15:14:00 GMThttp://www.aygfsteel.com/stingh711/archive/2006/12/11/87085.htmlhttp://www.aygfsteel.com/stingh711/comments/87085.htmlhttp://www.aygfsteel.com/stingh711/archive/2006/12/11/87085.html#Feedback0http://www.aygfsteel.com/stingh711/comments/commentRss/87085.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/87085.html所有åŒå‘的兌™”必须有一端被讄¡½®ä¸ºinverse.在一对多兌™”ä¸?它必™åÖM»£è¡¨å¤šçš„一ç«?在多对多ä¸?å¯ä»¥ä»ÀL„选å–一ç«?

inverse会媄å“到saveæ—¶å€™çš„è¡ŒäØ“ã€‚å¦‚æžœä¸€ç«¯çš„inverseè®¾äØ“trueåQŒåˆ™save应该在å¦ä¸€ç«¯è¿›è¡?/p>

django 2006-12-11 23:14 å‘表评论
]]>
一份简å•跟我风格比较一致的coding stylehttp://www.aygfsteel.com/stingh711/archive/2006/11/27/83819.htmldjangodjangoMon, 27 Nov 2006 08:18:00 GMThttp://www.aygfsteel.com/stingh711/archive/2006/11/27/83819.htmlhttp://www.aygfsteel.com/stingh711/comments/83819.htmlhttp://www.aygfsteel.com/stingh711/archive/2006/11/27/83819.html#Feedback0http://www.aygfsteel.com/stingh711/comments/commentRss/83819.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/83819.htmlIntroduction

The Java language gives you all the room you need to write code that would be very difficult for others to understand. Java also permits you to write code that is very easy to understand. Most development teams would prefer the latter.

A style guide provides provides a map so that the code generated by a group of programmers will be consistent and, therefore, easier to read and maintain. Many people do not care for the style guide offered by Sun. This document is one alternative.

This document covers most areas where there could be confusion or difference of opinion. Areas that have never been a problem in our experience are undocumented.

1 - Formatting

    1.1 - Indentation

    All indents are four spaces. All indenting is done with spaces, not tabs. (examples and reasoning)
    Matching braces always line up vertically in the same column as their construct. (examples)
    All if, while and for statements must use braces even if they control just one statement. (reasoning and examples)

    1.2 - Spacing

    All method names should be immediately followed by a left parenthesis.
    All array dereferences should be immediately followed by a left square bracket.
    Binary operators should have a space on either side.
    Unary operators should be immediately preceded or followed by their operand.
    Commas and semicolons are always followed by whitespace.
    All casts should be written with no spaces.
    The keywords if, while, for, switch, and catch must be followed by a space.
    (examples)

    1.3 - Class Member Ordering

    class Order
    {
    // fields

    // constructors

    // methods
    }

    1.4 - Maximum Line Length

    Avoid making lines longer than 120 characters. (reasoning)

    1.5 - Parentheses

    Parentheses should be used in expressions not only to specify order of precedence, but also to help simplify the expression. When in doubt, parenthesize.

2 - Identifiers

All identifiers use letters ('A' through 'Z' and 'a' through 'z') and numbers ('0' through '9') only. No underscores, dollar signs or non-ascii characters.

    2.1 - Classes and Interfaces

    All class and interface identifiers will use mixed case. The first letter of each word in the name will be uppercase, including the first letter of the name. All other letters will be in lowercase, except in the case of an acronym, which will be all upper case. (examples)

    2.2 - Packages

    Package names will use lower case characters only. Try to keep the length under eight (8) characters. Multi-word package names should be avoided. (examples)

    2.3 - All Other Identifiers

    All other identifiers, including (but not limited to) fields, local variables, methods and parameters, will use the following naming convention. This includes identifiers for constants.

    The first letter of each word in the name will be uppercase, except for the first letter of the name. All other letters will be in lowercase, except in the case of an embedded acronym, which will be all uppercase. Leading acronyms are all lower case. (examples and reasoning)

    Hungarian notation and scope identification are not allowed. (reasoning and examples)

    Test code is permitted to use underscores in identifiers for methods and fields. (reasoning and examples)

3 - Coding

    3.1 - Constructs to Avoid

    Never use do..while. (examples and reasoning)
    Never use return in the middle of a method. (reasoning)
    Never use continue. (reasoning)
    Never use break other than in a switch statement. (reasoning)

    3.2 - Do Not Compound Increment Or Decrement Operators

    Use a separate line for an increment or decrement. (examples and reasoning)

    Never use pre-increment or pre-decrement (examples and reasoning)

    3.3 - Initialization

    Declare variables as close as possible to where they are used. (examples)

    3.4 - Access

    All fields must be private, except for some constants.

4 - Self-Documenting Code

				"Any fool can write code that a computer can understand.
Good programmers write code that humans can understand."
        --- Martin Fowler, Refactoring: Improving the Design of Existing Code

Rather than trying to document how you perform a complex algorithm, try to make the algorithm easier to read by introducing more identifiers. This helps in the future in case the algorithm changes but someone forgets to change the documentation. (examples and reasoning)


原文链接�http://www.javaranch.com/style.jsp



django 2006-11-27 16:18 å‘表评论
]]>
Using PropertyPlaceHolderConfigurer to separate configuration files in springhttp://www.aygfsteel.com/stingh711/archive/2006/11/23/83145.htmldjangodjangoThu, 23 Nov 2006 15:53:00 GMThttp://www.aygfsteel.com/stingh711/archive/2006/11/23/83145.htmlhttp://www.aygfsteel.com/stingh711/comments/83145.htmlhttp://www.aygfsteel.com/stingh711/archive/2006/11/23/83145.html#Feedback0http://www.aygfsteel.com/stingh711/comments/commentRss/83145.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/83145.html<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderconfigurer">
    <property name="locations">
        <list>
            <value>...property files</value>
        </list>
    </property>
</bean>
Put the property files under classpath, then you can use ${property name} to reference properties in your property files in your spring configuration files.
Also, system properties and properties sent it by -D are also available through ${property name}.

django 2006-11-23 23:53 å‘表评论
]]>
使用Spring中的Resource接å£éš”离å¯ÒŽ–‡ä»¶ç³»¾lŸçš„ä¾èµ–http://www.aygfsteel.com/stingh711/archive/2006/11/19/82015.htmldjangodjangoSun, 19 Nov 2006 03:54:00 GMThttp://www.aygfsteel.com/stingh711/archive/2006/11/19/82015.htmlhttp://www.aygfsteel.com/stingh711/comments/82015.htmlhttp://www.aygfsteel.com/stingh711/archive/2006/11/19/82015.html#Feedback0http://www.aygfsteel.com/stingh711/comments/commentRss/82015.htmlhttp://www.aygfsteel.com/stingh711/services/trackbacks/82015.html在项目中,¾l常è¦ç”¨åˆ°è¯»¾pÈ»Ÿæ–‡äšg.在项目的é—留代ç ä¸?都是在系¾lŸå¯åŠ¨æ˜¯ä¼ å…¥ä¸€ä¸ªAPP_HOME,ç„¶åŽæ ÒŽ®ç›¸å¯¹è·¯å¾„åŽ»è¯»æ–‡äšg.˜q™æ ·åšçš„¾~ºç‚¹æ˜¯æ¯”较难‹¹‹è¯•,而且自动化的‹¹‹è¯•æ›´éš¾.

比如说有˜q™æ ·ä¸€ä¸ªç±»Server,è¦æ ¹æ®server.propertiesæ¥åˆå§‹åŒ–,ä¸€å¼€å§‹çš„ä»£ç æ˜¯è¿™æ ïLš„:

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
* @author sting
*/
public class Server {
private static final String FILE = "conf" + File.separator + "server.properties";

public void initial() throws IOException {
FileInputStream in = new FileInputStream(System.getProperty("APP_HOME") + File.separator + FILE);
Properties properties = new Properties();
properties.load(in);
// initial
}
}

æ–‡äšg路径和文件å都是hard code,很难‹¹‹è¯•. 我们首先把initial()釿ž„一ä¸?代ç å¦‚下:


public void initial(InputStream in) throws IOException {
Properties properties = new Properties();
properties.load(in);
// initial
}

臛_°‘,‹¹‹è¯•æ—?我们å¯ä»¥ä¼ è¿›æ¥è‡ªå·Þqš„InputStream,也å¯ä»¥æ–¹ä¾¿çš„æ—¶å€™æµ‹è¯•用的server.properties,或者干脆ä‹É用内è”的文äšg,代ç å¦‚下:

class ServerTest extends TestCase {
private Server server;

public void setUp() throws Exception {
this.server = new Server();
}

public void testInitial() throws Exception {
String serverProperties = "port=8080\n" +
"run_mode=normal";
InputStream in = new ByteArrayInputStream(serverProperties.getBytes());

this.server.initial(in);
// assert
}
}

但是,在实际工作的代ç ä¸?æ–‡äšgå和路径ä¾ç„¶è¦hard code˜q›ä»£ç ä¸­.˜q™æ—¶,我们å¯ä»¥ä½¿ç”¨spring中的ResourceæŽ¥å£æ¥è¿›ä¸€æ­¥æ”¹˜q›æˆ‘们的代ç .

public class Server {
private Resource resource;

public void setResource(Resource r) {
this.resource = r;
}

public void initial() throws IOException {
Properties properties = new Properties();
properties.load(this.resource.getInputStream());
// initial
}
}

å†åР䏀ŒDµspring的酾|®æ–‡ä»?

<beans>
<bean id="server" class="Server">
<property name="resource" value="classpath:server.properties"/>
</bean>
</beans>

˜q™æ ·,Server的代ç å®Œå…¨ä¸Žæ–‡äšg的具体èµ\径和文äšgåæ— å…?仅仅用酾|®æ–‡ä»¶å°±å¯ä»¥æŒ‡å®š,表达更清æ¥?也更易于‹¹‹è¯•.

当然,ä»…é™äºŽå·²¾lä‹É用spring的项ç›?



django 2006-11-19 11:54 å‘表评论
]]>
使用GroboUtils˜q›è¡Œå¤šçº¿½E‹æµ‹è¯?/title><link>http://www.aygfsteel.com/stingh711/archive/2006/06/24/54800.html</link><dc:creator>django</dc:creator><author>django</author><pubDate>Fri, 23 Jun 2006 16:27:00 GMT</pubDate><guid>http://www.aygfsteel.com/stingh711/archive/2006/06/24/54800.html</guid><wfw:comment>http://www.aygfsteel.com/stingh711/comments/54800.html</wfw:comment><comments>http://www.aygfsteel.com/stingh711/archive/2006/06/24/54800.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stingh711/comments/commentRss/54800.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stingh711/services/trackbacks/54800.html</trackback:ping><description><![CDATA[被测试的¾c? Buffer.java<br /><br /><font face="Courier New">package test;<br /><br />import java.util.HashMap;<br />import java.util.Map;<br /><br /><br />/**<br /> * <br /> * @author sting<br /> */<br />public class Buffer {<br />    private static Buffer me = new Buffer();<br />    <br />    public static Buffer getInstance() {<br />        return me;<br />    }<br />    <br />    private Map<String, Integer> buff;<br />    <br />    private Buffer() {<br />        this.buff = new HashMap<String, Integer>();<br />    }<br />    <br />    public void put(String key, int value) {<br />            if (!(this.buff.containsKey(key))) {<br />                this.buff.put(key, value);<br />        }<br />    }<br />    <br />    public int get(String key) {<br />            if (this.buff.containsKey(key)) {<br />                return this.buff.get(key);<br />            }<br />            return 0;<br />    }<br />}</font><br /><br />TestCase: BufferTest.java<br /><font face="Courier New">package test;<br /><br />import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;<br />import net.sourceforge.groboutils.junit.v1.TestRunnable;<br />import junit.framework.TestCase;<br /><br /><br />/**<br /> * <br /> * @author sting<br /> */<br />public class BufferTest extends TestCase {<br />    private Buffer buff;<br />    <br />    protected void setUp() throws Exception {<br />        super.setUp();<br />        buff = Buffer.getInstance();<br />    }<br /><br />    protected void tearDown() throws Exception {<br />        super.tearDown();<br />    }<br /><br />    public void test() throws Throwable {<br />        TestRunnable[] runnables = new TestRunnable[] {<br />                new WriteToBuffer(buff, 10),<br />                new GetFromBuffer(buff, 10)<br />        };<br />        <br />        MultiThreadedTestRunner testRunner = <br />                new MultiThreadedTestRunner(runnables);<br />        testRunner.runTestRunnables();<br />    }<br />    <br />    private static class WriteToBuffer extends TestRunnable {<br />        private int value;<br />        private Buffer buff;<br />        <br />        public WriteToBuffer(Buffer buff, int value) {<br />            this.buff = buff;<br />            this.value = value;<br />        }<br />        <br />        @Override<br />        public void runTest() throws Throwable {<br />            buff.put("sting", value);<br />        }<br />    }<br />    <br />    private static class GetFromBuffer extends TestRunnable {<br />        private int value;<br />        private Buffer buff;<br />        <br />        public GetFromBuffer(Buffer buff, int value) {<br />            this.buff = buff;<br />            this.value = value;<br />        }<br />        <br />        @Override<br />        public void runTest() throws Throwable {<br />            assertEquals(value, buff.get("sting"));<br />        }<br />    }<br />}</font><br /><br />˜q行该test caseåQŒç»“果如下:<br />WARN [Thread-1] (MultiThreadedTestRunner.java:276) - A test thread caused an exception.<br />junit.framework.AssertionFailedError: expected:<10> but was:<0><br />    at junit.framework.Assert.fail(Assert.java:47)<br />    at junit.framework.Assert.failNotEquals(Assert.java:282)<br />    at junit.framework.Assert.assertEquals(Assert.java:64)<br />    at junit.framework.Assert.assertEquals(Assert.java:201)<br />    at junit.framework.Assert.assertEquals(Assert.java:207)<br />    at test.BufferTest$GetFromBuffer.runTest(BufferTest.java:75)<br />    at net.sourceforge.groboutils.junit.v1.TestRunnable.run(TestRunnable.java:154)<br />    at java.lang.Thread.run(Unknown Source)<br /><br />把Buffer.javaåŠ ä¸ŠåŒæ­¥å¤„ç†åQ?br /><font face="Courier New">public class Buffer {<br />    private static Buffer me = new Buffer();<br />    <br />    public static Buffer getInstance() {<br />        return me;<br />    }<br />    <br />    private Map<String, Integer> buff;<br />    <br />    private Buffer() {<br />        this.buff = new HashMap<String, Integer>();<br />    }<br />    <br />    public void put(String key, int value) {<br />        <font color="#ff0000">synchronized (this)</font> {<br />            if (!(this.buff.containsKey(key))) {<br />                this.buff.put(key, value);<br />            }<br />        }<br />    }<br />    <br />    public int get(String key) {<br />        <font color="#ff0000">synchronized (this)</font> {<br />            if (this.buff.containsKey(key)) {<br />                return this.buff.get(key);<br />            }<br />            return 0;<br />        }<br />    }<br />}<br /><br />‹¹‹è¯•通过ã€?br /><br />˜q™é‡Œåªæ˜¯ç”¨æœ€½Ž€å•çš„code演示了一下如何ä‹É用GroboUtilsé‡Œé¢æä¾›</font><font face="Courier New">TestRunnableå’?/font><font face="Courier New">MultiThreadedTestRunneræ¥ç¼–写多¾U¿ç¨‹çš„æµ‹è¯•代ç ã€‚其实也å¯ä»¥è‡ªå·±å†™codeåŽÀLµ‹è¯•,ä¸è¿‡å·²ç»æœ‰äh写了åQŒä¸ç”¨å†é‡å¤åŽÕdšäº†ã€‚Please refer to </font><font face="Courier New"><a >http://broboutils.sourceforge.net</a></font><font face="Courier New"> to get more information.</font><img src ="http://www.aygfsteel.com/stingh711/aggbug/54800.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stingh711/" target="_blank">django</a> 2006-06-24 00:27 <a href="http://www.aygfsteel.com/stingh711/archive/2006/06/24/54800.html#Feedback" target="_blank" style="text-decoration:none;">å‘表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> Ö÷Õ¾Ö©Öë³ØÄ£°å£º <a href="http://" target="_blank">¹Ì°²ÏØ</a>| <a href="http://" target="_blank">¿ªÔ¶ÊÐ</a>| <a href="http://" target="_blank">Ëì²ýÏØ</a>| <a href="http://" target="_blank">¶¼°²</a>| <a href="http://" target="_blank">Çà¸ÔÏØ</a>| <a href="http://" target="_blank">Â¹ÒØÏØ</a>| <a href="http://" target="_blank">»¨Ô«ÏØ</a>| <a href="http://" target="_blank">ÐÏÌ¨ÏØ</a>| <a href="http://" target="_blank">ÇàÉñÏØ</a>| <a href="http://" target="_blank">À¼ÏªÊÐ</a>| <a href="http://" target="_blank">Î×ÏªÏØ</a>| <a href="http://" target="_blank">ÄÏÐÛÊÐ</a>| <a href="http://" target="_blank">»ÆÃ·ÏØ</a>| <a href="http://" target="_blank">кÓÏØ</a>| <a href="http://" target="_blank">´óÇìÊÐ</a>| <a href="http://" target="_blank">ËÞǨÊÐ</a>| <a href="http://" target="_blank">Èð°²ÊÐ</a>| <a href="http://" target="_blank">¾Å½­ÊÐ</a>| <a href="http://" target="_blank">»áÔóÏØ</a>| <a href="http://" target="_blank">Á¬½­ÏØ</a>| <a href="http://" target="_blank">Îå´óÁ¬³ØÊÐ</a>| <a href="http://" target="_blank">±±°²ÊÐ</a>| <a href="http://" target="_blank">бö</a>| <a href="http://" target="_blank">½¶ÁëÏØ</a>| <a href="http://" target="_blank">¾°µÂÕòÊÐ</a>| <a href="http://" target="_blank">¶«º£ÏØ</a>| <a href="http://" target="_blank">Áê´¨ÏØ</a>| <a href="http://" target="_blank">³É¶¼ÊÐ</a>| <a href="http://" target="_blank">ÅîÀ³ÊÐ</a>| <a href="http://" target="_blank">°¢ÍßÌáÏØ</a>| <a href="http://" target="_blank">ÏÌÑôÊÐ</a>| <a href="http://" target="_blank">Íþº£ÊÐ</a>| <a href="http://" target="_blank">ËïÎâÏØ</a>| <a href="http://" target="_blank">³¤¸ðÊÐ</a>| <a href="http://" target="_blank">ÉÏÓÌÏØ</a>| <a href="http://" target="_blank">ÈÕÕÕÊÐ</a>| <a href="http://" target="_blank">º×ÇìÏØ</a>| <a href="http://" target="_blank">ÑνòÏØ</a>| <a href="http://" target="_blank">Îå¼ÒÇþÊÐ</a>| <a href="http://" target="_blank">¸·Æ½ÏØ</a>| <a href="http://" target="_blank">ÆëÆë¹þ¶ûÊÐ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>