This repository has been archived by the owner on Dec 19, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
2,555 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
sourceSets.main.java.srcDirs | ||
|
||
dependencies { | ||
compile project(":tawus-core") | ||
compile "org.hibernate:hibernate-core:3.6.0.Final" | ||
compile "org.hibernate:hibernate-validator:4.1.0.Final" | ||
testCompile "hsqldb:hsqldb:1.8.0.7" | ||
testRuntime "cglib:cglib-nodep:2.2" | ||
testCompile "org.spockframework:spock-tapestry:0.4-groovy-1.7" | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Tapestry-Module-Classes': 'com.googlecode.tawus.hibernate.services.TawusHibernateModule' | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Class-Path: | ||
|
42 changes: 42 additions & 0 deletions
42
tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/InlineAudit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.googlecode.tawus.hibernate; | ||
|
||
import java.util.Date; | ||
|
||
|
||
public interface InlineAudit<T> { | ||
/** | ||
* Get login class which is stored in tapestry session | ||
* @return login class | ||
*/ | ||
Class<?> getLoginClass(); | ||
|
||
/** | ||
* Set creator | ||
* @param currentLogin | ||
*/ | ||
void setCreator(T currentLogin); | ||
|
||
/** | ||
* Set creation date | ||
* @param date | ||
*/ | ||
void setCreationDate(Date date); | ||
|
||
/** | ||
* Set modification date | ||
* @param date | ||
*/ | ||
void setModificationDate(Date date); | ||
|
||
/** | ||
* Set modifier | ||
* @param currentLogin | ||
*/ | ||
void setModifier(T currentLogin); | ||
|
||
/** | ||
* Has the record been modified | ||
* @return | ||
*/ | ||
boolean isModified(); | ||
} |
7 changes: 7 additions & 0 deletions
7
tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/TawusHibernateConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.googlecode.tawus.hibernate; | ||
|
||
public class TawusHibernateConstants { | ||
|
||
public static final String DEFAULT_FACTORY_ID = "tawus.hibernate.defaultFactoryID"; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/annotations/DefaultOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.googlecode.tawus.hibernate.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface DefaultOrder { | ||
|
||
boolean ascending() default true; | ||
|
||
String column(); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/annotations/Unique.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.googlecode.tawus.hibernate.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface Unique { | ||
String [] columns(); | ||
} |
30 changes: 30 additions & 0 deletions
30
...main/java/com/googlecode/tawus/hibernate/internal/advices/MandatoryTransactionAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* | ||
*/ | ||
package com.googlecode.tawus.hibernate.internal.advices; | ||
|
||
import org.apache.tapestry5.ioc.Invocation; | ||
import org.apache.tapestry5.ioc.MethodAdvice; | ||
|
||
import com.googlecode.tawus.hibernate.services.HibernateSessionManager; | ||
|
||
public class MandatoryTransactionAdvice implements | ||
MethodAdvice { | ||
|
||
private HibernateSessionManager sessionManager; | ||
private String factoryID; | ||
|
||
public MandatoryTransactionAdvice(String factoryID, | ||
HibernateSessionManager sessionManager) { | ||
this.sessionManager = sessionManager; | ||
this.factoryID = factoryID; | ||
} | ||
|
||
@Override | ||
public void advise(Invocation invocation) { | ||
if(!sessionManager.isWithinTransaction(factoryID)){ | ||
throw new RuntimeException("Must be within a transaction"); | ||
} | ||
invocation.proceed(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...rc/main/java/com/googlecode/tawus/hibernate/internal/advices/NestedTransactionAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* | ||
*/ | ||
package com.googlecode.tawus.hibernate.internal.advices; | ||
|
||
import org.apache.tapestry5.ioc.Invocation; | ||
import org.apache.tapestry5.ioc.MethodAdvice; | ||
|
||
import com.googlecode.tawus.hibernate.services.HibernateSessionManager; | ||
|
||
public class NestedTransactionAdvice implements MethodAdvice { | ||
|
||
private HibernateSessionManager sessionManager; | ||
private String factoryID; | ||
|
||
public NestedTransactionAdvice(String factoryID, | ||
HibernateSessionManager sessionManager) { | ||
this.sessionManager = sessionManager; | ||
this.factoryID = factoryID; | ||
} | ||
|
||
@Override | ||
public void advise(Invocation invocation) { | ||
|
||
try{ | ||
sessionManager.begin(factoryID); | ||
invocation.proceed(); | ||
sessionManager.commit(factoryID); | ||
}catch(Exception ex){ | ||
sessionManager.rollback(factoryID); | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...src/main/java/com/googlecode/tawus/hibernate/internal/advices/NeverTransactionAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* | ||
*/ | ||
package com.googlecode.tawus.hibernate.internal.advices; | ||
|
||
import org.apache.tapestry5.ioc.Invocation; | ||
import org.apache.tapestry5.ioc.MethodAdvice; | ||
|
||
import com.googlecode.tawus.hibernate.services.HibernateSessionManager; | ||
|
||
public class NeverTransactionAdvice implements MethodAdvice { | ||
|
||
private HibernateSessionManager sessionManager; | ||
private String factoryID; | ||
|
||
public NeverTransactionAdvice(String factoryID, | ||
HibernateSessionManager sessionManager) { | ||
this.sessionManager = sessionManager; | ||
this.factoryID = factoryID; | ||
} | ||
|
||
@Override | ||
public void advise(Invocation invocation) { | ||
if(sessionManager.isWithinTransaction(factoryID)){ | ||
throw new RuntimeException("Cannot proceed within a transaction"); | ||
} | ||
invocation.proceed(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...n/java/com/googlecode/tawus/hibernate/internal/advices/NotSupportedTransactionAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* | ||
*/ | ||
package com.googlecode.tawus.hibernate.internal.advices; | ||
|
||
import org.apache.tapestry5.ioc.Invocation; | ||
import org.apache.tapestry5.ioc.MethodAdvice; | ||
import org.hibernate.Session; | ||
|
||
import com.googlecode.tawus.hibernate.services.HibernateSessionManager; | ||
|
||
public class NotSupportedTransactionAdvice implements | ||
MethodAdvice { | ||
|
||
private HibernateSessionManager sessionManager; | ||
private String factoryID; | ||
|
||
public NotSupportedTransactionAdvice(String factoryID, | ||
HibernateSessionManager sessionManager) { | ||
this.sessionManager = sessionManager; | ||
this.factoryID = factoryID; | ||
} | ||
|
||
@Override | ||
public void advise(Invocation invocation) { | ||
if(sessionManager.isWithinTransaction()){ | ||
Session oldSession = sessionManager.getSession(factoryID); | ||
Session newSession = sessionManager.createSession(factoryID); | ||
invocation.proceed(); | ||
newSession.close(); | ||
sessionManager.setSession(factoryID, oldSession); | ||
}else{ | ||
invocation.proceed(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../main/java/com/googlecode/tawus/hibernate/internal/advices/RequiredTransactionAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* | ||
*/ | ||
package com.googlecode.tawus.hibernate.internal.advices; | ||
|
||
import org.apache.tapestry5.ioc.Invocation; | ||
import org.apache.tapestry5.ioc.MethodAdvice; | ||
|
||
import com.googlecode.tawus.hibernate.services.HibernateSessionManager; | ||
|
||
public class RequiredTransactionAdvice implements | ||
MethodAdvice { | ||
|
||
private HibernateSessionManager sessionManager; | ||
private String factoryID; | ||
|
||
public RequiredTransactionAdvice(String factoryID, | ||
HibernateSessionManager sessionManager) { | ||
this.sessionManager = sessionManager; | ||
this.factoryID = factoryID; | ||
} | ||
|
||
@Override | ||
public void advise(Invocation invocation) { | ||
boolean isNew = sessionManager.beginOrContinue(factoryID); | ||
if(!isNew){ | ||
invocation.proceed(); | ||
return; | ||
} | ||
|
||
try{ | ||
invocation.proceed(); | ||
sessionManager.commit(factoryID); | ||
}catch(Exception ex){ | ||
sessionManager.rollback(factoryID); | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...in/java/com/googlecode/tawus/hibernate/internal/advices/RequiresNewTransactionAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* | ||
*/ | ||
package com.googlecode.tawus.hibernate.internal.advices; | ||
|
||
import org.apache.tapestry5.ioc.Invocation; | ||
import org.apache.tapestry5.ioc.MethodAdvice; | ||
import org.hibernate.Session; | ||
import org.hibernate.Transaction; | ||
|
||
import com.googlecode.tawus.hibernate.services.HibernateSessionManager; | ||
|
||
public class RequiresNewTransactionAdvice implements | ||
MethodAdvice { | ||
|
||
private HibernateSessionManager sessionManager; | ||
private String factoryID; | ||
|
||
public RequiresNewTransactionAdvice(String factoryID, | ||
HibernateSessionManager sessionManager) { | ||
this.sessionManager = sessionManager; | ||
this.factoryID = factoryID; | ||
} | ||
|
||
@Override | ||
public void advise(Invocation invocation) { | ||
if(sessionManager.isWithinTransaction()){ | ||
Session oldSession = sessionManager.getSession(factoryID); | ||
Session newSession = sessionManager.createSession(factoryID); | ||
Transaction tx = null; | ||
try{ | ||
tx = newSession.beginTransaction(); | ||
invocation.proceed(); | ||
tx.commit(); | ||
}catch(Exception ex){ | ||
if(tx != null){ | ||
tx.rollback(); | ||
} | ||
throw new RuntimeException(ex); | ||
}finally { | ||
newSession.close(); | ||
sessionManager.setSession(factoryID, oldSession); | ||
} | ||
}else{ | ||
|
||
try{ | ||
sessionManager.begin(factoryID); | ||
invocation.proceed(); | ||
sessionManager.commit(factoryID); | ||
}catch(Exception ex){ | ||
sessionManager.rollback(factoryID); | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...main/java/com/googlecode/tawus/hibernate/internal/advices/TransactionIsolationAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* | ||
*/ | ||
package com.googlecode.tawus.hibernate.internal.advices; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import org.apache.tapestry5.ioc.Invocation; | ||
import org.apache.tapestry5.ioc.MethodAdvice; | ||
|
||
import com.googlecode.tawus.hibernate.services.HibernateSessionManager; | ||
|
||
public final class TransactionIsolationAdvice implements MethodAdvice { | ||
|
||
private String factoryID; | ||
private HibernateSessionManager sessionManager; | ||
private int isolation; | ||
|
||
public TransactionIsolationAdvice(final String factoryID, int isolation, | ||
HibernateSessionManager sessionManager) { | ||
this.factoryID = factoryID; | ||
this.sessionManager = sessionManager; | ||
this.isolation = isolation; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public void advise(Invocation invocation) { | ||
Connection connection = sessionManager.getSession(factoryID) | ||
.connection(); | ||
int oldIsolation = setIsolation(connection, isolation); | ||
invocation.proceed(); | ||
setIsolation(connection, oldIsolation); | ||
} | ||
|
||
private int setIsolation(Connection connection, int isolation) { | ||
try { | ||
int oldIsolation = connection.getTransactionIsolation(); | ||
connection.setTransactionIsolation(isolation); | ||
return oldIsolation; | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.