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;
}
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;
}
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);
}
}
Aggregations