/** * Ignore this DB column. It is not mapped to any bean property. */ public RawSqlBuilder columnMappingIgnore(String dbColumn) { return columnMapping(dbColumn, IGNORE_COLUMN); }
public List<CustomerWithPurchaseStats> getAllCustomersWithPurchaseStats() { StringBuilder sql = new StringBuilder("SELECT cu.id, <manually add all fields you need mapped ").append(" FROM customer cu "); RawSqlBuilder rawSqlBuilder = RawSqlBuilder.parse(sql.toString()); rawSqlBuilder.tableAliasMapping("cu", "customer").create(); return Ebean.find(CustomerWithPurchaseStats.class) .setRawSql(rawSqlBuilder.create()) .findList(); }
private void readXmlRawSql(DeployBeanDescriptor<?> deployDesc, List<Dnode> entityXml) { List<Dnode> rawSqlQueries = xmlConfig.find(entityXml, "raw-sql"); for (int i = 0; i < rawSqlQueries.size(); i++) { Dnode rawSqlDnode = rawSqlQueries.get(i); String name = rawSqlDnode.getAttribute("name"); if (isEmpty(name)) { throw new IllegalStateException("raw-sql for " + deployDesc.getFullName() + " missing name attribute"); } Dnode queryNode = rawSqlDnode.find("query"); if (queryNode == null) { throw new IllegalStateException("raw-sql for " + deployDesc.getFullName() + " missing query element"); } String sql = queryNode.getNodeContent(); if (isEmpty(sql)) { throw new IllegalStateException("raw-sql for " + deployDesc.getFullName() + " has empty sql in the query element?"); } List<Dnode> columnMappings = rawSqlDnode.findAll("columnMapping", 1); RawSqlBuilder rawSqlBuilder = RawSqlBuilder.parse(sql); for (int j = 0; j < columnMappings.size(); j++) { Dnode cm = columnMappings.get(j); String column = cm.getAttribute("column"); String property = cm.getAttribute("property"); rawSqlBuilder.columnMapping(column, property); } RawSql rawSql = rawSqlBuilder.create(); DeployNamedQuery namedQuery = new DeployNamedQuery(name, rawSql); deployDesc.add(namedQuery); } }
private void readEntityMapping(ClassLoader classLoader, XmEntity entityDeploy) { String entityClassName = entityDeploy.getClazz(); Class<?> entityClass; try { entityClass = Class.forName(entityClassName, false, classLoader); } catch (Exception e) { logger.error("Could not load entity bean class " + entityClassName + " for ebean.xml entry"); return; } DeployBeanInfo<?> info = deployInfoMap.get(entityClass); if (info == null) { logger.error("No entity bean for ebean.xml entry " + entityClassName); } else { for (XmRawSql sql : entityDeploy.getRawSql()) { RawSqlBuilder builder = RawSqlBuilder.parse(sql.getQuery().getValue()); for (XmColumnMapping columnMapping : sql.getColumnMapping()) { builder.columnMapping(columnMapping.getColumn(), columnMapping.getProperty()); } for (XmAliasMapping aliasMapping : sql.getAliasMapping()) { builder.tableAliasMapping(aliasMapping.getAlias(), aliasMapping.getProperty()); } info.addRawSql(sql.getName(), builder.create()); } for (XmNamedQuery namedQuery : entityDeploy.getNamedQuery()) { info.addNamedQuery(namedQuery.getName(), namedQuery.getQuery().getValue()); } } }
/** * Return an unparsed RawSqlBuilder. Unlike a parsed one this query can not be * modified - so no additional WHERE or HAVING expressions can be added to * this query. */ public static RawSqlBuilder unparsed(String sql) { Sql s = new Sql(sql); return new RawSqlBuilder(s, new ColumnMapping()); }
RawSql rawSql = RawSqlBuilder.resultSet(resultSet, propertyNames.toArray(new String[propertyNames.size()])); query.setRawSql(rawSql); return createRawSqlSqlTree(request, predicates);
private void readXmlRawSql(DeployBeanDescriptor<?> deployDesc, List<Dnode> entityXml) { List<Dnode> rawSqlQueries = xmlConfig.find(entityXml, "raw-sql"); for (int i = 0; i < rawSqlQueries.size(); i++) { Dnode rawSqlDnode = rawSqlQueries.get(i); String name = rawSqlDnode.getAttribute("name"); if (isEmpty(name)) { throw new IllegalStateException("raw-sql for " + deployDesc.getFullName() + " missing name attribute"); } Dnode queryNode = rawSqlDnode.find("query"); if (queryNode == null) { throw new IllegalStateException("raw-sql for " + deployDesc.getFullName() + " missing query element"); } String sql = queryNode.getNodeContent(); if (isEmpty(sql)) { throw new IllegalStateException("raw-sql for " + deployDesc.getFullName() + " has empty sql in the query element?"); } List<Dnode> columnMappings = rawSqlDnode.findAll("columnMapping", 1); RawSqlBuilder rawSqlBuilder = RawSqlBuilder.parse(sql); for (int j = 0; j < columnMappings.size(); j++) { Dnode cm = columnMappings.get(j); String column = cm.getAttribute("column"); String property = cm.getAttribute("property"); rawSqlBuilder.columnMapping(column, property); } RawSql rawSql = rawSqlBuilder.create(); DeployNamedQuery namedQuery = new DeployNamedQuery(name, rawSql); deployDesc.add(namedQuery); } }
/** * Return an unparsed RawSqlBuilder. Unlike a parsed one this query can not be * modified - so no additional WHERE or HAVING expressions can be added to * this query. */ public static RawSqlBuilder unparsed(String sql) { Sql s = new Sql(sql); return new RawSqlBuilder(s, new ColumnMapping()); }
/** * Return an unparsed RawSqlBuilder. Unlike a parsed one this query can not be * modified - so no additional WHERE or HAVING expressions can be added to * this query. */ public static RawSqlBuilder unparsed(String sql) { Sql s = new Sql(sql); return new RawSqlBuilder(s, new ColumnMapping()); }
/** * Ignore this DB column. It is not mapped to any bean property. */ public RawSqlBuilder columnMappingIgnore(String dbColumn) { return columnMapping(dbColumn, IGNORE_COLUMN); }
/** * Return a RawSqlBuilder parsing the sql. * <p> * The sql statement will be parsed so that Ebean can determine where it can * insert additional WHERE or HAVING expressions. * </p> * <p> * Additionally the selected columns are parsed to determine the column * ordering. This also means additional checks can be made with the column * mapping - specifically we can check that all columns are mapped and that * correct column names are entered into the mapping. * </p> */ public static RawSqlBuilder parse(String sql) { Sql sql2 = DRawSqlParser.parse(sql); String select = sql2.getPreFrom(); ColumnMapping mapping = DRawSqlColumnsParser.parse(select); return new RawSqlBuilder(sql2, mapping); }
/** * Ignore this DB column. It is not mapped to any bean property. */ public RawSqlBuilder columnMappingIgnore(String dbColumn) { return columnMapping(dbColumn, IGNORE_COLUMN); }
/** * Return a RawSqlBuilder parsing the sql. * <p> * The sql statement will be parsed so that Ebean can determine where it can * insert additional WHERE or HAVING expressions. * </p> * <p> * Additionally the selected columns are parsed to determine the column * ordering. This also means additional checks can be made with the column * mapping - specifically we can check that all columns are mapped and that * correct column names are entered into the mapping. * </p> */ public static RawSqlBuilder parse(String sql) { Sql sql2 = DRawSqlParser.parse(sql); String select = sql2.getPreFrom(); ColumnMapping mapping = DRawSqlColumnsParser.parse(select); return new RawSqlBuilder(sql2, mapping); }
/** * Return a RawSqlBuilder parsing the sql. * <p> * The sql statement will be parsed so that Ebean can determine where it can * insert additional WHERE or HAVING expressions. * </p> * <p> * Additionally the selected columns are parsed to determine the column * ordering. This also means additional checks can be made with the column * mapping - specifically we can check that all columns are mapped and that * correct column names are entered into the mapping. * </p> */ public static RawSqlBuilder parse(String sql) { Sql sql2 = DRawSqlParser.parse(sql); String select = sql2.getPreFrom(); ColumnMapping mapping = DRawSqlColumnsParser.parse(select); return new RawSqlBuilder(sql2, mapping); }