2015年8月26日 星期三

mysqldump data structure

mysqldump -upassword -ppassword --add-drop-table --no-data BR201312111529 > tables.sql


 mysqldump -upassword -ppwassword BR201312111529 SETTINGS  >SETTINGS.sql

INSERT INTO COMPANY_POLICY SELECT * FROM  BR201312111529.COMPANY_POLICY;


2015年8月20日 星期四

mysql-procedure update all po SALES_ORDER_INV_DESC row_no

delimiter $$
drop procedure updateSALES_ORDER_INV_DESCRowNo $$
CREATE PROCEDURE updateSALES_ORDER_INV_DESCRowNo ()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE mrow INT ;
declare mRECORDID varchar(20);
declare mPARENT_RECORDID varchar(20) DEFAULT '';
declare mLAST_PARENT_RECORDID varchar(20) DEFAULT '';
DEClARE SALES_ORDER_INV_DESC_cursor CURSOR FOR SELECT PARENT_RECORDID,RECORDID FROM SALES_ORDER_INV_DESC ORDER BY PARENT_RECORDID;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN SALES_ORDER_INV_DESC_cursor;
get_recordid: LOOP
FETCH SALES_ORDER_INV_DESC_cursor INTO mPARENT_RECORDID, mRECORDID;
IF done THEN
LEAVE get_recordid;
END IF;
/**********/
IF mPARENT_RECORDID<>mLAST_PARENT_RECORDID THEN
SET mLAST_PARENT_RECORDID=mPARENT_RECORDID;
SET MROW=1;
END IF;
UPDATE SALES_ORDER_INV_DESC SET ROW_NO=MROW,TIMESTAMP=TIMESTAMP WHERE RECORDID=MRECORDID AND ROW_NO=0;
SET MROW=MROW+1;
/**********/
END LOOP get_recordid;
END;
$$
DELIMITER ;
call updateSALES_ORDER_INV_DESCRowNo ();



/**************************************************************/

delimiter $$
drop procedure updatePoRowNo $$
CREATE PROCEDURE updatePoRowNo ()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE mrow INT ;
declare mRECORDID varchar(20);
declare mPARENT_RECORDID varchar(20) DEFAULT '';
declare mLAST_PARENT_RECORDID varchar(20) DEFAULT '';
DEClARE po_cursor CURSOR FOR SELECT PARENT_RECORDID,RECORDID FROM PO ORDER BY PARENT_RECORDID;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN po_cursor;
get_recordid: LOOP
FETCH po_cursor INTO mPARENT_RECORDID, mRECORDID;
IF done THEN
LEAVE get_recordid;
END IF;
/**********/
IF mPARENT_RECORDID<>mLAST_PARENT_RECORDID THEN
SET mLAST_PARENT_RECORDID=mPARENT_RECORDID;
SET MROW=1;
END IF;
UPDATE PO SET ROW_NO=MROW WHERE RECORDID=MRECORDID;
SET MROW=MROW+1;
/**********/
END LOOP get_recordid;
END;
$$
DELIMITER ;
call updatePoRowNo ();



/*********************************************************/

delimiter $$
drop procedure updatePAYMENT_LINERowNo $$
CREATE PROCEDURE updatePAYMENT_LINERowNo ()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE mrow INT ;
declare mRECORDID varchar(20);
declare mPARENT_RECORDID varchar(20) DEFAULT '';
declare mLAST_PARENT_RECORDID varchar(20) DEFAULT '';
DEClARE PAYMENT_LINE_cursor CURSOR FOR SELECT PARENT_RECORDID,RECORDID FROM PAYMENT_LINE ORDER BY PARENT_RECORDID;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN PAYMENT_LINE_cursor;
get_recordid: LOOP
FETCH PAYMENT_LINE_cursor INTO mPARENT_RECORDID, mRECORDID;
IF done THEN
LEAVE get_recordid;
END IF;
/**********/
IF mPARENT_RECORDID<>mLAST_PARENT_RECORDID THEN
SET mLAST_PARENT_RECORDID=mPARENT_RECORDID;
SET MROW=1;
END IF;
UPDATE PAYMENT_LINE SET ROW_NO=MROW WHERE RECORDID=MRECORDID;
SET MROW=MROW+1;
/**********/
END LOOP get_recordid;
END;
$$
DELIMITER ;
call updatePAYMENT_LINERowNo ();

















2015年8月16日 星期日

java Pass by-value or Pass by-reference


