3,7 → 3,7 |
import javassist.util.proxy.MethodFilter; |
import javassist.util.proxy.MethodHandler; |
import javassist.util.proxy.ProxyFactory; |
import pt.estgp.estgweb.domain.User; |
import pt.estgp.estgweb.domain.Course; |
|
import java.lang.reflect.InvocationTargetException; |
import java.lang.reflect.Method; |
17,7 → 17,7 |
|
|
ProxyFactory factory = new ProxyFactory(); |
factory.setSuperclass(User.class); |
factory.setSuperclass(Course.class); |
factory.setFilter( |
new MethodFilter() { |
@Override |
29,6 → 29,9 |
); |
|
|
|
|
|
MethodHandler handler = new MethodHandler() { |
@Override |
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { |
43,7 → 46,7 |
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[]{})); |
self.getClass().getMethod("getId").invoke(self, new Object[]{})); |
} |
if(thisMethod.getName().startsWith("set")) |
{ |
54,11 → 57,11 |
} |
}; |
|
User u = (User) factory.create(new Class[0], new Object[0], handler); |
Course u = (Course) factory.create(new Class[0], new Object[0], handler); |
u.setId(3); |
|
u.getUsername(); |
u.getCourses(); |
u.getName(); |
u.getInstitutionalCode(); |
u.getId(); |
|
} |