Thursday, 17 July 2014

Fastest way to delete horizontal line in word document

If you’ve ever had a problem deleting a horizontal line in Microsoft Word, this post is for you. The answer is something of a trick, as the horizontal line is not a line (or a graphic), it’s a bottom border.


Remove one line:
1>select the paragraph above the line
2>then Ctrl + Q

Remove all lines in a area:
1>select the areas you want clear all lines
2>then Ctrl + Q

Thursday, 10 July 2014

MB Standard provider adapter - connecting to a different server via https webserivce

Just need to make sure the port is set to match.
Vision.ConsumerAdapter.Standard.ssl.port=443 //listening port

endpoints table
Gateway :
This is equivalent to 443 is the default https port.

Vision.ConsumerAdapter.Standard.ssl.port=8888 //listening port

endpoints table
Gateway :

Wednesday, 9 July 2014

DBCP - Database connection pool (Apache Common + JNDI)


Q:Why we need connection pool ?
A: Each time an application communicates with a database, a connection is required.
Opening and closing connections is time consuming.
A connection pool stores/caches connections, allowing them to be re-used by the application on demand. This increases performance dramatically in most cases.

Apache Common DBCP

Commons DBCP is a project by the Apache Software Foundation, which provides a database connection pool facility for a Java application.
The connection pool layer is separated from the JDBC driver and the application, providing an invisible layer between them.

Common Topics:

  • Maximum Active Connections - the maximum number of concurrent connections the pool should allow. After this limit, the pool will wait for a connection to become available before providing it to the caller. Too many concurrent connections to the database can decrease performance, so it is important to find an appropriate balance. Unless an application is extremely busy, 2-5 connections is usually plenty.
  • Max Idle Connections - the maximum number of idle connections that should be kept active. For example, if 5 connections are opened at the same time, then closed again, all 5 connections would normally remain in the pool until the application needs them again. If the Max Idle Connections setting is set to 2, then only 2 will be kept active, the other 3 will be closed until. When multiple applications connect to the same database server, this decreases the total number of connections to the database until they are needed.
  • Connection Leak - a situation which occurs when a connection is opened, then forgotten about. This is known as a "leak", because each time it happens, one less connection is available for re-use.

Some userful DBCP configuration, full configuration see this link.
initialSize0The initial number of connections that are created when the pool is started.
Since: 1.2
maxTotal8The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
maxIdle8The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
minIdle0The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none.
maxWaitMillisindefinitelyThe maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely.

More Information


Do I need to call Connection.close()? Won't the connection be closed automatically when the session is destroyed?
You must always call Connection.close() when using a connection pool. Physical database connections will only free up if the java object is destroyed.
  • If you are using a connection pool, the pool will retain a reference to the connection, meaning the garbage collector never sees it as an orphaned object, so never destroys it.
  • If your VM has a large heap (eg: 512mb RAM), it might take a long time for the garbage collection to even run at all
  • Even if the connection did close automatically, if you have a session timeout of 60 minutes, and have 100 people visit the site during an hour, those 100 connections would stay connected for the next hour.
  • Warning: if you do not close connections, a Connection Leak will occur, and your pool will run out of connections. When this happens, your application will pause indefinitely waiting for a connection to be freed up, and will need to be restarted manually.

How many connections should I allow in my connection pool?

In a local development environment, setting a connection pool to allow a maximum of 100 connections is ok, because you are the only user of the database. However, on a server, this can have disastrous effects.
Imagine if 50 applications were accessing the same database server, and each of them had 100 concurrent connections. That's 5000 connections in total. Using connections in this way wastes resources such as network sockets, file handles, and RAM.
Most sites should have a minimum of 2-3 connections and a maximum of 8-15. A site allowing 15 concurrent connections would be a very busy site, handling 15 concurrent page accesses (approx 200-400 concurrent users).
In a busy CMS, handling over 50 websites, it would make sense to have a higher number than 15 connections. In this case 15-25 is a more sensible limit.
Allowing too many connections also hides problems during development. If you are the only user accessing your development server, try setting your connection limit to between 2 and 5. If there is a connection leak (connections being opened, but not closed again), you should be able to find out quickly, before risking deployment to the production environment.

