Added a bit of functionality to automatic class parser

This commit is contained in:
Acrobot 2012-11-02 20:12:46 +01:00
parent 51d4cf1b61
commit 533d9eacdd
2 changed files with 24 additions and 0 deletions

View File

@ -33,6 +33,8 @@ public class Database {
}
/**
* @Deprecated - Not ready yet
*
* Creates a table from a given class
*
* @param clazz Class with fields

View File

@ -3,6 +3,7 @@ package com.Acrobot.Breeze.Database;
import com.google.common.base.Joiner;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.lang.annotation.AnnotationFormatError;
import java.lang.reflect.Field;
import java.util.LinkedList;
@ -46,6 +47,27 @@ public class EntityParser {
* @return SQL type
*/
public String convertToSQL(Field field) {
String sqlType = "";
Class<?> type = field.getType();
if (type.isAssignableFrom(String.class)) {
sqlType += "VARCHAR(255)";
} else if (type.isAssignableFrom(boolean.class)) {
sqlType += "BOOLEAN";
} else if (type.isAssignableFrom(int.class)) {
sqlType += "INTEGER";
} else if (type.isAssignableFrom(double.class)) {
sqlType += "DOUBLE";
} else if (type.isAssignableFrom(float.class)) {
sqlType += "FLOAT";
} else {
sqlType += "TEXT";
}
if (field.isAnnotationPresent(Id.class)) {
sqlType += " AUTO INCREMENT";
}
return null; //TODO Finish this
}
}