What is the currently active workspace in Eclipse

Standard

Imagine you are dealing with multiple workspaces, which for example can be expected if you split up a code base in several Eclipse projects and you are working on several releases at once. Now wouldn’t it be handy if Eclipse would tell you which workspace is active?

Increase workspace history and derive from this list

You can derive from the workspace history list which workspace isn’t in there: that one will be the one currently active. This is the list you see when you got to File -> Switch Workspace.

Depending on how many workspaces you need, you might want to increase the size of the workspace history. You can configure this setting at:

Window -> Preferences -> General -> Startup and Shutdown -> Workspaces -> ‘Number of workspaces to remember’

How to Insert Excel Table with Borders in Gmail

Standard

googlI couldn’t find any way in Gmail to create tables. But there are of course other options Google opened in front of you. We have to think differently to create tables with borders in Gmail. You can create tables in the Google Doc and paste them to Gmail. No need to install any separate software to do this. But here we are going to learn how to paste Excel Table in Gmail with boarders.

Steps to Create a Table in Gmail with Boarder

Copy the Excel table.

Then on a new tab on your browser sign in to Google Drive (you can use your same Gmail address and password to go to Google Drive)

Under the Google Logo click on Create->Spreadsheet. It will open Google Spreadsheet.

Click on any cell and paste the copies excel table. It will get pasted without boarders.

Select the table and apply boarders by clicking on the Boarders icon.

Gmail Table

If you want you can adjust the column and row borders just like in Excel. Ensure that the copied contents are correct.

Select the Table and copy it (Ctrl+C)

Go to Gmail Compose window and paste the copied content. You can see that the table copied with boarders in Gmail.

Gmail Table

That’s all. When you want to create a table in Excel you can follow the above tutorial.

The above step is useful when you have already a table in Excel that you want to paste in Gmail. But if you want to create a new table with boarders in Gmail, directly create it in Google Doc Spreadsheet and then paste in Gmail Compose.

Enable telnet in Windows

Standard

How to turn on telnet in Windows

1. Open the Control Panel.

2. Click on Uninstall or Change a Program.

3. Click on Turn Windows Features On or Off.

4. Click on Telnet Client and Telnet Server.

5. Telnet will be installed.

6. Now, You can access telnet from the command prompt by typing “telnet” without the quotes.

mysql group_concat truncated result

Standard

Be aware if you are using group_concat() in MySQL query.

With default settings it may truncate your result if it’s return long length string data.

Yes if result of “group_concat()” contained MySQL query is very long String, it may give you truncated String result without any error.

Now, let’s see how to verify and resolve this error/issue.

According to the MySQL manual, the maximum length of `GROUP_CONCAT` is defined by the `group_concat_max_len` system variable, which defaults to 1024.

Query to check variable’s value :


show VARIABLES like 'group_concat_max_len';

This value can be increased, by using the following command:(Quick Modification in variable value, without restart the service)


SET [GLOBAL | SESSION] group_concat_max_len = 1048576; -- Equals to 1M

Or make changes in mysql.ini file(Permanent change,require mysql service restart),


[mysqld]

group_concat_max_len=1M

It should be noted, however, that the value of `group_concat_max_len` is itself limited by the value of another system variable, `max_allowed_packet`, which defaults to 1,048,576.

This value can be increased to a maximum of 1,073,741,824 using the same syntax

change mysql auto increment value

Standard

To change increment value of any MYSQL table, first check the current Auto Increment value of the table with this,

SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = "DATABASE NAME"
AND TABLE_NAME = "TABLE NAME";

Then, change the Auto Increment value with below query,

ALTER TABLE tbl AUTO_INCREMENT=310;

SQL inside Hibernate Criteria

Standard

Earlier we have seen, how a custom criterion could be created to handle special scenarios. However this may seem overkill if the condition can be easily expressed using native SQL. For Criteria allows us to add custom SQL expressions which get added in the where clause.

Here, I took the same scenario as the custom criteria – checking the length of a string column:

public static void testViaSql() {
    final Session session = sessionFactory.openSession();
    Criteria criteria = session.createCriteria(Entity.class);
    criteria.add(Restrictions.sqlRestriction(
            "length({alias}.name)< ?", 5, Hibernate.INTEGER)); 
    List<Entity> entities = criteria.list();
    System.out.println(entities);
}

The result is :

select
        this_.ID as ID0_0_,
        this_.NAME as NAME0_0_,
        this_.DATE as DATE0_0_,
        this_.MASTER_ID as MASTER4_0_0_ 
    from
        ENTITY this_ 
    where
        length(this_.name)< ?

As can be seen the restriction was added to the generated SQL query – with one tiny change: The {alias} parameter was replaced with the alias used for the table Entity.
The {alias} here represents the root class – the class for which the criteria is created. Also the “name” used in the SQL string represents the column name and not the class property. (This is SQL remember.)
The Restrictions.sqlRestriction method also has two more parameters – an object that will be substituted for the question mark. The third is the Hibernate built-in type. In this case as our parameter is an integer, we pass the INTEGER type.