How can I set up a connection pool?

This wiki has many examples of using Database Connection Pools, using the Apache Commons DBCP mechanism which is built into Tomcat.
The following pages are a good place to start:

What are the benefits of connection pooling?

  • Connection details (username/password/URL) are all managed from a single location. This prevents duplication all through your code, which increases portability and makes moving between the development, test and production environments easier.
  • Connections are re-used, providing a significant performance increase to your application
  • Resource usage is less, providing increased server performance

Example setup connection pool DBCP via JNDI

Here is a example of java code access relational database via a connection pool provided by Apache Common DBCP via JNDI configuration.

In /conf/jndi.xml

<entry key="java:comp/env/db/messageBusDB">
      <bean id="localmysql-ds" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${MB.dataSource.driverClassName}"/>
        <property name="url" value="${MB.dataSource.url}/${MB.dataSource.dbname}"/>
        <property name="username" value="${MB.dataSource.username}"/>
        <property name="password" value="${MB.dataSource.password}"/>
        <property name="poolPreparedStatements" value="${MB.dataSource.poolPreparedStatements}"/>
        <property name="validationQuery" value="SELECT 1"/>
        <property name="testOnBorrow" value="true"/>
        <property name="maxActive" value="-1"/>

2>In project parent pom add:

3>In java code

    private static final String MB_DB_PATH = "java:comp/env/db/messageBusDB";
    private static final String PROVIDER_URI = "classpath:jndi.xml";
    private static final String INITIAL_CONTEXT_FACTORY
        = "org.apache.xbean.spring.jndi.SpringInitialContextFactory";

    private final JdbcTemplate template = createJdbcTemplate();
    private final QueryBundle queryBundle = new QueryBundle();

    private JdbcTemplate createJdbcTemplate() {
        try {
            Hashtable<String, String> env = new Hashtable<String, String>();
            env.put(Context.PROVIDER_URL, PROVIDER_URI);
            Context ctx = new InitialContext(env);
            return new JdbcTemplate((DataSource) ctx.lookup(MB_DB_PATH));

        } catch (NamingException e) {

        return null;

    private final JdbcTemplate template = createJdbcTemplate();
    private final QueryBundle queryBundle = new QueryBundle();

    //then you can use template to do query
    public final List queryForList(final NamedQuery namedQuery,
            final Object[] args,
            final Class elementType) throws SQLException {

        return template.queryForList(getSQL(namedQuery),
                args, elementType);

JNDI - Java Naming and Directory Interface

JNDI - Java Naming and Directory Interface

JNDI enables a Java program or JSP page to reference resources specified in or outside the application.
JNDI names are specified as a URI. They point to anything from simple strings to complex data structures such as a JDBC data source.
For example, here is a JSP <sql:query> tag that uses JNDI to access a data source. The data source object has a JNDI address of java:comp/env/jdbc/mydatabase. In JSP, this can be refered to simply as jdbc/mydatabase.
<sql:query var="result" dataSource="jdbc/mydatabase">
    SELECT product_id, name, price FROM products
The following example references the same information using Java, which uses the full JNDI URI.
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/mydatabase");
For both of the examples given above, the actual JDBC data source information is defined in META-INF/context.xml as a JNDI Resource.
JNDI Resources can be defined in:
  • server.xml in the <Context> tag
  • context.xml in the <Context> tag, as Resources (prefered)
  • web.xml as environment variables using the <env-entry> tag, although this is only useful for simple values
An example context.xml is displayed below, containing a single JNDI Resource, of the type javax.sql.DataSource.
<?xml version="1.0" encoding="UTF-8"?>
    <Resource name="jdbc/mydatabase" 
              validationQuery="select 1"

More information

Tuesday, 8 July 2014

Postgres - Server Status(view all connection client info)

Q:If you want to do:
how how many client has connected with postgres,
which query are they running,
When/how long the client has connected

Simple from pgAdmin Tools ->

Total visitors since Jan 2012

World Visitor Map