static void doubleNumber (int input1, intClass input2)
{input1=input1*2; input2.number=input2.number*2;}


In general, there are two ways that a computer language can pass an argument to a subroutine. The first way is pass-by-value. This method copies the value of an argument into the formal parameter of the subroutine. Therefore, changes made to the parameter of the subroutine have no effect on the argument.

The second way an argument can be passed is pass-by-reference. In this method, a reference to an argument (not the value of the argument) is passed to the parameter. Inside the subroutine, this reference is used to access the actual argument specified in the call. This means that changes made to the parameter will affect the argument used to call the subroutine.

As you will see, Java uses both approaches, depending upon what is passed.

In Java, when you pass a primitive / simple type to a method, it is passed by value. Thus, what occurs to the parameter that receives the argument has no effect outside the method.

When you pass an object to a method, the situation changes dramatically. because objects are passed by reference. Keep in mind that when you create a variable of a class type, you are only creating a reference to an object. Thus , when you pass this reference to a method, the parameter that receives it will refer to the same object as that referred to by the argument. This effectively means that objects are passed to methods by use of call-by--reference. Changes to the object inside the method do affect the object used as an argument.




2015年8月1日 星期六

java local variable vs class variable


source : http://stackoverflow.com/questions/5539652/using-a-class-variable-vs-sending-local-variable-to-functions-methods

local variable to a function/method as a parameter, rather than using a class variable in place of the function/method variable.

The only answer out of the blue, for a any generic case is: it depends on your specific case. Data members, static members and function arguments all serve different purposes. Of course, there are some key tips we can give for what types of signs you should look for choosing one or the other.

Typical cases:

Data member: the value is part of the object's (as in instance of a class) state. You want other calls to methods to reflect this particular state.
Static member: the value has simultaneous, identical meaning to all instances of the class. This is typically used only for constants (even when initialized at runtime, like a singleton) but in some cases, there is need for mutable class state.
Function argument: the value has meaning only for a specific execution of the function/method. This value is subject to change from one invocation to the next.
There are some common symptoms of bad choice.

Consider the following questions:

Do you always pass the same value to a method, no matter where you call it from? Consider making the argument a constant and hiding the argument away. Consider defining overloads: one without argument for the common case and one with argument for flexibility.
Do you need to set a data member (via a setter) every single time you invoke the function? Consider making the value an argument to the function. There's no need to save on the function signature if you need to replace each call with two lines to set the value before hand.
I'm under the impression that you and your co-worker are in a simple misunderstanding of the nature of this parameter. Make sure you clearly understand your co-worker's arguments and make yourself clear. Try to rephrase what it is that you're trying to say.

java-servlet instance variables , method variable

source : http://stackoverflow.com/questions/2183974/difference-between-each-instance-of-servlet-and-each-thread-of-servlet-in-servle

When the Servlet container starts, it:

reads web.xml;
finds the declared Servlets in the classpath; and
loads and instantiates each Servlet only once.
Roughly, like this:

String urlPattern = parseWebXmlAndRetrieveServletUrlPattern();
String servletClass = parseWebXmlAndRetrieveServletClass();
HttpServlet servlet = (HttpServlet) Class.forName(servletClass).newInstance();
servlet.init();
servlets.put(urlPattern, servlet); // Similar to a map interface.
Those Servlets are stored in memory and reused every time the request URL matches the Servlet's associated url-pattern. The servlet container then executes code similar to:

for (Entry<String, HttpServlet> entry : servlets.entrySet()) {
    String urlPattern = entry.getKey();
    HttpServlet servlet = entry.getValue();
    if (request.getRequestURL().matches(urlPattern)) {
        servlet.service(request, response);
        break;
    }
}
The GenericServlet#service() on its turn decides which of the doGet(), doPost(), etc.. to invoke based on HttpServletRequest#getMethod().

You see, the servletcontainer reuses the same servlet instance for every request. In other words: the servlets are shared among every request. That's why it's extremely important to write servlet code the threadsafe manner --which is actually simple: just do not assign request or session scoped data as servlet instance variables, but just as method local variables. E.g.

public class MyServlet extends HttpServlet {

    private Object thisIsNOTThreadSafe;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Object thisIsThreadSafe;

        thisIsNOTThreadSafe = request.getParameter("foo"); // BAD!! Shared among all requests!
        thisIsThreadSafe = request.getParameter("foo"); // OK, this is thread safe.
    }
}