use of com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery in project elide by yahoo.
the class SQLQueryEngine method constructTable.
@Override
protected Table constructTable(Namespace namespace, Type<?> entityClass, EntityDictionary metaDataDictionary) {
String dbConnectionName = null;
Annotation annotation = EntityDictionary.getFirstAnnotation(entityClass, Arrays.asList(FromTable.class, FromSubquery.class));
if (annotation instanceof FromTable) {
dbConnectionName = ((FromTable) annotation).dbConnectionName();
} else if (annotation instanceof FromSubquery) {
dbConnectionName = ((FromSubquery) annotation).dbConnectionName();
}
ConnectionDetails connectionDetails = connectionDetailsLookup.apply(dbConnectionName);
return new SQLTable(namespace, entityClass, metaDataDictionary, connectionDetails);
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery in project elide by yahoo.
the class SQLTable method resolveTableOrSubselect.
/**
* Maps an entity class to a physical table or subselect query, if neither {@link javax.persistence.Table}
* nor {@link Subselect} annotation is present on this class, try {@link FromTable} and {@link FromSubquery}.
* @param cls The entity class.
* @return The physical SQL table or subselect query.
*/
public static String resolveTableOrSubselect(EntityDictionary dictionary, Type<?> cls) {
if (hasSql(cls)) {
if (cls.isAnnotationPresent(FromSubquery.class)) {
return dictionary.getAnnotation(cls, FromSubquery.class).sql();
}
return dictionary.getAnnotation(cls, Subselect.class).value();
}
javax.persistence.Table table = dictionary.getAnnotation(cls, javax.persistence.Table.class);
if (table != null) {
return resolveTableAnnotation(table);
}
FromTable fromTable = dictionary.getAnnotation(cls, FromTable.class);
return fromTable != null ? fromTable.name() : cls.getSimpleName();
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery in project elide by yahoo.
the class TableType method buildAnnotations.
private static Map<Class<? extends Annotation>, Annotation> buildAnnotations(Table table) {
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>();
annotations.put(Include.class, getIncludeAnnotation(table));
if (table.getSql() != null && !table.getSql().isEmpty()) {
annotations.put(FromSubquery.class, new FromSubquery() {
@Override
public Class<? extends Annotation> annotationType() {
return FromSubquery.class;
}
@Override
public String sql() {
return table.getSql();
}
@Override
public String dbConnectionName() {
return table.getDbConnectionName();
}
});
} else {
annotations.put(FromTable.class, new FromTable() {
@Override
public Class<? extends Annotation> annotationType() {
return FromTable.class;
}
@Override
public String name() {
String tableName = table.getTable();
if (table.getSchema() != null && !table.getSchema().isEmpty()) {
return table.getSchema() + "." + tableName;
}
return tableName;
}
@Override
public String dbConnectionName() {
return table.getDbConnectionName();
}
});
}
annotations.put(TableMeta.class, new TableMeta() {
@Override
public Class<? extends Annotation> annotationType() {
return TableMeta.class;
}
@Override
public String friendlyName() {
return table.getFriendlyName();
}
@Override
public String description() {
return table.getDescription();
}
@Override
public String category() {
return table.getCategory();
}
@Override
public String[] hints() {
return table.getHints().toArray(new String[0]);
}
@Override
public String[] tags() {
return table.getTags().toArray(new String[0]);
}
@Override
public String filterTemplate() {
return table.getFilterTemplate();
}
@Override
public boolean isFact() {
return table.getIsFact();
}
@Override
public boolean isHidden() {
return table.getHidden() != null && table.getHidden();
}
@Override
public CardinalitySize size() {
if (table.getCardinality() == null || table.getCardinality().isEmpty()) {
return CardinalitySize.UNKNOWN;
}
return CardinalitySize.valueOf(table.getCardinality().toUpperCase(Locale.ENGLISH));
}
@Override
public ArgumentDefinition[] arguments() {
return getArgumentDefinitions(table.getArguments());
}
});
String readPermission = table.getReadAccess();
if (StringUtils.isNotEmpty(readPermission)) {
annotations.put(ReadPermission.class, new ReadPermission() {
@Override
public Class<? extends Annotation> annotationType() {
return ReadPermission.class;
}
@Override
public String expression() {
return readPermission;
}
});
}
return annotations;
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery in project elide by yahoo.
the class TableTypeTest method testTableSQL.
@Test
void testTableSQL() throws Exception {
Table testTable = Table.builder().sql("SELECT * FROM FOO").name("Table").dbConnectionName("dbConn").build();
TableType testType = new TableType(testTable);
FromSubquery fromSubquery = (FromSubquery) testType.getAnnotation(FromSubquery.class);
assertEquals("SELECT * FROM FOO", fromSubquery.sql());
assertEquals("dbConn", fromSubquery.dbConnectionName());
}
Aggregations