Total Pageviews

2017/09/11

[DB2] The transaction log for the database is full.

Problem
When I execute the following SQL statement:
DELETE FROM test_table where id between 1 and 500000;


I get the error log: 
The transaction log for the database is full.


How-To
This error resulted from "All space in the transaction log is being used."

I need to modify the delete statement into 5 SQL statement, delete 100000 records in each statement instead of delete 500000 at one time.

The updated delete SQL statement are the following:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- delete rownumber from 1 to 100000
DELETE
FROM test_table
WHERE id IN
    (
    SELECT id
     FROM
       (SELECT id,
               row_num() over(ORDER BY id) AS rownumber
        FROM test_table)
     WHERE rownumber BETWEEN 1 AND 100000 
     );

-- delete rownumber from 100001 to 200000     
DELETE
FROM test_table
WHERE id IN
    (
    SELECT id
     FROM
       (SELECT id,
               row_num() over(ORDER BY id) AS rownumber
        FROM test_table)
     WHERE rownumber BETWEEN 100001 AND 200000 
     );     

-- delete rownumber from 200001 to 300000     
DELETE
FROM test_table
WHERE id IN
    (
    SELECT id
     FROM
       (SELECT id,
               row_num() over(ORDER BY id) AS rownumber
        FROM test_table)
     WHERE rownumber BETWEEN 200001 AND 300000 
     );          

-- delete rownumber from 300001 to 400000          
DELETE
FROM test_table
WHERE id IN
    (
    SELECT id
     FROM
       (SELECT id,
               row_num() over(ORDER BY id) AS rownumber
        FROM test_table)
     WHERE rownumber BETWEEN 300001 AND 400000 
     );               

-- delete rownumber from 400001 to 500000           
DELETE
FROM test_table
WHERE id IN
    (
    SELECT id
     FROM
       (SELECT id,
               row_num() over(ORDER BY id) AS rownumber
        FROM test_table)
     WHERE rownumber BETWEEN 400001 AND 500000 
     );                    





2017/09/10

[webMethods] How to invoke a Flow Service from a Java Service and get its output values

Problem
假設我要呼叫另外一個 flow service,此 flow service 沒有 input parameter,會回傳一個 output parameter,parameter name 為 isAlive

若我要透過 Java code 呼叫此 flow service,且取得其 output value 的話,該怎麼撰寫?


How-To

若呼叫 flow service 的方式是 synchronous,以下為 code snippet:
1
2
3
4
5
6
7
8
    try {
        // Invokes any service published on the server with the given input arguments.
        IData iData = Service.doInvoke("test.work", "Ping_Server", IDataFactory.create());
        // Returns a String representation of the value at the specified key.
        String isAlive = IDataUtil.getString(iData.getCursor(), "isAlive");
    } catch (Exception e1) {
     e1.printStackTrace();
    }



若呼叫 flow service 的方式是 asynchronous,以下為 code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    try {
        // Invokes any service published on the server as a thread
        ServiceThread serviceThread = Service.doThreadInvoke("test.work", "Ping_Server", session, IDataFactory.create());
        // Returns the pipeline from the service running in this service thread.
        IData iData = serviceThread.getIData();
        // Returns a String representation of the value at the specified key.
        String isAlive = IDataUtil.getString(iData.getCursor(), "isAlive");
        loggerAsync(session, " is Alive = " + isAlive);
    } catch (Exception e) {
     e.printStackTrace();
    }

2017/09/09

如何查詢董監事酬勞

在買賣股票前,要看一下董監事酬勞分配比例是否過高,買到的股價是否合理,避免過度稀釋股東權益的公司。

根據現行制度,公司賺錢後,盈餘會先分給公司的董監事們與員工,意味著假設你買的這檔股票的盈餘是五元,若分配其中的一元給董監事與員工,最後分配給你的只剩下四元。

所以,需查明類似產業的公司董監酬勞與員工分紅的比例過高,影響了股東們配股的權益,同時,投資前要計算所能得到的股利,看看是否划算,再決定是否投資

你可以到公開資訊觀測站來查詢董監事酬勞 http://mops.twse.com.tw/mops/web/t119sb04,選擇條件後,按下查詢按鈕


你就可以得到相關資訊















2017/09/08

[webMethods] How to invoke a Flow Service from a Java Service

Problem
如何在 Java Service 中,呼叫一個 Flow Service?

How-To
按照不同的情境 (synchronous 或 asynchronous),與有參數或無參數,需呼叫不同的 API,JavaDoc 如下:
JavaDoc for asynchronous


