0

Row Locking With MySQL

Source : http://www.xpertdeveloper.com/2011/11/row-locking-with-mysql/

Steps:
  1. Start tarnsaction
  2. Lock the desired row by using normal select statement and add FOR UPDATE or LOCK IN SHARE MODE in the back.
  3. Update the row(s)
  4. Commit (update) / Rollback (revert)
    For example :
        SELECT * FROM table_name WHERE id=10 FOR UPDATE;
        SELECT * FROM table_name WHERE id=10 LOCK IN SHARE MODE;

Any lock placed with LOCK IN SHARE MODE will allow other transaction to read the locked row but it will not allow other transaction to update or delete the row.

Any lock placed with the FOR UPDATE will not allow other transactions to read, update or delete the row. Other transaction can read this rows only once first transaction get commit or rollback. 
0

MySQL Cache

Source : http://www.techiecorner.com/45/turn-on-mysql-query-cache-to-speed-up-mysql-query-performance/

It's a very simple.
Simply add to my.ini and restart MySQL service.
query-cache-type = 1          [0 (disable / off), 1 (enable / on) and 2 (on demand)]
query-cache-size = 20M     [the cache size)]

It will boost the performance. For me almost 5x faster.

:)
0

GWT - Add touch support to canvas

I have worked in the image viewer with support GWT scroll and touch.
The audience images using canvas + SVG transformation is detected so that the image can be panned and zoomed.No problems with scrolls, but I have a problem when showing images on smart phones.I have tried several other methods to handle events on canvas in GWT but failed.

Finally, I found an example of event handling in native JS and give a try. Luckyly it works.
I lost the URL of the referring page, but I'll try to find and update this post later.

The example :
I put all the event declaration in a function.
private native void attachTouch(JavaScriptObject ele) /*-{
    var ref = this;
    ele.ontouchstart = function(evt) {
      evt.preventDefault();
      var x2=-100;
      var y2=-100;
      if(evt.touches.length > 1){
        x2=evt.touches[1].pageX;
        y2=evt.touches[1].pageY;
      }
      ref.@net.vcari.webipc.client.graphics.ImageViewerSvgPanel::setInitialTouch(IIII)(evt.touches[0].pageX, evt.touches[0].pageY,x2,y2);
    }
    ele.ontouchmove = function(evt) {
      evt.preventDefault();
      var x2=-100;
      var y2=-100;
      if(evt.touches.length > 1){
        x2=evt.touches[1].pageX;
        y2=evt.touches[1].pageY;
      }
      ref.@net.vcari.webipc.client.graphics.ImageViewerSvgPanel::onTouchMove(IIII)(evt.touches[0].pageX, evt.touches[0].pageY,x2,y2);
    }
    ele.ontouchend = function(evt) {
      evt.preventDefault();
      ref.@net.vcari.webipc.client.graphics.ImageViewerSvgPanel::onEndTouch(II)(evt.pageX, evt.pageY);
    }
  }-*/;

Add touch events to the canvas:
attachTouch(canvas.getElement());

Yayy.....
0

GWT Generic Event Bus

I was looking at GWT Event Bus implementation on MVP Design Pattern.I think it's good but I'm too lazy to write the event and eventhandler classes for each type of event.So I decided to wrote a helper to simplify the implementation.

May be someone is disagree with this solution.

EventBusGenericEventHandler.java
package net.vcari.webipc.client;

import com.google.gwt.event.shared.EventHandler;

public interface EventBusGenericEventHandler  extends EventHandler{
  void  onEventTrigger(EventBusGenericEvent event);
}

The event bus event handler.

EventBusGenericEvent.java
package net.vcari.webipc.client;

import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.event.shared.GwtEvent;

public class EventBusGenericEvent extends GwtEvent<EventBusGenericEventHandler>{
  public Type<EventBusGenericEventHandler> eventType;

  public ModelData dataModel;
  public List<ModelData> dataModelList;
  
  @Override
  public Type<EventBusGenericEventHandler> getAssociatedType() {
    return eventType;
  }

  @Override
  protected void dispatch(EventBusGenericEventHandler handler) {
    handler.onEventTrigger(this);    
  }

}

Event bus event. I use GXT modeldata in my application. I put extra variable for single data(ModelData) and List. I use 2 variable to avoid confusion between List and single ModelData (^&%@&YY(&@& - dirty solution. Hahahaha).


EventBusTypes.java
package net.vcari.webipc.client;

import com.google.gwt.event.shared.GwtEvent.Type;

public class EventBusTypes {
  
  /**
   * Set current location event type. Use to trigger data update for other location like in image viewer
   */
  public static Type<EventBusGenericEventHandler> setCurrentLocationEvent=new Type<EventBusGenericEventHandler>();
  
  /**
   * Set current location process updated event type
   */
  public static Type<EventBusGenericEventHandler> setCurrentLocationUpdatedEvent=new Type<EventBusGenericEventHandler>();
  
  /**
   * Set other location event type. Use to trigger data update for other location like in image viewer
   */
  public static Type<EventBusGenericEventHandler> setOtherLocationEvent=new Type<EventBusGenericEventHandler>();
  
  /**
   * Set other location process updated event type
   */
  public static Type<EventBusGenericEventHandler> setOtherLocationUpdatedEvent=new Type<EventBusGenericEventHandler>();
  
}
The registers of event types.

I  declare the event bus as static. It can be called from other class.
public static EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);


To trigger the event:
EventBusGenericEvent event = new EventBusGenericEvent();
event.eventType=EventBusTypes.setCurrentLocationEvent;
event.dataModel=pagingGrid.getGrid().getSelectionModel().getSelectedItem();
Application.EVENT_BUS.fireEvent(event);
Declare the event, set the type, set the data and fire the event.

To handle the event:

I think it's easier to declare the HandlerRegistration variable in module/class scope as it can be accessed anywhere inside the module/class. This is because it's required to remove the event handler when the container (like form or panel) is closed. If not, the event handler will be handled even the container has ben closed.
HandlerRegistration onSetOtherLocationHandlerRegistration;

Put the handler (may be in onRender function).
onSetOtherLocationHandlerRegistration=Application.EVENT_BUS.addHandler(EventBusTypes.setOtherLocationUpdatedEvent, new EventBusGenericEventHandler() {

      @Override
      public void onEventTrigger(EventBusGenericEvent event) {
        onSetOtherLocationEvent(event);
      }
    });

Finally, remove the handler when the form is closed / unloaded.
@Override
  protected void onUnload() {
    super.onUnload();
    onSetOtherLocationHandlerRegistration.removeHandler();
  }

Voila !!!

0

GWT - nocache.js cached

I got a problem when my GWT site keep notifying there is no file found for deferred binding js file. After simple investigation, I realize the main nocache.js file is cached. I thought it will be cache automatically but I was wrong.

A simple solution is to make web server to send a header not to cache the nocache.js files.
I found the solution here :
http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html
http://code.google.com/p/google-web-toolkit/issues/detail?id=4823

Simply modify the .htaccess file (I use this file for compression) and put the following configuration:

<filesMatch "\.(nocache.js)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>

or this one
<Files *.nocache.*>
  ExpiresActive on
  ExpiresDefault "now"
  Header merge Cache-Control "public, max-age=0, must-revalidate"
</Files>


Voila !!!. :)


 
 
 
Copyright © peyotest