Liferay StructureNameException when importing Lar file

Friday, November 2nd, 2018

Note: I’m no Liferay expert, in fact I’ve only been using it for a few days on a customers legacy system (Liferay 6.1.1) so YMMV.

The Problem

I was trying to import a “LAR” file (a compressed archive like a JAR which holds exported data/pages from a [different] Liferay instance). Problem was every time I tried the import I got a:

StructureNameException

This appears to have been caused by the fact that the exported files contained in the LAR were referring to locales that the importing server was not set-up to use:

<root available-locales="en_US,en_GB" default-locale="en_US">

(in this case my server was only set up to use en_US)

The Solution

In portal-ext.properties edit the following property to add the “missing” locales:

locales=en_US,en_GB

Tags:
Posted in Misc | No Comments »

Java – deliberately cause Deadlock

Tuesday, August 4th, 2015

Another interview question.

When this code is executed runnable1 will wait for a lock on “b” and runnable2 will wait for a lock on “a”.

package test;
/**
 * Deliberately try and cause deadlock
 * 
 */
public class DeadLockTest {
    public static void main(String[] args) {
    	final Object a = new Object();
        final Object b = new Object();
 
        final Runnable runnable1 = new Runnable() {
            public void run() {
                synchronized (a) {
                    try {
                        Thread.sleep(100); // Adding delay to increase chance of deadlock
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    
                    synchronized (b) { // We already have "a" abut need "b" too
                        System.out.println("In runnable1");
                    }
                }
            }
        };
 
        final Runnable runnable2 = new Runnable() {
            public void run() {
                synchronized (b) { // Has "b" but needs "a"
                    synchronized (a) {
                        System.out.println("In runnable2");
                    }
                }
            }
        };
 
        new Thread(runnable1).start();
        new Thread(runnable2).start();
    }
}

Tags:
Posted in Interview Questions | No Comments »

Java – deliberately cause OutOfMemoryException

Tuesday, August 4th, 2015

package test;

import java.util.ArrayList;
import java.util.List;

public class OutOfMemory {
    public static void main(String[] args) {
    	final List<String>list = new ArrayList<String>();
    	int i = 1;
    	while(true) {
			list.add(new String(System.nanoTime()+""));
			list.addAll(list);
			System.out.println(i+ " " + Runtime.getRuntime().freeMemory());
			i++;
		}
    	
    }
}

After a few seconds should output something like:


Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2245)
at java.util.Arrays.copyOf(Arrays.java:2219)
at java.util.ArrayList.grow(ArrayList.java:213)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:187)
at java.util.ArrayList.addAll(ArrayList.java:532)
at test.OutOfMemory.main(OutOfMemory.java:12)

Tags:
Posted in Interview Questions | No Comments »

Oracle XML DB – extracting relational data using XMLTables

Wednesday, April 22nd, 2015

Background

So say you’ve got some XML in an XMLType table. You want to get the data into a “normal” relational table (maybe for faster reporting etc)

The XML looks like this:

<!-- this is one row in the XML table (xml_table) -->
<mxrecords>
   <mxrecord>
       <sysurn></sysurn>
       <description></description>
   </mxrecord>
   <mxrecord>
       <sysurn></sysurn>
       <description></description>
   </mxrecord>
   <mxrecord>
       <sysurn></sysurn>
       <description></description>
   </mxrecord>
</mxrecords>

<!-- this is another row in the XML table -->
<mxrecords>
   <mxrecord>
       <sysurn></sysurn>
       <description></description>
   </mxrecord>
   <mxrecord>
       <sysurn></sysurn>
       <description></description>
   </mxrecord>
   <mxrecord>
       <sysurn></sysurn>
       <description></description>
   </mxrecord>
   <mxrecord>
       <sysurn></sysurn>
       <description></description>
   </mxrecord>
</mxrecords>

The relational table looks like this:

create table reporting(
    sysurn varchar2(50),
    description varchar2(4000)
);

Lets rip the XML into the relational table:

insert into reporting
select mxrecord.* from xml_table xt,
    XMLTABLE(
        '/mxrecords/mxrecord'
        passing xt.OBJECT_VALUE
        columns mxrecord XMLTYPE PATH '/mxrecord') mxrecords,
    XMLTABLE(
        '/mxrecord'
        passing mxrecords.mxrecord
        columns sysurn varchar2(50) PATH '/mxrecord/sysurn',
                description varchar2(4000) PATH '/mxrecord/description') mxrecord

Tags: , , , ,
Posted in How to's, Oracle | No Comments »

Oracle XML DB – Inserting XML

Friday, March 20th, 2015

Background

So following on from my previous post about creating XMLType tables in Oracle (either CLOB or schema based), here’s a few quick notes on getting data into the tables.

Inserting Data into XMLType Table

-- Create XMLType Table
CREATE TABLE XML_TABLE OF XMLType 

-- create an Oracle directory to hold the XML (readable by Oracle)
CREATE OR REPLACE DIRECTORY XML as '/home/foo/bar/xml'

-- insert the record (reading from filesystem)
-- filename.xml would be in directory you created above
INSERT INTO XML_TABLE(SELECT XMLTYPE(bfilename('XML', 'filename.xml'), nls_charset_id('UTF8')) FROM dual);

Of course you could easily write some PL/SQL to iterate all files in the directory.

You can also insert XML directly via SQL:

INSERT INTO XML_TABLE VALUES(XMLType('<mxrecords>
        <mxrecord>
            <sysurn>sysurn1</sysurn>
            <eventid>eventid1</eventid>
        </mxrecord>
        <mxrecord>
            <sysurn>sysurn2</sysurn>
            <eventid>eventid2</eventid>
        </mxrecord>
    </mxrecords>'
));

Tags: , , ,
Posted in Examples, How to's, Oracle | No Comments »