Dialect support for SQL comments.
by Daniel Bell
Hi,
I have recently tried turning on SQL comments in hibernate 3.2.6.ga.
However, I found that our database (informix 7.31) did not support SQL
where the comment was at the start of the comment. Instead, the comment
needed to be after the SQL. For example:
/* not accepted by informix 7.31*/ select * from systables;
select * from systables /* accepted by informix 7.31*/
Because of this, I have added a method to the Dialect for adding comments:
/**
* Add a comment to the SQL string.
*
* @param sql StringBuffer holding the SQL.
* @param comment Comment to add to the SQL. May be null.
*/
public void addCommentToSql(StringBuffer sql, String comment) {
if (StringHelper.isNotEmpty(comment))
sql.insert(0, "/* " + comment + " */ ");
}
Thus, the default implementation provides the same functionality as
before. However, derived Dialects may override this method to add the
comment in a different location.
It is also possible to add additional comments in the derived Dialect.
In our case, we also add the Java thread ID.
I have included a complete patch for this change for hibernate 3.2.6.GA.
Please consider its inclusion in Hibernate.
Thanks,
Daniel.
16 years, 5 months
Re: [hibernate-dev] HSEARCH-189 & concurrency
by Sanne Grinovero
Hi Pavitar Singh,
I thank you very much about your explanations but actually I opened the
issue myself
because I have read the same specs and am aware of that.
in H.Search (and several other hibernate code) there's this quite common
pattern for starting
"replaceable" objects (something like user-written plugins, you can provide
your own implementation
to do some stuff) but this same pattern is also used to start the built-in
default strategies.
It looks like this:
- an empty constructor, to use class.newInstance();
- an initialize() to set configuration options
- a start() method (eventually) used to start background tasks
- some doStuff() and/or getXX() which need to be fast & threadsafe
As you can see in Concurrecy in Practice at page 50, this is BAD, as for
example in the FSSlaveDirectoryProvider nobody takes care of locking
or visibility, and nobody is doing anywhere where I see this pattern used
(several times in the project).
I'm not saying it is all broken, because usually the threads consuming
these unsafely-initialized objects are started after the initialization, so
that's ok. In this specific case the state will be used to communicate
between threads, so some visibility fix is needed.
I know I could use it only for final fields, but this is exactly what I
want:
there are currently 10 instance variables, of these
4 have no concurrent use
4 are configuration constants and could use the "final" (they're not safely
published)
2 would need some lock/volatile anyway, bot only one is used frequently, so
IMHO 1 volatile is ok.
I was thinking in using the same Piggyback technique you mention to
safely publish the initialization constants,
but I'm afraid the code will become more difficult to maintain and more
"unreadable", possibly breaking at the first next patch:
IMHO using some unchanging fields "final" is the most clean and
readable solution (and best performing), but I need a different
constructor for that.
your opinion is really welcome as I couldn't find other feedback,
if you would like to take a look at the sources download the Search trunk
and look at:
org.hibernate.search.store.FSSlaveDirectoryProvider
or the FIXME in
org.hibernate.search.reader.SharingBufferReaderProvider
Sanne
2008/7/4 Pavitar Singh <pavitar.singh(a)gmail.com>:
> Hi Sanne,
>
> I don't think moving everything in constructor can guarantee safe
> publication.
>
> From the JMM Specification Section 3.5
>
> "An object is considered to be completely initialized when its constructor
> finishes. A thread that can only see a reference to an object after that
> object has been completely initialized is guaranteed to see the correctly
> initialized values for that object's final fields."
>
> That means there are no guarantees for other fields which are non-final.
>
> But once things are moved in constructor then by using Safe Publication one
> can enforce visibility guarantees.
>
> Other thing i was wondering was why do one need to make every field as
> volatile. As just by using a single volatile variable one can enforce memory
> barriers. A technique documented in JCIP as Piggyback Synchronizations and
> used by Doug Lea in implementing ConcurrentHashMap.(You will find get method
> in ConcurrentHashMap is without any locking and visibility is enforced by
> use of a single volatile variable.)
>
> Also if you can elaborate more on how you are facing the visibility issue
> then may be i can also spend time on it on figuring performant solution.
>
> Regards
> Pavitar Singh
> http://pitfalls.wordpress.com
>
> On Fri, Jul 4, 2008 at 5:13 AM, Sanne Grinovero <sanne.grinovero(a)gmail.com>
> wrote:
>
>> Hello all,
>> I'm sorry I've been very busy but as promised I would like to fix
>> HSEARCH-189
>> (and others) very soon;
>>
>> I would like to propose a API extension (backwards compatible) that would
>> simplify the patch a lot:
>> keeping it as is it is very tricky to fix the visibility issues in
>> FSSlaveDirectoryProvider
>> and FSMasterDirectoryProvider without introducing a performance penalty.
>>
>> I have these options to close the issue:
>> 1) add a "volatile" to more than six fields per class (ugly and not good
>> for performance)
>> 2) use some Locks/synch (more readable, still performance hits)
>> 3) move the "initialize" arguments to a constructor.
>>
>> As Emmanuel knows I would really love the third option, but he's worried
>> about
>> the fact we can't force a constructor in an interface*1, so my proposal
>> is:
>>
>> if we find there exists a constructor having the same arguments as the
>> initialize method,
>> we use that, otherwise we use a no-arg constructor and then call the
>> initialize.
>>
>> Reflection is used anyway to instantiate these components,
>> the code in DirectoryProviderFactory doesn't get much more complicated
>> and much more cleanup is made possible in all DPs because of this
>> (as the equals/hashcode comments already ask for).
>>
>> I actually think this same pattern is needed for other components,
>> such as all ReaderProvider, so I hope you'll want to give it a try
>> and let me apply it on other components too if you like the resulting
>> code.
>>
>> Sanne
>>
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev(a)lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>
>>
>
>
> --
> Pavitar Singh
> Blog: http://pitfalls.wordpress.com
16 years, 5 months
Search initialization: remove WeakHashMap?
by Sanne Grinovero
Hello,
does the resolution of HSEARCH-209 imply we can get rid of the
private static final ThreadLocal<WeakHashMap<Configuration,
SearchFactoryImpl>> contexts = ...
in SearchFactoryImpl?
I never fully understood the need of that, I thought because we could
have several Search listeners
registered, but if we could delete
FullTextIndexCollectionEventListener this shouldn't be an issue
anymore.
Sanne
16 years, 5 months
Hibernate join problem
by ManiKanta G
Hi,
I have two tables (drug_master, cds_drugstore) with cds_master.drug_id
reference to drug_master.id.
I want to fetch all the drugids, drug_name, sum of avaialble drugs (if
avaialable, or else null).
I have this native MySql query, which is working fine. but I am unable
to port this in to HQL.
select dm.id, dm.drug_name, sum(cds.qty_available)
from drug_master dm
left join cds_drugstore cds
on dm.id = cds.drug_id
and cds.cds_id = 1
and cds.source_id = 'sourceName'
and cds.source_type = 'c'
group by dm.id
I've didn't see any examples using 'ON' keyword. Because here I've to
join tables based on 3 tables.
Some one please help. I need this very urgently.
Thanks in advance.
Regards,
ManiKanta
********** DISCLAIMER **********
Information contained and transmitted by this E-MAIL is proprietary to
Sify Limited and is intended for use only by the individual or entity to
which it is addressed, and may contain information that is privileged,
confidential or exempt from disclosure under applicable law. If this is a
forwarded message, the content of this E-MAIL may not have been sent with
the authority of the Company. If you are not the intended recipient, an
agent of the intended recipient or a person responsible for delivering the
information to the named recipient, you are notified that any use,
distribution, transmission, printing, copying or dissemination of this
information in any way or in any manner is strictly prohibited. If you have
received this communication in error, please delete this mail & notify us
immediately at admin(a)sifycorp.com
16 years, 5 months