Opera Unite – Reinventing the web? We’ll see.

Posted by Jamie on June 16, 2009

Opera, a Norwegian software company, known for the Opera web browser, has promised to re-invent the web with their new Unite service. It certainly looks promising, allowing users to share files, play music/movies, etc. on their computers from a web brower anywhere on the internet. I’m going to look into it, but the technology does look promising. Check it out for yourself: http://unite.opera.com/

Back again…

Posted by Jamie on June 03, 2009

I apologize for the downtime – One of my plugins decided to stop playing nicely so I had to shuffle some things around. Code coloration is disabled for the time being.

The Ruby Toolbox: Look up gems by category and popularity

Posted by Jamie on May 19, 2009

I heard about The Ruby Toolbox today:  http://ruby-toolbox.com/

Here is a brief description, taken from their site:

The Ruby Toolbox gives you an overview of these tools, sorted in categories and rated by the amount of watchers and forks in the corresponding source code repository on GitHub so you can find out easily what options you have and which are the most common ones in the Ruby community.

They basically list Ruby libraries by category and ‘popularity’ (defined above.)  I think it’s really interesting how influential GitHub has been to Ruby development, and in my opinion it is only natural that sites like The Ruby Toolbox are created.  I like the site because it lets me quickly choose candidates for evaluation when I am looking for a library to help with a particular task.

Adding additional controlfiles (multiplexing) in Oracle using ASM

Posted by Jamie on May 12, 2009

When creating a database using ASM, the Oracle database creation assistant, ordbca, has an annoying tendency to only create one controlfile by default.  This is unequivocally a bad idea for any database that contains meaningful data, therefore it is necessary to add additional controlfiles.  Before ASM, you could shutdown the db, copy the controlfile on the OS level and modify the control_files parameter to add additional controlfiles.  If you use ASM, the operation is not that simple anymore, you need to use RMAN to perform the copy.  Here’s how I did it on my RAC database (10.2.0.3.0) on ASM (Note: check your ASM locations – this is only an example) : Continue reading…

UPDATE! – Ruby ActiveRecord and Oracle: Auto Incrementing Primary Keys using Triggers

Posted by Jamie on July 11, 2008

Well, it looks like this has been fixed in the latest versions of the Oracle enhanced adapter for ActiveRecord. It looks like there was a reorganization of the different components of the ActiveRecord/Adapter relationship that had originally led to this problem, according to the documentation submitted with the fix. Thanks to whomever was able to provide the patch; You just made my life a little bit easier.

Martin Fowler’s article “Using the Rake Build Language”

Posted by Jamie on March 27, 2008

I just got through reading Martin Fowler’s excellent article on using the Rake build Language. It is a very easy to understand and fairly complete initiation into basic and intermediate build/automation techniques using Rake. It is old (Aug 10th 05) but, in my opinion, still quite relevant.

You can find the article here, and his main site (excellent!) is here: http://www.martinfowler.com

I stumbled across the article while exploring deployment/system administration options utilizing Ruby. Because I am using RAC for my database instances, I have multiple servers that I need to consistently update with scripts, configuration, data, etc. I have been looking into Capistrano for this task (even though it is an Oracle system) and it looks promising, if a bit kludgy to implement without SCM in place and accessible from the server.

Once I have the deployment solution figured out, I’ll write it up.

Ruby ActiveRecord and Oracle: Auto Incrementing Primary Keys using Triggers

Posted by Jamie on January 30, 2008

One of the most obvious limitations that I have faced when using ActiveRecord is it’s ability to adapt to legacy systems, especially Oracle databases. Many of the Oracle databases that I have used employ triggers to populate numeric primary key columns when data is inserted into the database tables. While this is a very nice and easy way to hide the mechanisms used to identify the data from the application developers when they are using straight DML, when you try to use ActiveRecord on these tables, ESPECIALLY when dealing with large object (LOB) fields, you get into some real hair-pulling situations.

ActiveRecord handles LOB inserts in two steps:

  1. The data is inserted into the database and the LOB field is initialized with an empty lob.
  2. The record is updated with the provided LOB data, replacing the empty lob.

As part of step 1 above, ActiveRecord pre-fetches the sequence that is used to populate the primary key field of the table. If you then have a trigger on that table that updates the incoming primary key column with the next sequence value, your Ruby object and the data inserted into the database are out of sync. Therefore, in step
2 of the LOB insert process described above, ActiveRecord is attempting to update a row with a primary key value that does not exist and no LOB values are ever populated.

To prevent this, I created the following code that alters ActiveRecord::Base and ActiveRecord::ConnectionAdapters::OracleAdapter to use the trigger-generated key (via the Oracle ‘RETURNING’ clause) in the AR object.
[ruby]

module ActiveRecord
module ConnectionAdapters #:nodoc:
class OracleAdapter < AbstractAdapter
def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
cursor = @connection.parse(sql)
log(sql, name) { cursor.exec(0) }
# return the primary key value for the record just inserted
cursor[1]
end
end
end

class Base
# Creates a record with values matching those of the instance attributes and
# returns its id.
def create
if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name)
self.id = connection.next_sequence_value(self.class.sequence_name)
end

quoted_attributes = attributes_with_quotes

statement = if quoted_attributes.empty?
connection.empty_insert_statement(self.class.table_name)
else
“INSERT INTO #{self.class.quoted_table_name} ” +
“(#{quoted_column_names.join(‘, ‘)}) ” +
“VALUES(#{quoted_attributes.values.join(‘, ‘)}) returning #{self.class.primary_key} into :1″
end

self.id = connection.insert(statement, “#{self.class.name} Create”,
self.class.primary_key, self.id, self.class.sequence_name)

@new_record = false
id
end
end
end
[/ruby]

Now, this is really, really rough. I am using the 2.x version of ActiveRecord, and any updates to these sections in future releases will break my changes. It does, however, work for me right now. As I have time I will refactor this and increase its maintainablility.

Comments?

Open!

Posted by Jamie on August 16, 2007

Greetings, and welcome to ThoughtHook! This is the obligatory here-I am post – But you deserve more than just an announcement, don’t you?

What is this place about?

ThoughtHook is a place where I can share my thoughts and ideas about surviving and thriving in the jungle that is software development. I relish programming in Ruby, so much of what I post about will be ruby-related (not necessarily Rails-related.) You will also see posts about Programming Languages, Oracle, PL/SQL, general coding, etc.; Whatever interests me and/or is relevant to my current work.

So now you have a better idea of what I am trying to do here. Hopefully, we can all learn from each other.