Search Smith

ColdFusion, SQL queries, and, of course, searching

Posts Tagged ‘Java’

SHA-256 Hash in Oracle 10g

Posted by David Faber on August 24, 2012

It’s been a while since I’ve posted, and I’m not certain when I will get back to posting regularly (sorry!), but I came across an issue yesterday and found a blog post that was too good not to bring to others’ attention. I was looking to hash a column in Oracle with the SHA-2 256-bit hash function but that is not available in Oracle 10g.

The key to accomplishing this is found in the ability to load Java classes into Oracle and create Oracle functions based on the methods of those classes.

vnull – SHA1, SHA256, SHA512 in Oracle for free without using DBMS_CRYPTO

Incidentally, according to this post on the Oracle forums, the DBMS_CRYPTO package is certainly included in all editions of Oracle 11g, not just Enterprise Edition. There is nothing in the Oracle licensing information that would suggest that DBMS_CRYPTO is not available on Standard Edition, Standard Edition One, etc.

Having these encryption algorithms available within the Oracle DBMS is certainly helpful as it allows data to be encrypted or hashed via database triggers and the like.

To test your SHA-256 hash results, try the following link: SHA-256 Cryptographic Hash Algorithm.

If SHA-256 is not strong enough for you, SHA-512 is also included in the GNU Crypto project.

Posted in Oracle, SQL | Tagged: , , , , , , , , , , | 2 Comments »

ColdFusion 9 and Solr: Weak typing vs. strong

Posted by David Faber on January 10, 2012

I was trying to index a collection recently, and I kept getting an error when trying to add a value to a particular field. The field in question was defined in schema.xml as an “slong,” indexed, stored, and required. ColdFusion returned a weird error like the following:


So even though the value appeared to be a number, Solr was seeing it as something other than a number. It took me a couple of tweaks, but I finally hit upon a solution to the problem – using ColdFusion’s javaCast() function when invoking the addField() method:

<cfset temp.addField("user_cnt", javaCast("long", user_cnt)) />

The underlying problem is that ColdFusion is weakly-typed, and is quite happy to convert strings to numbers and vice versa, while Java is not.

Posted in ColdFusion, Solr | Tagged: , , , , , , , | 1 Comment »

Verity to Solr Addendum

Posted by David Faber on December 22, 2011

One day into this blog and I’m already lying about upcoming posts! Seriously, I noticed reading over my first post that I had unintentionally left a couple of things out.

The first is a postscript to the blog post I cited by ColdFusion Muse. This blog post dealt with some issues caused by using Solr with the default (as installed under ColdFusion) options for the JVM. One of these options is


Oracle, the maintainer of Java since its takeover of Sun, has the following to say on this subject (kudos to a colleague for turning this up):

On the same day, Oracle released Java 6u29 fixing the same problems occurring with Java 6, if the JVM switches -XX:+AggressiveOpts or -XX:+OptimizeStringConcat were used. Of course, you should not use experimental JVM options like -XX:+AggressiveOpts in production environments! We recommend everybody to upgrade to this latest version 6u29.

Now I can’t speak for anyone else, but I do find it strange that Solr would be configured by default (at least in its ColdFusion edition) to use an experimental JVM option. It’s not as if this is a new option, or that it was originally used for some other purpose. Sun mentioned that it was an experimental option in a 2005 white paper on Java Tuning:

Turns on point performance optimizations that are expected to be on by default in upcoming releases. The changes grouped by this flag are minor changes to JVM runtime compiled code and not distinct performance features (such as BiasedLocking and ParallelOldGC). This is a good flag to try the JVM engineering team’s latest performance tweaks for upcoming releases. Note: this option is experimental! The specific optimizations enabled by this option can change from release to release and even build to build. You should reevaluate the effects of this option with prior to deploying a new release of Java.

The other thing that I omitted was a short discussion on how to search a Solr collection on a custom field, or how to filter a search. Let’s consider the Solr query from the previous post:


This is just a plain-vanilla keyword search — there are no custom fields involved at all (well, there could be — but more on that later unless I am lying about future posts again). If we want to search on a custom field, we can do the following:


If we want to filter (filtering will search the field, but it won’t affect the results’ scores) the search on a custom field, we can do the following:


The “fq” parameter is used for filter queries and I believe the same syntax is used for this parameter as is used for the “q” parameter.

What if you want to search or filter on TWO (or more) custom fields? That is easy enough.


The “%2B” codes are url-encoded plus (+) signs, used because the “+” sign is used to url-encode spaces, while “%20” is the code for a url-encoded space. I suppose one might use a + sign here instead, but that might get confusing. (As an aside, I am old enough that some of the oldest code I used was written out on a blackboard for me, and we used an uppercase delta character Δ to denote a space as spaces are not always obvious when written.) I believe (but I am not entirely certain without checking) that the + signs are needed in front of both terms.

Posted in ColdFusion, Oracle, Solr | Tagged: , , , , , , | Leave a Comment »