... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2006-12-19

E4X Documentation

It is hard to find readable documentation on ECMAScript E4X.  Adobe's Flex 2 documentation is much easier to read than the E4X specification.  Look under Programming ActionScript 3.0 / Core ActionScript 3.0 Data Types and Classes / Working with XML.  Of course, you must take care using these documents as ActionScript is (mostly) a superset of ECMAScript.

ApexSQL Clean

While evaluating changes to the PetroAra schema, I took a look at the product ApexSQL Clean.  It performs SQL Server dependency analysis, among other things.  The product is pretty slick.

2006-12-14

OLEDB Connection String and UDL files

".UDL".  That's the extension of OLDEB connection string files that I keep forgetting.  By creating and opening an empty ".UDL" file you are presented with a snazzy GUI for building connection strings. The GUI tools is part of the MDAC distribution. You can access a UDL file from ADO by using a connection string like

File Name=c:\somewhere\my.udl;

2006-12-13

Copy a Java Serializable

I'm tired of repeatedly recreating this code to copy a Java Serializable:

private static <OBJECT_TYPE extends Serializable> OBJECT_TYPE copySerializable(
        OBJECT_TYPE object) {
    try {
        ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
        ObjectOutputStream objectOutput = new ObjectOutputStream(byteOutput);
        objectOutput.writeObject(object);
        ByteArrayInputStream byteInput = new ByteArrayInputStream(byteOutput.toByteArray());
        ObjectInputStream objectInput = new ObjectInputStream(byteInput);
        @SuppressWarnings("unchecked")
        OBJECT_TYPE copy = (OBJECT_TYPE) objectInput.readObject();
        return copy;
    } catch (Exception ex) {
        throw new RuntimeException(String.format("unable to copy the object '%s'", object), ex); //$NON-NLS-1$
    }
}

or its threaded equivalent that uses pipes:

private static <OBJECT_TYPE extends Serializable> OBJECT_TYPE copySerializable2(
        final OBJECT_TYPE object) {
    try {
        final PipedInputStream pipeInput = new PipedInputStream();
        final PipedOutputStream pipeOutput = new PipedOutputStream(pipeInput);
        Thread writerThread = new Thread("copySerializable2") { //$NON-NLS-1$
            @Override
            public void run() {
                try {
                    ObjectOutputStream objectOutput = new ObjectOutputStream(pipeOutput);
                    try {
                        objectOutput.writeObject(object);
                    } finally {
                        objectOutput.close();
                    }
                } catch (IOException ex) {
                    throw new RuntimeException(String.format(
                        "Unable to serialize the object '%s'", object), ex); //$NON-NLS-1$
                }
            }
        };
        writerThread.start();
        try {
            ObjectInputStream objectInput = new ObjectInputStream(pipeInput);
            try {
                @SuppressWarnings("unchecked")
                OBJECT_TYPE copy = (OBJECT_TYPE) objectInput.readObject();
                return copy;
            } finally {
                objectInput.close();
            }
        } finally {
            writerThread.join();
        }
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Unable to read the object '%s'", object), ex); //$NON-NLS-1$
    }
}

Java Pipes

I'm also tired of writing the boilerplate in Java necessary to use a pipe.  Here is a helper class, preceded by something that uses it:

private static <OBJECT_TYPE extends Serializable> OBJECT_TYPE copySerializable3(
        final OBJECT_TYPE object) {
    PipeHelper<OBJECT_TYPE> pipeHelper = new PipeHelper<OBJECT_TYPE>() {

        @Override
        protected void write(PipedOutputStream pipeOutput) throws Exception {
            ObjectOutputStream objectOutput = new ObjectOutputStream(pipeOutput);
            objectOutput.writeObject(object);
            objectOutput.close();
        }

        @Override
        protected OBJECT_TYPE read(PipedInputStream pipeInput) throws Exception {
            ObjectInputStream objectInput = new ObjectInputStream(pipeInput);
            @SuppressWarnings("unchecked")
            OBJECT_TYPE copy = (OBJECT_TYPE) objectInput.readObject();
            objectInput.close();
            return copy;
        }
    };
    
    try {
        return pipeHelper.run();
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Unable to copy the object '%s'", object), ex); //$NON-NLS-1$
    }
}



abstract class PipeHelper<RESULT_TYPE> {

    public RESULT_TYPE run() throws Exception {
        final Exception[] writerException = { null };
        final PipedInputStream pipeInput = new PipedInputStream();
        try {
            final PipedOutputStream pipeOutput = new PipedOutputStream(pipeInput);
            try {
                Thread writerThread = new Thread(this.getClass().getName()) {
                    @Override
                    public void run() {
                        try {
                            write(pipeOutput);
                        } catch (Exception ex) {
                            writerException[0] = ex;
                        }
                    }
                };
                writerThread.start();
                try {
                    RESULT_TYPE result = read(pipeInput);
                    if (null != writerException[0]) {
                        throw writerException[0];
                    }
                    return result;
                } finally {
                    writerThread.join();
                }
            } finally {
                pipeOutput.close();
            }
        } finally {
            pipeInput.close();
        }
    }

    protected abstract RESULT_TYPE read(PipedInputStream pipeInput) throws Exception;

    protected abstract void write(PipedOutputStream pipeOutput) throws Exception;
}

2006-12-12

Subversive / SVNKit

I tried installing Subversive, an Eclipse plug-in for Subversion.  I have been watching this plug-in for a while after abandoning Subclipse.  This time I tried Subversive 1.1.0, using version 1.1.0 of the SVNKit client.  The plug-in seemed reasonably stable, but the Eclipse IDE performed abysmally.  A coworker said that he found similar bad performance, but was able to work around it by disconnecting each project from SVN after performing SVN operations.  Another coworker did not see this behaviour.  I uninstalled Subversive, and Eclipse responsiveness was restored.  Perhaps Subversive was doing some sort of tree crawl in the background that eventually finishes, restoring proper responsiveness?  I'll have to re-install some day to find out.

Blog Archive