JavaDoc for synchronous


Examples:
1. Asynchronous and DO NOT have input parameter
    Session session = Service.getSession(); 
    Service.doThreadInvoke("test.work", "Test_Flow", session, IDataFactory.create());


2. Asynchronous and HAVE input parameter (s)
    Session session = Service.getSession(); 
    
    IData input = IDataFactory.create();
        
    IDataCursor inputCursor = input.getCursor();
    IDataUtil.put(inputCursor, "input", " test test ");
    inputCursor.destroy();
    
    Service.doThreadInvoke("test.work", "Test_Flow", session, input);


3. Synchronous and DO NOT have input parameter
    Service.doInvoke("test.work", "Test_Flow", IDataFactory.create());


4. Synchronous and HAVE input parameter (s)
    IData input = IDataFactory.create();
        
    IDataCursor inputCursor = input.getCursor();
    IDataUtil.put(inputCursor, "input", " test test ");
    inputCursor.destroy();
    
    Service.doInvoke("test.work", "Test_Flow", input);

2017/09/07

How to call a REST service in webMethods Integration Server from commons-httpclient

Scenario
Assume I had created two REST Resources in webMethods, one is via HTTP Post method, another one is by HTTP Get method.

How do I test them by commons-httpclient?


How-to
Add two dependencies in your pom.xml
    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>


Here has sample code to demonstrate how to send  HTTP Post method and HTTP Get method using commons-httpclient:
package albert.practice.httpClient;

import java.io.IOException;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.io.IOUtils;

import com.google.common.base.Charsets;

public class HttpClientExample {

    private String post_uri = "http://10.12.14.28:5555/rest/test.restful.RestTest2";
    private String get_uri = "http://10.12.14.28:5555/rest/test.restful.RestTest3";
    private String inputJson = "{\"ip\":\"10.10.12.66\",\"state\": \"OFFLINE\"}";

    /**
     * Implements the HTTP POST method.
     * 
     * @return response code
     * @throws HttpException
     * @throws IOException
     */
    public int sendPost() throws HttpException, IOException {
        AuthScope authScope = getAuthScope();
        Credentials credentials = getCredentials();

        HttpClient client = new HttpClient();
        client.getState().setCredentials(authScope, credentials);

        PostMethod postMethod = new PostMethod(post_uri);
        postMethod.setDoAuthentication(true);
        postMethod.setParameter("data", inputJson);

        return client.executeMethod(postMethod);
    }

    /**
     * Implements the HTTP GET method.
     * 
     * @return the response string of the HTTP method
     * @throws HttpException
     * @throws IOException
     */
    public String sendGet() throws HttpException, IOException {
        String responseString = "";

        AuthScope authScope = getAuthScope();
        Credentials credentials = getCredentials();

        HttpClient client = new HttpClient();
        client.getState().setCredentials(authScope, credentials);

        GetMethod getMethod = new GetMethod(get_uri + "?input=albert");
        getMethod.setDoAuthentication(true);

        int statusCode = client.executeMethod(getMethod);
        if (HttpStatus.SC_OK == statusCode) {
            responseString = IOUtils.toString(getMethod.getResponseBodyAsStream(), Charsets.UTF_8);
        }
        return responseString;
    }

    /**
     * Set authentication scope.
     * 
     * @return authentication scope
     */
    private AuthScope getAuthScope() {
        String ip = "10.12.14.28";
        int port = 5555;
        String realm = AuthScope.ANY_REALM;

        AuthScope authScope = new AuthScope(ip, port, realm);
        return authScope;
    }

    /**
     * Set the authentication credentials for the given scope.
     * 
     * @return credentials
     */
    private Credentials getCredentials() {
        String username = "cctv";
        String password = "cctv";
        Credentials credentials = new UsernamePasswordCredentials(username, password);
        return credentials;
    }

}


Here has the test code:
package albert.practice.httpClient;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;

import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.junit.Before;
import org.junit.Test;

public class HttpClientExampleTest {

    private HttpClientExample httpClientExample;

    @Before
    public void setup() {
        httpClientExample = new HttpClientExample();
    }

    @Test
    public void testSendPost() throws HttpException, IOException {
        int statusCode = httpClientExample.sendPost();
        assertEquals(HttpStatus.SC_OK, statusCode);
    }

    @Test
    public void testSendGet() throws HttpException, IOException {
        String responseString = httpClientExample.sendGet();
        System.out.println("responseString = " + responseString);
        assertNotNull(responseString);
    }

}