Search in sources :

Example 16 with SqlBoxException

use of com.github.drinkjava2.jsqlbox.SqlBoxException in project jSqlBox by drinkjava2.

the class EntityNetUtils method jointConfigModels.

public static TableModel[] jointConfigModels(TableModel[] bindeds, TableModel[] givens) {
    // check setted to avoid user set empty value to TableModel
    Map<String, TableModel> uses = new HashMap<String, TableModel>();
    for (TableModel tb : givens) {
        SqlBoxException.assureNotNull(tb.getEntityClass(), "EntityClass setting can not be null for '" + tb.getTableName() + "'");
        SqlBoxException.assureNotEmpty(tb.getTableName(), "TableName setting can not be empty for '" + tb.getTableName() + "'");
        uses.put(tb.getTableName().toLowerCase(), tb);
    }
    for (TableModel tb : bindeds) {
        SqlBoxException.assureNotEmpty(tb.getTableName(), "TableName setting can not be empty for '" + tb.getTableName() + "'");
        TableModel exist = uses.get(tb.getTableName().toLowerCase());
        if (tb.getEntityClass() != null) {
            // it's binded by has entityClass
            if (exist == null)
                uses.put(tb.getTableName().toLowerCase(), tb);
            else
                // exist and current tb both can use, duplicated
                throw new SqlBoxException("Duplicated entityClass setting for '" + tb.getTableName() + "'");
        }
    }
    for (TableModel tb : bindeds) {
        // use alias to fill
        TableModel exist = uses.get(tb.getTableName().toLowerCase());
        if (exist != null && tb.getEntityClass() == null) {
            // it's binded by
            // has
            // entityClass
            String alias = tb.getAlias();
            if (!StrUtils.isEmpty(alias) && StrUtils.isEmpty(exist.getAlias()))
                exist.setAlias(alias);
        }
    }
    TableModel[] result = new TableModel[uses.size()];
    int i = 0;
    for (Entry<String, TableModel> entry : uses.entrySet()) {
        result[i++] = entry.getValue();
    }
    return result;
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) SqlBoxException(com.github.drinkjava2.jsqlbox.SqlBoxException) TableModel(com.github.drinkjava2.jdialects.model.TableModel)

Aggregations

Method (java.lang.reflect.Method)9 TableModel (com.github.drinkjava2.jdialects.model.TableModel)8 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)6 SqlBoxException (com.github.drinkjava2.jsqlbox.SqlBoxException)6 PreparedSQL (com.github.drinkjava2.jdbpro.inline.PreparedSQL)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 Type (com.github.drinkjava2.jdialects.Type)1 GenerationType (com.github.drinkjava2.jdialects.annotation.jpa.GenerationType)1 IdGenerator (com.github.drinkjava2.jdialects.id.IdGenerator)1 IdentityIdGenerator (com.github.drinkjava2.jdialects.id.IdentityIdGenerator)1 FKeyModel (com.github.drinkjava2.jdialects.model.FKeyModel)1 Sql (com.github.drinkjava2.jsqlbox.annotation.Sql)1 EntityListHandler (com.github.drinkjava2.jsqlbox.handler.EntityListHandler)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1