Subversion Repositories bacoAlunos

Compare Revisions

Ignore whitespace Rev 1350 → Rev 1351

/branches/v3/impl/src/java/jomm/experiments/JavaAssistDynamicProxy.java
New file
0,0 → 1,65
package jomm.experiments;
 
import javassist.util.proxy.MethodFilter;
import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
import pt.estgp.estgweb.domain.User;
 
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
 
/**
* Created by jorgemachado on 12/04/16.
*/
public class JavaAssistDynamicProxy
{
public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
 
 
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(User.class);
factory.setFilter(
new MethodFilter() {
@Override
public boolean isHandled(Method method) {
return true;
//return Modifier.isAbstract(method.getModifiers());
}
}
);
 
 
MethodHandler handler = new MethodHandler() {
@Override
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
System.out.println("Handling " + thisMethod + " via the method handler");
if(thisMethod.getName().startsWith("getId"))
{
return proceed.invoke(self,args);
}
else if(thisMethod.getName().startsWith("get"))
{
System.out.println("Acedendo a uma propriedade " + thisMethod.getName() + " na class " + thisMethod.getDeclaringClass().getName());
String campo = thisMethod.getName().substring(3);
campo = ("" + campo.charAt(0)).toLowerCase() + campo.substring(1);
System.out.println("select " + campo + " from " + thisMethod.getDeclaringClass().getCanonicalName() + " where id = " +
self.getClass().getMethod("getId").invoke(self,new Object[]{}));
}
if(thisMethod.getName().startsWith("set"))
{
System.out.println("Alterando uma propriedade no proxy " + thisMethod.getName() + " na class " + thisMethod.getDeclaringClass().getName());
return proceed.invoke(self,args);
}
return null;
}
};
 
User u = (User) factory.create(new Class[0], new Object[0], handler);
u.setId(3);
 
u.getUsername();
u.getCourses();
u.getId();
 
}
}
/branches/v3/impl/src/java/jomm/experiments/DynamicProxy.java
New file
0,0 → 1,41
package jomm.experiments;
 
import pt.estgp.estgweb.domain.UserImpl;
 
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* Created by jorgemachado on 12/04/16.
*/
public class DynamicProxy implements InvocationHandler {
 
 
public Object invoke(Object proxy, Method method,
Object[] args) throws Throwable
{
if (method.getName().equals("toString")) {
return super.toString();
}
System.out.println("Metodo " + method +
" invocado sobre " + proxy);
return null;
}
 
 
 
public static void main(String [] args)
throws IOException
{
 
ClassLoader cl = DynamicProxy.class.getClassLoader();
UserImpl u = (UserImpl) Proxy.newProxyInstance(cl,
new Class[]{UserImpl.class},
new DynamicProxy());
u.getUsername();
u.getCourses();
}
 
 
}
/branches/v3/impl/src/hbm/pt/estgp/estgweb/domain/CourseUnit.hbm.xml
44,6 → 44,33
<column name="summariesJson" sql-type="MEDIUMTEXT"/>
</property>
 
<!-- CourseUnit Statistics -->
<property name="teachers" type="int"/>
<property name="students" type="int"/>
<property name="contentsFiles" type="int"/>
<property name="contentsFolders" type="int"/>
<property name="contentsLastUpdate" type="int"/>
 
<property name="works" type="int"/>
<property name="anuncios" type="int"/>
<property name="blogPosts" type="int"/>
 
<property name="dtpSumaries" type="int"/>
<property name="dtpSumariesMissing" type="int"/>
<property name="dtpPlaneamentoFiles" type="int"/>
<property name="dtpPlaneamentoFilesLastUpdate" type="timestamp"/>
<property name="dtpFichaCurricularValid" type="boolean"/> <!--refere para o campo ficha válida coloca-se apenas o GET no IMPL-->
<property name="dtpFichaCurricularLastUpdate" type="timestamp"/>
<property name="dtpEvaluationReportState" type="string"/> <!-- VALIDO,ENTREGUE,INICIADO,INEXISTENTE refere para o campo relatorio de avaliação válido coloca-se apenas o GET no IMPL-->
<property name="dtpEvaluationReportLastUpdate" type="timestamp"/>
<property name="dtpInqueritoPedagogicoFiles" type="int"/>
<property name="dtpInqueritoPedagogicoFilesLastUpdate" type="timestamp"/>
<property name="dtpAvaliacaoEnunciadosFiles" type="int"/>
<property name="dtpAvaliacaoEnunciadosLastUpdate" type="timestamp"/>
<property name="dtpAvaliacaoPautasFiles" type="int"/>
<property name="dtpAvaliacaoPautasLastUpdate" type="timestamp"/>
 
 
<!--
Este código de turma apenas é usado nos casos em que o curso é de turmas separadas
Nesse caso uma cadeira só pode ter uma turma e então a turma é aqui colocada