Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4 - Mailing list pgsql-jdbc

From Віталій Тимчишин
Subject Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
Date
Msg-id AANLkTinbK92ZRqUqgfnB41NCgzX59xUa+Byt5EkFTa9n@mail.gmail.com
Whole thread Raw
In response to Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4  (Dave Cramer <pg@fastcrypt.com>)
Responses Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4  (Dave Cramer <pg@fastcrypt.com>)
List pgsql-jdbc


2011/3/28 Dave Cramer <pg@fastcrypt.com>
On Mon, Mar 28, 2011 at 9:27 AM, Lew <noone@lewscanon.com> wrote:
> Chris Wareham wrote:
>>
>> Dave Cramer wrote:
>>>
>>> Ok, looking at the hibernate source this is what is in the
>>> PostgreSQLDialect
>>>
>>> public String getIdentitySelectString(String table, String column, int
>>> type) {
>>>  return new StringBuffer().append("select currval('")
>>>    .append(table)
>>>    .append('_')
>>>    .append(column)
>>>    .append("_seq')")
>>>    .toString();
>>>  }
>>> }
>
>> Just as an aside, should that not be using a StringBuilder rather than
>> a StringBuffer? Or does Hibernate still explicitly support Java 1.4?
>
> My Red-Flag-O-Meter triggered on that, too.  What Hibernate ought to do is:
>
>  return "select currval('" + table + '_' + column + "_seq')";
>
> for Pete's sake.


Really ??? the last time I checked the above will generate approx 5
objects StringBuffer.append is the recommended use for java 1.4,
StringBuilder is only marginally faster as it not synchronized.

+ or concat is much slower as it creates a new object each time and
copies the old into the new.

Have just checked with decompiler - It is exactly same if 1 expression with multiple pluses is used, one StringBuilder (StringBuffer for J1.4) is created, then multiple .append calls, then toString. Explicit StringBuilder should be used only in multiple expressions (e.g. in famount str += value in for circle). For single expression "+" gives same result, but is more readable and will choose StringBuilder/StringBuffer automatically depending on java version.

--
Best regards,
 Vitalii Tymchyshyn

pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
Next
From: Chris Wareham
Date:
Subject: Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4