zwwcn

Just another WordPress.com site

Monthly Archives: May 2011

Replace Text in MySQL Database using SQL

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);

 

 

SELECT REPLACE(‘www.mysql.com’, ‘w’, ‘Ww’);

 

Ref:

http://www.mydigitallife.info/how-to-find-and-replace-text-in-mysql-database-using-sql/

JPA Modeling

CVS Default port

should be 2401

grep cvs /etc/services

Set limit in JPA

Use setMaxResults to generate “Limit” in SQL


public Notes findNotesForProspect(Customer prospect){
return (Notes)em.createNamedQuery("Notes.FindByProspect")
.setParameter("prospect", prospect)
.setMaxResults(1);
}

ignore validation check when clicking Cancel

Add  immediate=”true” will ignore validation check and redirect the page immediatly.

<h:commandButton id=”cancelContactButton” immediate=”true” type=”submit” value=”Cancel” action=”#{masterCustDetailsAction.cancelContactType}”>

Datamodel and Factory method

We need to add @Out annotation to make it work


@Out(required=false)
private List<NationalAccount> masterNationalAccountList;

@Factory("masterNationalAccountList")
public void findMasterNationalAccounts(){
masterNationalAccountList =  em.createNamedQuery("NationalAccount.findAllNationalAccountByMaster")
.setParameter("master", AdvisorUtil.getMaster(getCurrentUser().getAdvisor()))
.getResultList();
}

<li>
<h:outputLabel for="goto"  value="National Account:" />
<h:selectOneMenu id="nationalAccount"  styleClass="input smaller"  value="#{prospectController.nationalAccount}" >
<s:selectItems value="#{masterNationalAccountList}"
var="_nationalAccount"
label="#{_nationalAccount.nationalAccountName}"/>
</h:selectOneMenu>
</li>

SQL add new column

ALTER TABLE test_posts ADD sticky boolean NOT NULL default false 

BigDecimal compare to a specific value

BigDecimal.valueOf:

taxComponent.getTax().getRate().compareTo(BigDecimal.valueOf(0.12500))==0

rich:calendar a4j:support


<rich:calendar popup="true" id="createdDate" value="#{currentInvoice.createdDate}"
buttonIcon="/images/icons/calendar.gif" datePattern="dd-MM-yy"  required="true">
<a4j:support event="onchanged" reRender="invItemTable" action="#{invoiceDetailAction.setSelectedDate()}" ajxSingle="true"/>
</rich:calendar>

event=”onchanged” will triger the action after you selecting the date

event=”ondateselected” will triger the action after you click the rich calendar component(before you selecting any date)

Cascade JPA Hibernate

E.g:


@OneToMany(mappedBy="invoice",fetch=FetchType.LAZY,cascade={CascadeType.ALL})
@OrderBy("lineNumber")
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public List<CodeEntry> entries;

If you are using it with Hibernate, you’ll have to explicitly define org.hibernate.annotations.CascadeType.DELETE_ORPHAN, which can be used in conjunction with JPA CascadeType.ALL.