Skip to content

Instantly share code, notes, and snippets.

View martinlau's full-sized avatar

Martin Lau martinlau

View GitHub Profile
@martinlau
martinlau / keybase.md
Created September 23, 2014 05:02
keybase.md

Keybase proof

I hereby claim:

  • I am martinlau on github.
  • I am msl (https://keybase.io/msl) on keybase.
  • I have a public key whose fingerprint is 7682 47A7 93C4 0F6C 3BCC 7816 E4D1 D636 209A D697

To claim this, I am signing this object:

@martinlau
martinlau / GroupLocalServiceImpl.java
Last active December 10, 2015 20:49
GroupLocalServiceImpl snippet
/**
* Adds a group.
*
* @param userId the primary key of the group's creator/owner
* @param parentGroupId the primary key of the parent group
* @param className the entity's class name
* @param classPK the primary key of the entity's instance
* @param liveGroupId the primary key of the live group
* @param name the entity's name
* @param description the group's description (optionally
@martinlau
martinlau / SiteCreator.java
Last active May 23, 2017 08:02
Sample code to create a site in liferay (don't do this)
public class SiteCreator {
public static void createGroup() throws Exception {
// Don't do this!
long groupId = CounterLocalServiceUtil.increment(Group.class.getName());
Group group = GroupLocalServiceUtil.createGroup(groupId);
group.setName("Test Site");
@martinlau
martinlau / add-site.sql
Created January 9, 2013 05:57
SQL resulting from adding a new site through liferay's control panel.
INSERT INTO GROUP_ VALUES(10614,10154,10196,10001,10614,0,0,'Test Site','This is a test site',2,'','/test-site','1','1')
INSERT INTO LAYOUTSET VALUES(10615,10614,10154,'2013-01-09 16:56:01.504000','2013-01-09 16:56:01.504000','1','0',0,'classic','01','mobile','01','',0,'','','0')
INSERT INTO LAYOUTSET VALUES(10616,10614,10154,'2013-01-09 16:56:01.506000','2013-01-09 16:56:01.506000','0','0',0,'classic','01','mobile','01','',0,'','','0')
INSERT INTO RESOURCEPERMISSION VALUES(611,10154,'com.liferay.portal.model.Group',4,'10614',10163,0,2097151)
INSERT INTO USERGROUPROLE VALUES(10196,10614,10171)
INSERT INTO USERS_GROUPS VALUES(10196,10614)
INSERT INTO ASSETENTRY VALUES(10617,10192,10154,10196,'Test Test','2013-01-09 16:56:02.502000','2013-01-09 16:56:02.502000',10001,10614,'',0,'0',NULL,NULL,NULL,NULL,'','Test Site','This is a test site','','','',0,0,0.0E0,0)
COMMIT
@martinlau
martinlau / portal-log4j-ext.xml
Created December 4, 2012 00:48
portal-log4j-ext.xml configuration for logging hibernate statements
<?xml version="1.0"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="SQL_FILE" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="@liferay.home@/logs/sql.%d{yyyy-MM-dd}.log" />
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
@martinlau
martinlau / StartupHookAction.java
Created November 30, 2012 00:37
Changes to spring configuration and liferay hook implementation leveraging aspectj weaving
package au.com.permeance.hook;
import au.com.permeance.service.FakeService;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import static org.springframework.beans.factory.annotation.Autowire.BY_TYPE;
@martinlau
martinlau / gist:4172918
Created November 30, 2012 00:34
Maven output with aspectj compilation
[INFO] --- aspectj-maven-plugin:1.4:compile (default) @ spring-hook ---
[INFO] Join point 'method-execution(void au.com.permeance.service.impl.FakeServiceImpl.doStuff())' in Type 'au.com.permeance.service.impl.FakeServiceImpl' (FakeServiceImpl.java:26) advised by before advice from 'org.springframework.transaction.aspectj.AnnotationTransactionAspect' (spring-aspects-3.1.3.RELEASE.jar!AbstractTransactionAspect.class:60(from AbstractTransactionAspect.aj))
[INFO] Join point 'method-execution(void au.com.permeance.service.impl.FakeServiceImpl.doStuff())' in Type 'au.com.permeance.service.impl.FakeServiceImpl' (FakeServiceImpl.java:26) advised by afterThrowing advice from 'org.springframework.transaction.aspectj.AnnotationTransactionAspect' (spring-aspects-3.1.3.RELEASE.jar!AbstractTransactionAspect.class:67(from AbstractTransactionAspect.aj))
[INFO] Join point 'method-execution(void au.com.permeance.service.impl.FakeServiceImpl.doStuff())' in Type 'au.com.permeance.service.impl.FakeServiceImpl' (FakeServiceImpl.j
@martinlau
martinlau / pom.xml
Created November 30, 2012 00:33
Maven pom.xml snippet enabling aspectj compile time weaving
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
@martinlau
martinlau / StartupHookAction.java
Created November 30, 2012 00:29
A hook which uses an external spring context to enter into spring managed transactions and dependency injection
package au.com.permeance.hook;
import au.com.permeance.service.FakeService;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;
import com.liferay.portal.kernel.servlet.ServletContextPool;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContext;
@martinlau
martinlau / applicationContext.xml
Created November 30, 2012 00:28
Spring web.xml and applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>