Determining Permissions for a User

SQL> select privilege from user_tab_privs where lower(table_name)=’t_foo’ and lower(grantee)=’frank’;

PRIVILEGE
—————————————-
UPDATE
SELECT
INSERT
DELETE

SQL> select * from user_role_privs;

USERNAME GRANTED_ROLE ADM DEF OS_
—————————— —————————— — — —
FRANK AQ_ADMINISTRATOR_ROLE NO YES NO
PUBLIC SELECT_CATALOG_ROLE NO YES NO

Submitting an ATG Form Using a Text Link

It has always bedeviled me how to submit an ATG form using a text link. I have asked many people about this but no one seems to know. Finally with the help of ATG support I figured it out.

Below is a simple example of how to do it. The trick is the hidden submit input which triggers ATG to call the handleSubmit method of the form handler.

<%@ taglib uri="/dspTaglib" prefix="dsp"%>

<dsp:page>

<script>
  function submit(form) {
    form.submit();
  }
</script>

<dsp:form action="<%=request.getRequestURI()%>" method="post" name="testForm">

  Foo: <dsp:input type="text" bean="TestFormHandler.foo"/>

  <p><a href="javascript:submit(document.testForm)">Submit</a>

  <dsp:input type="hidden" bean="TestFormHandler.submit" value="Submit"/>

</dsp:form>

</dsp:page>

You can also invoke the JavaScript like this:

  <p><a href="#" onclick="submit(document.testForm); return false;">Submit</a>

HOWTO Rollback to Previous Version

Perforce has great tech notes and one of them is Perforce Reverting Submitted Changelists.

Here is how one rolls back to version N-1 .

> p4 sync …@N-1

> p4 add deleted_file
> p4 edit foo bar baz

> p4 sync …@N

> p4 resolve -ay

> p4 sync …

> p4 resolve

> p4 delete added_file

> p4 submit …

You can also do a simple rollback of a file like in this example.

> p4 sync foo#7

> p4 edit foo

> p4 sync …

> p4 resolve -ay

> p4 submit …

Deploying to Production Notes

  1. To run the DB migrate scripts you must specify that you are using the production configuration. One simple way to do this is:

    rake RAILS_ENV='production' db:migrate

  2. Make the public/dispatch.* scripts executable. If you developed originally in Windows then you need to change the first line in each of these dispatch scripts from

    #!e:/ruby/bin/ruby

    to

    #!/usr/bin/ruby1.8

  3. Enable FastCGI (CGI is ridiculously slow) by changing .htaccess. Change this line

    RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

    to

    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

  4. Change the public and log directories to mode 755 (not sure if this is necessary but seems like good practice).

    chmod 755 public
    chmod 755 log

Inserting a text value with special characters

To insert a text value with an ampersand, e.g. AT&T, one can do something like this.

insert into foo values(‘AT’||Chr(38)||’T’)

To learn more see How does one disable interactive prompting in SQL*Plus?

To insert a text value with a single quote, e.g. Don’t do it, one can do something like this.

insert into foo values(‘Don”t do it’)

To learn more see How does one escape special characters when building SQL queries?

Submitting a form with a radio button

Submitting a form from a radio button is not common but it is a nice UI which is even better when done with AJAX.

A typical form with two radio buttons would look something like this.

<form action="test.html">
1 <input type="radio" name="test" value ="1"><br>
2 <input type="radio" name="test" value ="2">
<p><input type="submit" value="submit">
</form>
1
2

But with basic JavaScript you can make a simpler form like this.

<script>
function submitAction( form, absPath ) {
form.action = absPath;
form.submit();
}
</script>
<form action="test.html" id="test">
1 <input type="radio" name="test" value ="1" onchange="submitAction(document.getElementById('test'), 'test.html')"><br>
2 <input type="radio" name="test" value ="2" onchange="submitAction(document.getElementById('test'), 'test.html')">
</form>
1
2

If you are using Struts the above form’s JSP would be:

<html:form action="test.do" styleId="test">
1 <input type="radio" name="test" value ="1" onchange="submitAction(document.getElementById('test'), 'test.do')"><br>
2 <input type="radio" name="test" value ="2" onchange="submitAction(document.getElementById('test'), 'test.do')">
</html:form>

Eclipse won’t start after Windows shutdown

My laptop unexpectedly shutdown when I had Eclipse open. After rebooting I could not start Eclipse. Instead it kept crashing with the message “An error has occurred. See the log file …” Looking at the log file I saw errors related to the Perforce plugin.

java.lang.NoClassDefFoundError
        at org.eclipse.ui.internal.themes.ThemeElementHelper.installFont(ThemeElementHelper.java:101)

org.osgi.framework.BundleException: Exception in org.eclipse.core.internal.compatibility.PluginActivator.start() of bundle com.perforce.team.ui.
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1010)
Caused by: java.lang.ExceptionInInitializerError
        at com.perforce.team.ui.PerforceUIPlugin.initializeDefaultPreferences(PerforceUIPlugin.java:284)

I saw a post about this problem which referred to another post for a solution. Basically the post suggests that stale plugin cache information is causing the problem and suggests starting Eclipse with the -clean argument. After doing this I was successfully able to launch Eclipse.

Printing out an array

When printing out an array if you simply do a toString on the array you will get a “fairly useless result such as [C@16f0472”. Consider using Arrays.toString to convert the array into a readable String that gives the contents of the array.” I used to use Arrays.asList followed by toString but Arrays.toString is definitely more efficient and is available as of JDK 1.5.0.

This method is useful when you want to report on the values of an JDK 1.5 enum since the values method returns an array.

The quote is from a FindBugs report.

Perforce Tips

The Perforce Windows GUI has a few neat tricks.

  1. If you click on a folder/file in the depot view of the Perforce Windows GUI and do a copy (Ctrl+C), then if you do a paste in another application it will paste the complete depot path to that folder/file.
  2. If you copy the Windows path to a folder/file in your work space and then do a paste in the depot view the Perforce Windows GUI will reveal where in the depot the folder/file is located.

Perforce Merging

A former colleague has a great Perforce FAQ and in it he writes a lot about how to do a merge.

If you are doing a simple merge one can do it on the code line like in this example.

> p4 integ //depot/foo/...@17,@17 //depot/bar/...
> p4 resolve -am
> p4 submit

(Some people suggest doing p4 resolve -as && p4 resolve -am. The -as is the simple resolve.)

You can also do a simple merge of a file like in this example.

> p4 integ //depot/foo/frank.java#7,#7 //depot/bar/frank.java
> p4 resolve -am
> p4 submit

Sometimes Perforce will not do the integration and say “all revision(s) already integrated.” In that case you can force the revision by using the -f flag.

> p4 integ -f //depot/foo/frank.java#7,#7 //depot/bar/frank.java