Search in sources :

Example 1 with DbTable

use of jodd.db.oom.meta.DbTable in project jodd by oblac.

the class DbMetaUtil method resolveTableName.

/**
	 * Resolves table name from a type. If type is annotated, table name
	 * will be read from annotation value. If this value is empty or if
	 * type is not annotated, table name will be set to wildcard pattern '*'
	 * (to match all tables).
	 */
public static String resolveTableName(Class<?> type, TableNamingStrategy tableNamingStrategy) {
    String tableName = null;
    DbTable dbTable = type.getAnnotation(DbTable.class);
    if (dbTable != null) {
        tableName = dbTable.value().trim();
    }
    if ((tableName == null) || (tableName.length() == 0)) {
        tableName = tableNamingStrategy.convertEntityNameToTableName(type);
    } else {
        if (!tableNamingStrategy.isStrictAnnotationNames()) {
            tableName = tableNamingStrategy.applyToTableName(tableName);
        }
    }
    return tableName;
}
Also used : DbTable(jodd.db.oom.meta.DbTable)

Example 2 with DbTable

use of jodd.db.oom.meta.DbTable in project jodd by oblac.

the class DbMetaUtil method resolveSchemaName.

/**
	 * Resolves schema name from a type. Uses default schema name if not specified.
	 */
public static String resolveSchemaName(Class<?> type, String defaultSchemaName) {
    String schemaName = null;
    DbTable dbTable = type.getAnnotation(DbTable.class);
    if (dbTable != null) {
        schemaName = dbTable.schema().trim();
    }
    if ((schemaName == null) || (schemaName.length() == 0)) {
        schemaName = defaultSchemaName;
    }
    return schemaName;
}
Also used : DbTable(jodd.db.oom.meta.DbTable)

Example 3 with DbTable

use of jodd.db.oom.meta.DbTable in project jodd by oblac.

the class AutomagicDbOomConfigurator method onEntry.

/**
	 * Scans all classes and registers only those annotated with {@link DbTable}.
	 * Because of performance purposes, classes are not dynamically loaded; instead, their
	 * file content is examined.
	 */
@Override
protected void onEntry(EntryData entryData) {
    String entryName = entryData.getName();
    InputStream inputStream = entryData.openInputStream();
    if (!isTypeSignatureInUse(inputStream, dbTableAnnotationBytes)) {
        return;
    }
    Class<?> beanClass;
    try {
        beanClass = loadClass(entryName);
    } catch (ClassNotFoundException cnfex) {
        throw new DbOomException("Entry class not found: " + entryName, cnfex);
    }
    if (beanClass == null) {
        return;
    }
    DbTable dbTable = beanClass.getAnnotation(DbTable.class);
    if (dbTable == null) {
        return;
    }
    if (registerAsEntities) {
        dbOomManager.registerEntity(beanClass);
    } else {
        dbOomManager.registerType(beanClass);
    }
}
Also used : DbOomException(jodd.db.oom.DbOomException) InputStream(java.io.InputStream) DbTable(jodd.db.oom.meta.DbTable)

Aggregations

DbTable (jodd.db.oom.meta.DbTable)3 InputStream (java.io.InputStream)1 DbOomException (jodd.db.oom.DbOomException)1