What if we do not have any parameters ?

public static void testViaSql_Simpler() {
    final Session session = sessionFactory.openSession();
    Criteria criteria = session.createCriteria(Entity.class);
    criteria.add(Restrictions.sqlRestriction("{alias}.master_id = 2"));
    List<Entity> entities = criteria.list();
    System.out.println(entities);
}

As can be seen there is an overloaded version that allows for just the where condition to be specified – without any parameters.

This facility can be used to create much more complex queries too.

public static void testViaSql_Complex() {
    final Session session = sessionFactory.openSession();
    Criteria criteria = session.createCriteria(Entity.class);
    criteria.add(Restrictions
            .sqlRestriction("{alias}.master_id = "
                    + "(select id from entity_master where data like 'master No 1')"));
    List<Entity> entities = criteria.list();
    System.out.println(entities);
}

The SQL is:

select
        this_.ID as ID0_0_,
        this_.NAME as NAME0_0_,
        this_.DATE as DATE0_0_,
        this_.MASTER_ID as MASTER4_0_0_ 
    from
        ENTITY this_ 
    where
        this_.master_id = (
            select
                id 
            from
                entity_master 
            where
                data like 'master No 1'
        )

In this case we used it to fire nested queries. The subquery feature is also available directly in the Criteria API and we shall see that in the next post.

Hibernate Custom Criterion : Check The Length of String Properties

Standard

We have seen Hibernate’s set of Restrictions and they cover a very large range of queries but not all. In Hibernate criterion we can not check String property length with existing functionality.

However Hibernate also allows the creation of a custom Criterion that can be used in the criteria.

Here, I created a simple Criterion class that is used to check the length of string properties like below SQL query,

select * from ENTITY where length(NAME) = 7;

Custom Criterion class

@SuppressWarnings("serial")
public class LengthExpression implements Criterion {
    private final String propertyName;
    private final int value;

    public LengthExpression(final String propertyName, final int value) {
        this.propertyName = propertyName;
        this.value = value;
    }

    @Override
    public String toSqlString(final Criteria criteria,
            final CriteriaQuery criteriaQuery) throws HibernateException {
        criteriaQuery.getFactory().getDialect();
        final String[] columns = criteriaQuery.getColumnsUsingProjection(
                criteria, this.propertyName);
        final String queryFragment = "length(" + columns[0] + ") = ?";
        return queryFragment;
    }

    @Override
    public TypedValue[] getTypedValues(final Criteria criteria,
            final CriteriaQuery criteriaQuery) throws HibernateException {
        // An ordered pair of a value and its Hibernate type
        return new TypedValue[] { new TypedValue(Hibernate.INTEGER,
                Integer.valueOf(value), EntityMode.POJO) };
    }
}

In the above code:

The class implements the Criterion Interface which exposes two methods.
The toSqlString() method is what generates the actual sql fragment. As we work with prepared statements, “?” ares used. In this case the sql length function is used. The alias used for property in the actual query is obtained using the getColumnsUsingProjection() method.
The getTypedValues() method tells Hibernate about the data Type to be used in the query. In this case the parameter will be set using the preparedStatement.setInt() method.

To test this code, I used it in a criteria example:

public static void testCriterion() {
    final Session session = sessionFactory.openSession();
    Criteria criteria = session.createCriteria(Entity.class);
    criteria.add(new LengthExpression("name", 7));        
    List<Entity> entities = criteria.list(); 
    System.out.println(entities);
}

The result of the execution is below:

3484 [main] DEBUG org.hibernate.SQL  - 
    /* criteria query */ 
    select
        this_.ID as ID0_0_,
        this_.NAME as NAME0_0_,
    from
        ENTITY this_ 
    where
        length(this_.NAME) = ?

Mysql Database Backup & Restore

Standard

What is the quickest way to backup restore mysql database?

First open command prompt(cmd) and get folder location from where we want to generate backup file or want to read file for restore.

For Local Access

Backup:

c:\> mysqldump -u root -p db_name > file_name.bkp

Restore:

c:\> mysql -u root -p db_name < file_name.bkp

For Remote Access

Backup:

c:\> mysqldump -h server_ip -u root -p db_name > file_name.bkp

Restore:

c:\> mysql -h server_ip -u root -p db_name < file_name.bkp

Then, it will prompt for password and done.

Note: Backup file will not support in all mysql version to restore. so first verify version. For that kind of problem you can find different different solution as per two version of mysql. like,

Backup:(–routines)

c:\> mysqldump --routines -u root -p db_name > file_name.bkp

For Restore it will same as above noted.

Hello world!

Standard

Welcome to Jubin’s Technical Blog. This is my first post before I start to Post .

I need your help friends. Let me suggest new topics/ links or subject to write for my Blog or you can send me your content at blog@jubinpatel.com and I will post your blog and may give you chance to write for me.