|  | @@ -2,6 +2,7 @@ package db;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.lang.annotation.Annotation;
 | 
	
		
			
				|  |  |  import java.lang.reflect.Field;
 | 
	
		
			
				|  |  | +import java.lang.reflect.InvocationTargetException;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import db.annotation.DbField;
 | 
	
		
			
				|  |  |  import db.annotation.DbId;
 | 
	
	
		
			
				|  | @@ -78,6 +79,26 @@ public class DatabaseUtils {
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  | +	public static DatabaseTable<?> getDatabaseTable(Field f) {
 | 
	
		
			
				|  |  | +		if (!(isDbLink(f) && isPersistable(f.getType()))) {
 | 
	
		
			
				|  |  | +			return null;
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		String pckg = getDbLink(f);
 | 
	
		
			
				|  |  | +		String[] split = f.getType().getName().split("\\.");
 | 
	
		
			
				|  |  | +		String className = split[split.length - 1];
 | 
	
		
			
				|  |  | +		return getDatabaseTable(pckg, className);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	public static DatabaseTable<?> getDatabaseTable(String pckg, String className) {
 | 
	
		
			
				|  |  | +		Class<?> clazz;
 | 
	
		
			
				|  |  | +		try {
 | 
	
		
			
				|  |  | +			clazz = Class.forName(pckg + "." + className + "Table");
 | 
	
		
			
				|  |  | +			return (DatabaseTable<?>) clazz.getMethod("getInstance").invoke(null);
 | 
	
		
			
				|  |  | +		} catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
 | 
	
		
			
				|  |  | +			throw new IllegalStateException("Unable to load " + className + "Table in the package " + pckg, e);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  |  	private static boolean isAnnotation(Field f, Class<? extends Annotation> clazz) {
 | 
	
		
			
				|  |  |  		return f.isAnnotationPresent(clazz);
 | 
	
		
			
				|  |  |  	}
 |