mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#716 - Remove createNamedQuery() and createQuery(Class<T> beanType, String query) ... use criteria API, query beans and RawSql
This commit is contained in:
1 parent
a20822a9e1
commit
11d623cb69
58 files changed
+56
-3578
No files matched your search
@@ -347,10 +347,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
|
||||
*/
|
||||
private final String fullName;
|
||||
|
||||
private final Map<String, DeployNamedQuery> namedQueries;
|
||||
|
||||
private final Map<String, DeployNamedUpdate> namedUpdates;
|
||||
|
||||
/**
|
||||
* Flag used to determine if saves can be skipped.
|
||||
*/
|
||||
@@ -414,9 +410,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
|
||||
this.beanType = deploy.getBeanType();
|
||||
this.rootBeanType = PersistenceContextUtil.root(beanType);
|
||||
this.prototypeEntityBean = createPrototypeEntityBean(beanType);
|
||||
|
||||
this.namedQueries = deploy.getNamedQueries();
|
||||
this.namedUpdates = deploy.getNamedUpdates();
|
||||
|
||||
this.inheritInfo = deploy.getInheritInfo();
|
||||
|
||||
@@ -703,14 +696,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
|
||||
softDeleteByIdSql = null;
|
||||
softDeleteByIdInSql = null;
|
||||
}
|
||||
|
||||
if (!isEmbedded()) {
|
||||
// parse every named update up front into sql dml
|
||||
for (DeployNamedUpdate namedUpdate : namedUpdates.values()) {
|
||||
DeployUpdateParser parser = new DeployUpdateParser(this);
|
||||
namedUpdate.initialise(parser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1532,24 +1517,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
|
||||
return idBinder.getBindValues(idValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a named query.
|
||||
*/
|
||||
public DeployNamedQuery getNamedQuery(String name) {
|
||||
return namedQueries.get(name);
|
||||
}
|
||||
|
||||
public void addNamedQuery(DeployNamedQuery deployNamedQuery) {
|
||||
namedQueries.put(deployNamedQuery.getName(), deployNamedQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a named update.
|
||||
*/
|
||||
public DeployNamedUpdate getNamedUpdate(String name) {
|
||||
return namedUpdates.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T createBean() {
|
||||
|
||||
@@ -2,9 +2,6 @@ package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebean.BackgroundExecutor;
|
||||
import com.avaje.ebean.Model;
|
||||
import com.avaje.ebean.RawSql;
|
||||
import com.avaje.ebean.RawSqlBuilder;
|
||||
import com.avaje.ebeaninternal.api.ConcurrencyMode;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.cache.ServerCacheManager;
|
||||
@@ -15,20 +12,20 @@ import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.DbHistorySupport;
|
||||
import com.avaje.ebean.config.dbplatform.DbIdentity;
|
||||
import com.avaje.ebean.config.dbplatform.PlatformIdGenerator;
|
||||
import com.avaje.ebean.config.dbplatform.IdType;
|
||||
import com.avaje.ebean.config.dbplatform.PlatformIdGenerator;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogFilter;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogListener;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogPrepare;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogRegister;
|
||||
import com.avaje.ebean.plugin.BeanType;
|
||||
import com.avaje.ebeaninternal.api.ConcurrencyMode;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
import com.avaje.ebeaninternal.server.core.BootupClasses;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.core.InternalConfiguration;
|
||||
import com.avaje.ebeaninternal.server.core.Message;
|
||||
import com.avaje.ebeaninternal.server.core.XmlConfig;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.IdBinder;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.IdBinderEmbedded;
|
||||
@@ -46,8 +43,6 @@ import com.avaje.ebeaninternal.server.deploy.parse.DeployInherit;
|
||||
import com.avaje.ebeaninternal.server.deploy.parse.DeployUtil;
|
||||
import com.avaje.ebeaninternal.server.deploy.parse.ReadAnnotations;
|
||||
import com.avaje.ebeaninternal.server.deploy.parse.TransientProperties;
|
||||
import com.avaje.ebeaninternal.server.idgen.UuidIdGenerator;
|
||||
import com.avaje.ebeaninternal.server.lib.util.Dnode;
|
||||
import com.avaje.ebeaninternal.server.properties.BeanPropertiesReader;
|
||||
import com.avaje.ebeaninternal.server.properties.BeanPropertyInfo;
|
||||
import com.avaje.ebeaninternal.server.properties.BeanPropertyInfoFactory;
|
||||
@@ -109,8 +104,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
private final DeployCreateProperties createProperties;
|
||||
|
||||
private final DeployOrmXml deployOrmXml;
|
||||
|
||||
private final BeanManagerFactory beanManagerFactory;
|
||||
|
||||
private final ServerConfig serverConfig;
|
||||
@@ -163,8 +156,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
private final IdBinderFactory idBinderFactory;
|
||||
|
||||
private final XmlConfig xmlConfig;
|
||||
|
||||
private final BeanLifecycleAdapterFactory beanLifecycleAdapterFactory;
|
||||
|
||||
private final boolean eagerFetchLobs;
|
||||
@@ -190,7 +181,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
this.serverName = InternString.intern(serverConfig.getName());
|
||||
this.cacheManager = config.getCacheManager();
|
||||
this.docStoreFactory = config.getDocStoreFactory();
|
||||
this.xmlConfig = config.getXmlConfig();
|
||||
this.dbSequenceBatchSize = serverConfig.getDatabaseSequenceBatchSize();
|
||||
this.backgroundExecutor = config.getBackgroundExecutor();
|
||||
this.dataSource = serverConfig.getDataSource();
|
||||
@@ -207,7 +197,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
this.namingConvention = serverConfig.getNamingConvention();
|
||||
this.dbIdentity = config.getDatabasePlatform().getDbIdentity();
|
||||
this.deplyInherit = config.getDeployInherit();
|
||||
this.deployOrmXml = config.getDeployOrmXml();
|
||||
this.deployUtil = config.getDeployUtil();
|
||||
|
||||
this.beanManagerFactory = new BeanManagerFactory(config.getDatabasePlatform());
|
||||
@@ -316,10 +305,8 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
readEntityBeanTable();
|
||||
readEntityDeploymentAssociations();
|
||||
readInheritedIdGenerators();
|
||||
|
||||
// creates the BeanDescriptors
|
||||
readEntityRelationships();
|
||||
readRawSqlQueries();
|
||||
|
||||
List<BeanDescriptor<?>> list = new ArrayList<BeanDescriptor<?>>(descMap.values());
|
||||
Collections.sort(list, beanDescComparator);
|
||||
@@ -555,10 +542,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
return beanManagerMap.get(beanClassName);
|
||||
}
|
||||
|
||||
public DNativeQuery getNativeQuery(String name) {
|
||||
return deployOrmXml.getNativeQuery(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the BeanControllers, BeanFinders and BeanListeners.
|
||||
*/
|
||||
@@ -679,25 +662,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
return new BeanTable(beanTable, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the named Raw Sql queries using BeanDescriptor.
|
||||
*/
|
||||
private void readRawSqlQueries() {
|
||||
|
||||
for (DeployBeanInfo<?> info : deplyInfoMap.values()) {
|
||||
|
||||
DeployBeanDescriptor<?> deployDesc = info.getDescriptor();
|
||||
BeanDescriptor<?> desc = getBeanDescriptor(deployDesc.getBeanType());
|
||||
|
||||
for (DRawSqlMeta rawSqlMeta : deployDesc.getRawSqlMeta()) {
|
||||
if (rawSqlMeta.getQuery() != null) {
|
||||
DeployNamedQuery nq = new DRawSqlSelectBuilder(namingConvention, desc, rawSqlMeta).parse();
|
||||
desc.addNamedQuery(nq);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private void readEntityRelationships() {
|
||||
|
||||
@@ -1148,8 +1112,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
readAnnotations.readAssociations(info, this);
|
||||
|
||||
readXml(desc);
|
||||
|
||||
if (EntityType.SQL == desc.getEntityType()) {
|
||||
desc.setBaseTable(null, null, null);
|
||||
}
|
||||
@@ -1271,127 +1233,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
}
|
||||
}
|
||||
|
||||
private void readXml(DeployBeanDescriptor<?> deployDesc) {
|
||||
|
||||
List<Dnode> eXml = xmlConfig.findEntityXml(deployDesc.getFullName());
|
||||
readXmlRawSql(deployDesc, eXml);
|
||||
|
||||
Dnode entityXml = deployOrmXml.findEntityDeploymentXml(deployDesc.getFullName());
|
||||
|
||||
if (entityXml != null) {
|
||||
readXmlNamedQueries(deployDesc, entityXml);
|
||||
readXmlSql(deployDesc, entityXml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read sql-select (FUTURE: additionally sql-insert, sql-update, sql-delete).
|
||||
* If found this entity bean is based on raw sql.
|
||||
*/
|
||||
private void readXmlSql(DeployBeanDescriptor<?> deployDesc, Dnode entityXml) {
|
||||
|
||||
List<Dnode> sqlSelectList = entityXml.findAll("sql-select", entityXml.getLevel() + 1);
|
||||
for (int i = 0; i < sqlSelectList.size(); i++) {
|
||||
Dnode sqlSelect = sqlSelectList.get(i);
|
||||
readSqlSelect(deployDesc, sqlSelect);
|
||||
}
|
||||
}
|
||||
|
||||
private String findContent(Dnode node, String nodeName) {
|
||||
Dnode found = node.find(nodeName);
|
||||
if (found != null) {
|
||||
return found.getNodeContent();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void readSqlSelect(DeployBeanDescriptor<?> deployDesc, Dnode sqlSelect) {
|
||||
|
||||
String name = sqlSelect.getStringAttr("name", "default");
|
||||
String extend = sqlSelect.getStringAttr("extend", null);
|
||||
String queryDebug = sqlSelect.getStringAttr("debug", null);
|
||||
boolean debug = (queryDebug != null && queryDebug.equalsIgnoreCase("true"));
|
||||
|
||||
// the raw sql select
|
||||
String query = findContent(sqlSelect, "query");
|
||||
String where = findContent(sqlSelect, "where");
|
||||
String having = findContent(sqlSelect, "having");
|
||||
String columnMapping = findContent(sqlSelect, "columnMapping");
|
||||
|
||||
DRawSqlMeta m = new DRawSqlMeta(name, extend, query, debug, where, having, columnMapping);
|
||||
|
||||
deployDesc.add(m);
|
||||
|
||||
}
|
||||
|
||||
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 boolean isEmpty(String s) {
|
||||
return s == null || s.trim().length() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read named queries for this bean type.
|
||||
*/
|
||||
private void readXmlNamedQueries(DeployBeanDescriptor<?> deployDesc, Dnode entityXml) {
|
||||
|
||||
// look for named-query...
|
||||
List<Dnode> namedQueries = entityXml.findAll("named-query", 1);
|
||||
|
||||
for (Dnode namedQueryXml : namedQueries) {
|
||||
|
||||
String name = namedQueryXml.getAttribute("name");
|
||||
Dnode query = namedQueryXml.find("query");
|
||||
if (query == null) {
|
||||
logger.warn("orm.xml " + deployDesc.getFullName() + " named-query missing query element?");
|
||||
|
||||
} else {
|
||||
String oql = query.getNodeContent();
|
||||
// TODO: QueryHints not read from xml yet
|
||||
if (name == null || oql == null) {
|
||||
logger.warn("orm.xml " + deployDesc.getFullName() + " named-query has no query content?");
|
||||
} else {
|
||||
// add the named query
|
||||
DeployNamedQuery q = new DeployNamedQuery(name, oql, null);
|
||||
deployDesc.add(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BeanPropertyInfoFactory createReflectionFactory() {
|
||||
|
||||
return new EnhanceBeanPropertyInfoFactory();
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
/**
|
||||
* A native query defined in deployment xml.
|
||||
*/
|
||||
public class DNativeQuery {
|
||||
|
||||
final String query;
|
||||
|
||||
public DNativeQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
public class DRawSqlColumnInfo {
|
||||
|
||||
final String name;
|
||||
|
||||
final String label;
|
||||
|
||||
final String propertyName;
|
||||
|
||||
final boolean scalarProperty;
|
||||
|
||||
public DRawSqlColumnInfo(String name, String label, String propertyName, boolean scalarProperty) {
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.propertyName = propertyName;
|
||||
this.scalarProperty = scalarProperty;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public boolean isScalarProperty() {
|
||||
return scalarProperty;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "name:" + name + " label:" + label + " prop:" + propertyName;
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
/**
|
||||
* Meta data for a sql-select object.
|
||||
* <p>
|
||||
* Created from SqlSelect annotation or xml deployment.
|
||||
* </p>
|
||||
*/
|
||||
public class DRawSqlMeta {
|
||||
|
||||
private String name;
|
||||
private String tableAlias;
|
||||
private String extend;
|
||||
private String query;
|
||||
private boolean debug;
|
||||
private String where;
|
||||
private String having;
|
||||
private String columnMapping;
|
||||
|
||||
public DRawSqlMeta(String name, String extend, String query, boolean debug,
|
||||
String where, String having, String columnMapping) {
|
||||
|
||||
this.name = name;
|
||||
this.extend = extend;
|
||||
this.query = query;
|
||||
this.debug = debug;
|
||||
this.having = having;
|
||||
this.where = where;
|
||||
this.columnMapping = columnMapping;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setTableAlias(String tableAlias) {
|
||||
this.tableAlias = tableAlias;
|
||||
}
|
||||
|
||||
public String getTableAlias() {
|
||||
return tableAlias;
|
||||
}
|
||||
|
||||
public String getExtend() {
|
||||
return extend;
|
||||
}
|
||||
|
||||
public void setExtend(String extend) {
|
||||
this.extend = extend;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public String getWhere() {
|
||||
return where;
|
||||
}
|
||||
|
||||
public void setWhere(String where) {
|
||||
this.where = where;
|
||||
}
|
||||
|
||||
public String getHaving() {
|
||||
return having;
|
||||
}
|
||||
|
||||
public void setHaving(String having) {
|
||||
this.having = having;
|
||||
}
|
||||
|
||||
public String getColumnMapping() {
|
||||
return columnMapping;
|
||||
}
|
||||
|
||||
public void setColumnMapping(String columnMapping) {
|
||||
this.columnMapping = columnMapping;
|
||||
}
|
||||
|
||||
public void extend(DRawSqlMeta parentQuery){
|
||||
extendQuery(parentQuery.getQuery());
|
||||
extendColumnMapping(parentQuery.getColumnMapping());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend sql from the parent query that this query 'extends'.
|
||||
*/
|
||||
private void extendQuery(String parentSql) {
|
||||
if (query == null) {
|
||||
query = parentSql;
|
||||
} else {
|
||||
query = parentSql + " " + query;
|
||||
}
|
||||
}
|
||||
|
||||
private void extendColumnMapping(String parentColumnMapping) {
|
||||
if (columnMapping == null){
|
||||
columnMapping = parentColumnMapping;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,267 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import com.avaje.ebeaninternal.server.query.CQueryPredicates;
|
||||
import com.avaje.ebeaninternal.server.query.SqlTree;
|
||||
import com.avaje.ebeaninternal.server.query.SqlTreeNode;
|
||||
import com.avaje.ebeaninternal.server.query.SqlTreeNodeRoot;
|
||||
import com.avaje.ebeaninternal.server.query.SqlTreeProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a SqlSelect raw sql query.
|
||||
*/
|
||||
public class DRawSqlSelect {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DRawSqlSelect.class);
|
||||
|
||||
private final BeanDescriptor<?> desc;
|
||||
|
||||
private final DRawSqlColumnInfo[] selectColumns;
|
||||
|
||||
private final Map<String,DRawSqlColumnInfo> columnMap;
|
||||
|
||||
private final String preWhereExprSql;
|
||||
|
||||
private final boolean andWhereExpr;
|
||||
|
||||
private final String preHavingExprSql;
|
||||
|
||||
private final boolean andHavingExpr;
|
||||
|
||||
private final String orderBySql;
|
||||
|
||||
private final String whereClause;
|
||||
|
||||
private final String havingClause;
|
||||
|
||||
private final String query;
|
||||
|
||||
private final String columnMapping;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final SqlTree sqlTree;
|
||||
|
||||
private boolean withId;
|
||||
|
||||
private final String tableAlias;
|
||||
|
||||
public DRawSqlSelect(BeanDescriptor<?> desc, List<DRawSqlColumnInfo> selectColumns,
|
||||
String tableAlias, String preWhereExprSql, boolean andWhereExpr, String preHavingExprSql,
|
||||
boolean andHavingExpr, String orderBySql, DRawSqlMeta meta) {
|
||||
|
||||
this.desc = desc;
|
||||
this.tableAlias = tableAlias;
|
||||
this.selectColumns = selectColumns.toArray(new DRawSqlColumnInfo[selectColumns.size()]);
|
||||
this.preHavingExprSql = preHavingExprSql;
|
||||
this.preWhereExprSql = preWhereExprSql;
|
||||
this.andHavingExpr = andHavingExpr;
|
||||
this.andWhereExpr = andWhereExpr;
|
||||
this.orderBySql = orderBySql;
|
||||
this.name = meta.getName();
|
||||
this.whereClause = meta.getWhere();
|
||||
this.havingClause = meta.getHaving();
|
||||
this.query = meta.getQuery();
|
||||
this.columnMapping = meta.getColumnMapping();
|
||||
|
||||
this.sqlTree = initialise(desc);
|
||||
this.columnMap = createColumnMap(this.selectColumns);
|
||||
}
|
||||
|
||||
private Map<String,DRawSqlColumnInfo> createColumnMap(DRawSqlColumnInfo[] selectColumns) {
|
||||
|
||||
HashMap<String,DRawSqlColumnInfo> m = new HashMap<String,DRawSqlColumnInfo>();
|
||||
for (int i = 0; i < selectColumns.length; i++) {
|
||||
m.put(selectColumns[i].getPropertyName(), selectColumns[i]);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find foreign keys for assoc one types and build SqlTree.
|
||||
*/
|
||||
private SqlTree initialise(BeanDescriptor<?> owner){
|
||||
|
||||
try {
|
||||
return buildSqlTree(owner);
|
||||
|
||||
} catch (Exception e){
|
||||
String m = "Bug? initialising query "+name+" on "+owner;
|
||||
throw new RuntimeException(m, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the RawSqlColumnInfo given it's logical property name.
|
||||
*/
|
||||
public DRawSqlColumnInfo getRawSqlColumnInfo(String propertyName){
|
||||
return columnMap.get(propertyName);
|
||||
}
|
||||
|
||||
public String getTableAlias() {
|
||||
return tableAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the SqlTree for this query.
|
||||
* <p>
|
||||
* Most commonly this is just a simple list of properties - aka flat, but it
|
||||
* could be a real object graph tree for more complex scenarios.
|
||||
* </p>
|
||||
*/
|
||||
private SqlTree buildSqlTree(BeanDescriptor<?> desc){
|
||||
|
||||
SqlTreeProperties selectProps = new SqlTreeProperties();
|
||||
|
||||
for (int i = 0; i < selectColumns.length; i++) {
|
||||
|
||||
DRawSqlColumnInfo columnInfo = selectColumns[i];
|
||||
String propName = columnInfo.getPropertyName();
|
||||
BeanProperty beanProperty = desc.getBeanProperty(propName);
|
||||
if (beanProperty != null) {
|
||||
if (beanProperty.isId()){
|
||||
if (i > 0){
|
||||
String m = "With "+desc+" query:"+name+" the ID is not the first column in the select. It must be...";
|
||||
throw new PersistenceException(m);
|
||||
} else {
|
||||
withId = true;
|
||||
}
|
||||
} else {
|
||||
selectProps.add(beanProperty);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
String m = "Mapping for " + desc.getFullName();
|
||||
m += " query["+name+"] column[" + columnInfo + "] index[" + i;
|
||||
m += "] not matched to bean property?";
|
||||
logger.error(m);
|
||||
}
|
||||
}
|
||||
|
||||
SqlTreeNode sqlRoot = new SqlTreeNodeRoot(desc, selectProps, withId);
|
||||
|
||||
return new SqlTree(desc.getName(), sqlRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the full SQL Select statement for the request.
|
||||
*/
|
||||
public String buildSql(String orderBy, CQueryPredicates predicates, OrmQueryRequest<?> request) {
|
||||
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(preWhereExprSql);
|
||||
sb.append(" ");
|
||||
|
||||
String dynamicWhere = null;
|
||||
if (request.getQuery().getId() != null) {
|
||||
// need to convert this as well. This avoids the
|
||||
// assumption that id has its proper dbColumn assigned
|
||||
// which may change if using multiple raw sql statements
|
||||
// against the same bean.
|
||||
BeanDescriptor<?> descriptor = request.getBeanDescriptor();
|
||||
//FIXME: I think this is broken... needs to be logical
|
||||
// and then parsed for RawSqlSelect...
|
||||
dynamicWhere = descriptor.getIdBinderIdSql();
|
||||
}
|
||||
|
||||
String dbWhere = predicates.getDbWhere();
|
||||
if (dbWhere != null && dbWhere.length() > 0) {
|
||||
if (dynamicWhere == null) {
|
||||
dynamicWhere = dbWhere;
|
||||
} else {
|
||||
dynamicWhere += " and " + dbWhere;
|
||||
}
|
||||
}
|
||||
|
||||
if (dynamicWhere != null) {
|
||||
if (andWhereExpr) {
|
||||
sb.append(" and ");
|
||||
} else {
|
||||
sb.append(" where ");
|
||||
}
|
||||
sb.append(dynamicWhere);
|
||||
sb.append(" ");
|
||||
}
|
||||
|
||||
if (preHavingExprSql != null) {
|
||||
sb.append(preHavingExprSql);
|
||||
sb.append(" ");
|
||||
}
|
||||
|
||||
String dbHaving = predicates.getDbHaving();
|
||||
|
||||
if (dbHaving != null && dbHaving.length() > 0) {
|
||||
if (andHavingExpr) {
|
||||
sb.append(" and ");
|
||||
} else {
|
||||
sb.append(" having ");
|
||||
}
|
||||
sb.append(dbHaving);
|
||||
sb.append(" ");
|
||||
}
|
||||
|
||||
if (orderBy != null) {
|
||||
sb.append(" order by ").append(orderBy);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getOrderBy(CQueryPredicates predicates) {
|
||||
String orderBy = predicates.getDbOrderBy();
|
||||
if (orderBy != null) {
|
||||
return orderBy;
|
||||
} else {
|
||||
return orderBySql;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SqlTree getSqlTree() {
|
||||
return sqlTree;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public String getColumnMapping() {
|
||||
return columnMapping;
|
||||
}
|
||||
|
||||
public String getWhereClause() {
|
||||
return whereClause;
|
||||
}
|
||||
|
||||
public String getHavingClause() {
|
||||
return havingClause;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return Arrays.toString(selectColumns);
|
||||
}
|
||||
|
||||
public BeanDescriptor<?> getBeanDescriptor() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public DeployParser createDeployPropertyParser() {
|
||||
return new DeployPropertyParserRawSql(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,339 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.config.NamingConvention;
|
||||
import com.avaje.ebeaninternal.server.querydefn.SimpleTextParser;
|
||||
|
||||
/**
|
||||
* Parses sql-select queries to try and determine the location where WHERE and HAVING
|
||||
* clauses can be added dynamically to the sql.
|
||||
*/
|
||||
public class DRawSqlSelectBuilder {
|
||||
|
||||
public static final String $_AND_HAVING = "${andHaving}";
|
||||
|
||||
public static final String $_HAVING = "${having}";
|
||||
|
||||
public static final String $_AND_WHERE = "${andWhere}";
|
||||
|
||||
public static final String $_WHERE = "${where}";
|
||||
|
||||
private static final String ORDER_BY = "order by";
|
||||
|
||||
private final BeanDescriptor<?> desc;
|
||||
|
||||
private final NamingConvention namingConvention;
|
||||
|
||||
private final DRawSqlMeta meta;
|
||||
|
||||
private final boolean debug;
|
||||
|
||||
private String sql;
|
||||
|
||||
private final SimpleTextParser textParser;
|
||||
|
||||
private int placeHolderWhere;
|
||||
private int placeHolderAndWhere;
|
||||
private int placeHolderHaving;
|
||||
private int placeHolderAndHaving;
|
||||
private final boolean hasPlaceHolders;
|
||||
|
||||
private int selectPos = -1;
|
||||
private int fromPos = -1;
|
||||
private int wherePos = -1;
|
||||
private int groupByPos = -1;
|
||||
private int havingPos = -1;
|
||||
private int orderByPos = -1;
|
||||
|
||||
private boolean whereExprAnd;
|
||||
private int whereExprPos = -1;
|
||||
private boolean havingExprAnd;
|
||||
private int havingExprPos = -1;
|
||||
|
||||
private final String tableAlias;
|
||||
|
||||
public DRawSqlSelectBuilder(NamingConvention namingConvention, BeanDescriptor<?> desc, DRawSqlMeta sqlSelectMeta) {
|
||||
|
||||
this.namingConvention = namingConvention;
|
||||
this.desc = desc;
|
||||
this.tableAlias = sqlSelectMeta.getTableAlias();
|
||||
this.meta = sqlSelectMeta;
|
||||
this.debug = sqlSelectMeta.isDebug();
|
||||
this.sql = sqlSelectMeta.getQuery().trim();
|
||||
this.hasPlaceHolders = findAndRemovePlaceHolders();
|
||||
this.textParser = new SimpleTextParser(this.sql);
|
||||
}
|
||||
|
||||
protected NamingConvention getNamingConvention() {
|
||||
return namingConvention;
|
||||
}
|
||||
|
||||
protected BeanDescriptor<?> getBeanDescriptor() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
protected boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
protected void debug(String msg) {
|
||||
if (debug) {
|
||||
System.out.println("debug> " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
public DeployNamedQuery parse() {
|
||||
|
||||
if (debug) {
|
||||
debug("");
|
||||
debug("Parsing sql-select in " + getErrName());
|
||||
}
|
||||
|
||||
if (!hasPlaceHolders()) {
|
||||
// parse the sql for the keywords...
|
||||
// select, from, where, having, group by, order by
|
||||
parseSqlFindKeywords(true);
|
||||
}
|
||||
|
||||
List<DRawSqlColumnInfo> selectColumns = findSelectColumns(meta.getColumnMapping());
|
||||
whereExprPos = findWhereExprPosition();
|
||||
havingExprPos = findHavingExprPosition();
|
||||
|
||||
String preWhereExprSql = removeWhitespace(findPreWhereExprSql());
|
||||
String preHavingExprSql = removeWhitespace(findPreHavingExprSql());
|
||||
|
||||
preWhereExprSql = trimSelectKeyword(preWhereExprSql);
|
||||
|
||||
String orderBySql = findOrderBySql();
|
||||
|
||||
DRawSqlSelect rawSqlSelect = new DRawSqlSelect(desc, selectColumns, tableAlias, preWhereExprSql,
|
||||
whereExprAnd, preHavingExprSql, havingExprAnd, orderBySql, meta);
|
||||
|
||||
return new DeployNamedQuery(rawSqlSelect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and remove the known place holders such as ${where}.
|
||||
*/
|
||||
private boolean findAndRemovePlaceHolders() {
|
||||
placeHolderWhere = removePlaceHolder($_WHERE);
|
||||
placeHolderAndWhere = removePlaceHolder($_AND_WHERE);
|
||||
placeHolderHaving = removePlaceHolder($_HAVING);
|
||||
placeHolderAndHaving = removePlaceHolder($_AND_HAVING);
|
||||
return hasPlaceHolders();
|
||||
}
|
||||
|
||||
private int removePlaceHolder(String placeHolder) {
|
||||
int pos = sql.indexOf(placeHolder);
|
||||
if (pos > -1) {
|
||||
int after = pos + placeHolder.length() + 1;
|
||||
if (after > sql.length()) {
|
||||
sql = sql.substring(0, pos);
|
||||
} else {
|
||||
sql = sql.substring(0, pos) + sql.substring(after);
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
private boolean hasPlaceHolders() {
|
||||
return placeHolderWhere > -1 || placeHolderAndWhere > -1 || placeHolderHaving > -1 || placeHolderAndHaving > -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim off the select keyword (to support row_number() limit function).
|
||||
*/
|
||||
private String trimSelectKeyword(String preWhereExprSql) {
|
||||
|
||||
if (preWhereExprSql.length() < 7){
|
||||
throw new RuntimeException("Expecting at least 7 chars in ["+preWhereExprSql+"]");
|
||||
}
|
||||
|
||||
String select = preWhereExprSql.substring(0, 7);
|
||||
if (!select.equalsIgnoreCase("select ")){
|
||||
throw new RuntimeException("Expecting ["+preWhereExprSql+"] to start with \"select\"");
|
||||
}
|
||||
return preWhereExprSql.substring(7);
|
||||
}
|
||||
|
||||
|
||||
private String findOrderBySql() {
|
||||
if (orderByPos > -1) {
|
||||
int pos = orderByPos + ORDER_BY.length();
|
||||
return sql.substring(pos);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String findPreHavingExprSql() {
|
||||
if (havingExprPos > whereExprPos) {
|
||||
// an order by clause follows...
|
||||
return sql.substring(whereExprPos, havingExprPos - 1);
|
||||
}
|
||||
if (whereExprPos > -1) {
|
||||
// the rest of the sql...
|
||||
return sql.substring(whereExprPos);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String findPreWhereExprSql() {
|
||||
if (whereExprPos > -1) {
|
||||
return sql.substring(0, whereExprPos - 1);
|
||||
} else {
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
|
||||
protected String getErrName() {
|
||||
return "entity[" + desc.getFullName() + "] query[" + meta.getName() + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the columns in the select clause including the table alias' and
|
||||
* column alias.
|
||||
*/
|
||||
private List<DRawSqlColumnInfo> findSelectColumns(String selectClause) {
|
||||
|
||||
if (selectClause == null || selectClause.trim().length() == 0) {
|
||||
if (hasPlaceHolders) {
|
||||
if (debug) {
|
||||
debug("... No explicit ColumnMapping, so parse the sql looking for SELECT and FROM keywords.");
|
||||
}
|
||||
parseSqlFindKeywords(false);
|
||||
}
|
||||
if (selectPos == -1 || fromPos == -1) {
|
||||
String msg = "Error in [" + getErrName() + "] parsing sql looking ";
|
||||
msg += "for SELECT and FROM keywords.";
|
||||
msg += " select:" + selectPos + " from:" + fromPos;
|
||||
msg += ". You could use an explicit columnMapping to bypass this error.";
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
selectPos += "select".length();
|
||||
selectClause = sql.substring(selectPos, fromPos);
|
||||
}
|
||||
|
||||
selectClause = selectClause.trim();
|
||||
if (debug) {
|
||||
debug("ColumnMapping ... [" + selectClause + "]");
|
||||
}
|
||||
|
||||
return new DRawSqlSelectColumnsParser(this,selectClause).parse();
|
||||
}
|
||||
|
||||
private void parseSqlFindKeywords(boolean allKeywords) {
|
||||
|
||||
debug("Parsing query looking for SELECT...");
|
||||
selectPos = textParser.findWordLower("select");
|
||||
if (selectPos == -1) {
|
||||
String msg = "Error in "+getErrName()+" parsing sql, can not find SELECT keyword in:";
|
||||
throw new RuntimeException(msg + sql);
|
||||
}
|
||||
debug("Parsing query looking for FROM... SELECT found at " + selectPos);
|
||||
fromPos = textParser.findWordLower("from");
|
||||
if (fromPos == -1) {
|
||||
String msg = "Error in "+getErrName()+" parsing sql, can not find FROM keyword in:";
|
||||
throw new RuntimeException(msg + sql);
|
||||
}
|
||||
|
||||
if (!allKeywords) {
|
||||
return;
|
||||
}
|
||||
|
||||
debug("Parsing query looking for WHERE... FROM found at " + fromPos);
|
||||
wherePos = textParser.findWordLower("where");
|
||||
if (wherePos == -1) {
|
||||
debug("Parsing query looking for GROUP... no WHERE found");
|
||||
groupByPos = textParser.findWordLower("group", fromPos + 5);
|
||||
} else {
|
||||
debug("Parsing query looking for GROUP... WHERE found at " + wherePos);
|
||||
groupByPos = textParser.findWordLower("group");
|
||||
}
|
||||
if (groupByPos > -1) {
|
||||
debug("Parsing query looking for HAVING... GROUP found at " + groupByPos);
|
||||
havingPos = textParser.findWordLower("having");
|
||||
}
|
||||
|
||||
int startOrderBy = havingPos;
|
||||
if (startOrderBy == -1) {
|
||||
startOrderBy = groupByPos;
|
||||
}
|
||||
if (startOrderBy == -1) {
|
||||
startOrderBy = wherePos;
|
||||
}
|
||||
if (startOrderBy == -1) {
|
||||
startOrderBy = fromPos;
|
||||
}
|
||||
|
||||
debug("Parsing query looking for ORDER... starting at " + startOrderBy);
|
||||
orderByPos = textParser.findWordLower("order", startOrderBy);
|
||||
}
|
||||
|
||||
private int findWhereExprPosition() {
|
||||
if (hasPlaceHolders) {
|
||||
if (placeHolderWhere > -1) {
|
||||
return placeHolderWhere;
|
||||
} else {
|
||||
whereExprAnd = true;
|
||||
return placeHolderAndWhere;
|
||||
}
|
||||
}
|
||||
whereExprAnd = wherePos > 0;
|
||||
if (groupByPos > 0) {
|
||||
return groupByPos;
|
||||
}
|
||||
if (havingPos > 0) {
|
||||
return havingPos;
|
||||
}
|
||||
if (orderByPos > 0) {
|
||||
return orderByPos;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int findHavingExprPosition() {
|
||||
if (hasPlaceHolders) {
|
||||
if (placeHolderHaving > -1) {
|
||||
return placeHolderHaving;
|
||||
} else {
|
||||
havingExprAnd = true;
|
||||
return placeHolderAndHaving;
|
||||
}
|
||||
}
|
||||
havingExprAnd = havingPos > 0;
|
||||
if (orderByPos > 0) {
|
||||
return orderByPos;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private String removeWhitespace(String sql) {
|
||||
if (sql == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
boolean removeWhitespace = false;
|
||||
|
||||
int length = sql.length();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = sql.charAt(i);
|
||||
if (removeWhitespace) {
|
||||
if (!Character.isWhitespace(c)) {
|
||||
sb.append(c);
|
||||
removeWhitespace = false;
|
||||
}
|
||||
} else {
|
||||
if (c == '\r' || c == '\n') {
|
||||
sb.append('\n');
|
||||
removeWhitespace = true;
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.config.NamingConvention;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Parses columnMapping (select clause) mapping columns to bean properties.
|
||||
*/
|
||||
public final class DRawSqlSelectColumnsParser {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DRawSqlSelectColumnsParser.class);
|
||||
|
||||
/**
|
||||
* Description of how the match was made.
|
||||
*/
|
||||
private String matchDescription;
|
||||
|
||||
/**
|
||||
* The actual column string used in search for a matching property.
|
||||
* <p>
|
||||
* This has table alias' and quoted identifiers removed.
|
||||
* </p>
|
||||
*/
|
||||
private String searchColumn;
|
||||
|
||||
private int columnIndex;
|
||||
|
||||
private int pos;
|
||||
|
||||
private final int end;
|
||||
|
||||
private final String sqlSelect;
|
||||
|
||||
private final List<DRawSqlColumnInfo> columns = new ArrayList<DRawSqlColumnInfo>();
|
||||
|
||||
private final BeanDescriptor<?> desc;
|
||||
|
||||
private final NamingConvention namingConvention;
|
||||
|
||||
private final DRawSqlSelectBuilder parent;
|
||||
|
||||
private final boolean debug;
|
||||
|
||||
public DRawSqlSelectColumnsParser(DRawSqlSelectBuilder parent, String sqlSelect) {
|
||||
this.parent = parent;
|
||||
this.debug = parent.isDebug();
|
||||
this.namingConvention = parent.getNamingConvention();
|
||||
this.desc = parent.getBeanDescriptor();
|
||||
this.sqlSelect = sqlSelect;
|
||||
this.end = sqlSelect.length();
|
||||
}
|
||||
|
||||
public List<DRawSqlColumnInfo> parse() {
|
||||
while (pos <= end) {
|
||||
nextColumnInfo();
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
private void nextColumnInfo() {
|
||||
int start = pos;
|
||||
nextComma();
|
||||
String colInfo = sqlSelect.substring(start, pos);
|
||||
pos++;
|
||||
colInfo = colInfo.trim();
|
||||
int secLastSpace = -1;
|
||||
int lastSpace = colInfo.lastIndexOf(' ');
|
||||
if (lastSpace > -1) {
|
||||
secLastSpace = colInfo.lastIndexOf(' ', lastSpace - 1);
|
||||
}
|
||||
String colName;
|
||||
String colLabel;
|
||||
if (lastSpace == -1) {
|
||||
// no column alias
|
||||
colName = colInfo;
|
||||
colLabel = colName;
|
||||
} else if (secLastSpace == -1) {
|
||||
// no 'as' keyword
|
||||
colName = colInfo.substring(0, lastSpace);
|
||||
colLabel = colInfo.substring(lastSpace + 1);
|
||||
if (colName.equals("")) {
|
||||
colName = colLabel;
|
||||
}
|
||||
} else {
|
||||
// check for as keyword
|
||||
String expectedAs = colInfo.substring(secLastSpace + 1, lastSpace);
|
||||
if (expectedAs.toLowerCase().equals("as")) {
|
||||
colName = colInfo.substring(0, secLastSpace);
|
||||
colLabel = colInfo.substring(lastSpace + 1);
|
||||
} else {
|
||||
String msg = "Error in " + parent.getErrName() + ". ";
|
||||
msg += "Expected \"AS\" keyword but got [" + expectedAs + "] in select clause ["
|
||||
+ colInfo + "]";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BeanProperty prop = findProperty(colLabel);
|
||||
if (prop == null) {
|
||||
if (debug) {
|
||||
String msg = "ColumnMapping ... idx[" + columnIndex
|
||||
+ "] ERROR, no property found to match... column[" + colName + "] label[" + colLabel
|
||||
+ "] search[" + searchColumn + "]";
|
||||
parent.debug(msg);
|
||||
}
|
||||
String msg = "Error in " + parent.getErrName() + ". ";
|
||||
msg += "No matching bean property for column[" + colName + "] columnLabel[" + colLabel
|
||||
+ "] idx[" + columnIndex + "] using search[" + searchColumn + "] found?";
|
||||
logger.error(msg);
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
String msg = null;
|
||||
if (debug || logger.isDebugEnabled()) {
|
||||
msg = "ColumnMapping ... idx[" + columnIndex + "] match column[" + colName
|
||||
+ "] label[" + colLabel + "] to property[" + prop + "]"
|
||||
+ matchDescription;
|
||||
}
|
||||
if (debug) {
|
||||
parent.debug(msg);
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(msg);
|
||||
}
|
||||
|
||||
DRawSqlColumnInfo info = new DRawSqlColumnInfo(colName, colLabel, prop.getName(), prop.isScalar());
|
||||
columns.add(info);
|
||||
columnIndex++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private String removeQuotedIdentifierChars(String columnLabel) {
|
||||
|
||||
char c = columnLabel.charAt(0);
|
||||
if (Character.isJavaIdentifierStart(c)) {
|
||||
return columnLabel;
|
||||
}
|
||||
|
||||
// trim off first and last character
|
||||
String result = columnLabel.substring(1, columnLabel.length() - 1);
|
||||
|
||||
String msg = "sql-select trimming quoted identifier from["
|
||||
+ columnLabel + "] to[" + result+ "]";
|
||||
logger.debug(msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the property to match against the given resultSet column.
|
||||
*/
|
||||
private BeanProperty findProperty(String column) {
|
||||
|
||||
searchColumn = column;
|
||||
int dotPos = searchColumn.indexOf(".");
|
||||
if (dotPos > -1) {
|
||||
searchColumn = searchColumn.substring(dotPos + 1);
|
||||
}
|
||||
|
||||
searchColumn = removeQuotedIdentifierChars(searchColumn);
|
||||
|
||||
BeanProperty matchingProp = desc.getBeanProperty(searchColumn);
|
||||
if (matchingProp != null) {
|
||||
matchDescription = "";
|
||||
return matchingProp;
|
||||
}
|
||||
|
||||
// convert columnName using the namingConvention
|
||||
String propertyName = namingConvention.getPropertyFromColumn(desc.getBeanType(), searchColumn);
|
||||
matchingProp = desc.getBeanProperty(propertyName);
|
||||
if (matchingProp != null) {
|
||||
matchDescription = " ... using naming convention";
|
||||
return matchingProp;
|
||||
}
|
||||
|
||||
matchDescription = " ... by linear search";
|
||||
|
||||
// search all properties matching against the property db column
|
||||
BeanProperty[] propertiesBase = desc.propertiesBaseScalar();
|
||||
for (int i = 0; i < propertiesBase.length; i++) {
|
||||
BeanProperty prop = propertiesBase[i];
|
||||
if (isMatch(prop, searchColumn)) {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
||||
BeanProperty idProp = desc.getIdProperty();
|
||||
if (idProp != null) {
|
||||
if (isMatch(idProp, searchColumn)) {
|
||||
return idProp;
|
||||
}
|
||||
}
|
||||
|
||||
BeanPropertyAssocOne<?>[] propertiesAssocOne = desc.propertiesOne();
|
||||
for (int i = 0; i < propertiesAssocOne.length; i++) {
|
||||
BeanProperty prop = propertiesAssocOne[i];
|
||||
if (isMatch(prop, searchColumn)) {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isMatch(BeanProperty prop, String columnLabel) {
|
||||
return columnLabel.equalsIgnoreCase(prop.getDbColumn()) || columnLabel.equalsIgnoreCase(prop.getName());
|
||||
}
|
||||
|
||||
private void nextComma() {
|
||||
boolean inQuote = false;
|
||||
while (pos < end) {
|
||||
char c = sqlSelect.charAt(pos);
|
||||
if (c == '\'') {
|
||||
inQuote = !inQuote;
|
||||
} else if (!inQuote && c == ',') {
|
||||
return;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.QueryHint;
|
||||
|
||||
import com.avaje.ebean.RawSql;
|
||||
|
||||
public class DeployNamedQuery {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String query;
|
||||
|
||||
private final QueryHint[] hints;
|
||||
|
||||
private final DRawSqlSelect sqlSelect;
|
||||
|
||||
private final RawSql rawSql;
|
||||
|
||||
public DeployNamedQuery(NamedQuery namedQuery) {
|
||||
this.name = namedQuery.name();
|
||||
this.query = namedQuery.query();
|
||||
this.hints = namedQuery.hints();
|
||||
this.sqlSelect = null;
|
||||
this.rawSql = null;
|
||||
}
|
||||
|
||||
public DeployNamedQuery(String name, String query, QueryHint[] hints) {
|
||||
this.name = name;
|
||||
this.query = query;
|
||||
this.hints = hints;
|
||||
this.sqlSelect = null;
|
||||
this.rawSql = null;
|
||||
}
|
||||
|
||||
public DeployNamedQuery(String name, RawSql rawSql) {
|
||||
this.name = name;
|
||||
this.query = null;
|
||||
this.hints = null;
|
||||
this.sqlSelect = null;
|
||||
this.rawSql = rawSql;
|
||||
}
|
||||
|
||||
public DeployNamedQuery(DRawSqlSelect sqlSelect) {
|
||||
this.name = sqlSelect.getName();
|
||||
this.query = null;
|
||||
this.hints = null;
|
||||
this.sqlSelect = sqlSelect;
|
||||
this.rawSql = null;
|
||||
}
|
||||
|
||||
public boolean isRawSql() {
|
||||
return rawSql != null;
|
||||
}
|
||||
|
||||
public boolean isSqlSelect() {
|
||||
return sqlSelect != null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public QueryHint[] getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
public RawSql getRawSql() {
|
||||
return rawSql;
|
||||
}
|
||||
|
||||
public DRawSqlSelect getSqlSelect() {
|
||||
return sqlSelect;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebean.annotation.NamedUpdate;
|
||||
|
||||
/**
|
||||
* Deployment information for a named update.
|
||||
*/
|
||||
public class DeployNamedUpdate {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String updateStatement;
|
||||
|
||||
private final boolean notifyCache;
|
||||
|
||||
private String sqlUpdateStatement;
|
||||
|
||||
public DeployNamedUpdate(NamedUpdate update) {
|
||||
this.name = update.name();
|
||||
this.updateStatement = update.update();
|
||||
this.notifyCache = update.notifyCache();
|
||||
}
|
||||
|
||||
public void initialise(DeployUpdateParser parser) {
|
||||
sqlUpdateStatement = parser.parse(updateStatement);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSqlUpdateStatement() {
|
||||
return sqlUpdateStatement;
|
||||
}
|
||||
|
||||
public boolean isNotifyCache() {
|
||||
return notifyCache;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebeaninternal.server.lib.util.Dnode;
|
||||
import com.avaje.ebeaninternal.server.lib.util.DnodeReader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controls the creation and caching of BeanManager's, BeanDescriptors,
|
||||
* BeanTable etc for both beans and tables(MapBeans).
|
||||
* <p>
|
||||
* Also supports some other deployment features such as type conversion.
|
||||
* </p>
|
||||
*/
|
||||
public class DeployOrmXml {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DeployOrmXml.class);
|
||||
|
||||
private final HashMap<String, DNativeQuery> nativeQueryCache;
|
||||
|
||||
private final ArrayList<Dnode> ormXmlList;
|
||||
|
||||
public DeployOrmXml() {
|
||||
this.nativeQueryCache = new HashMap<String, DNativeQuery>();
|
||||
this.ormXmlList = findAllOrmXml();
|
||||
|
||||
initialiseNativeQueries();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all the native queries in ALL orm xml deployment.
|
||||
*/
|
||||
private void initialiseNativeQueries() {
|
||||
for (Dnode ormXml : ormXmlList) {
|
||||
initialiseNativeQueries(ormXml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the native queries in this particular orm xml deployment.
|
||||
*/
|
||||
private void initialiseNativeQueries(Dnode ormXml) {
|
||||
|
||||
Dnode entityMappings = ormXml.find("entity-mappings");
|
||||
if (entityMappings != null) {
|
||||
List<Dnode> nq = entityMappings.findAll("named-native-query", 1);
|
||||
for (int i = 0; i < nq.size(); i++) {
|
||||
Dnode nqNode = nq.get(i);
|
||||
Dnode nqQueryNode = nqNode.find("query");
|
||||
if (nqQueryNode != null) {
|
||||
String queryContent = nqQueryNode.getNodeContent();
|
||||
String queryName = nqNode.getAttribute("name");
|
||||
|
||||
if (queryName != null && queryContent != null) {
|
||||
DNativeQuery query = new DNativeQuery(queryContent);
|
||||
nativeQueryCache.put(queryName, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a native named query.
|
||||
* <p>
|
||||
* These are loaded from the orm.xml deployment file.
|
||||
* </p>
|
||||
*/
|
||||
public DNativeQuery getNativeQuery(String name) {
|
||||
return nativeQueryCache.get(name);
|
||||
}
|
||||
|
||||
private ArrayList<Dnode> findAllOrmXml() {
|
||||
|
||||
ArrayList<Dnode> ormXmlList = new ArrayList<Dnode>();
|
||||
|
||||
|
||||
String defaultFile = "orm.xml";
|
||||
readOrmXml(defaultFile, ormXmlList);
|
||||
|
||||
if (!ormXmlList.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Dnode ox : ormXmlList) {
|
||||
sb.append(", ").append(ox.getAttribute("ebean.filename"));
|
||||
}
|
||||
String loadedFiles = sb.toString().substring(2);
|
||||
logger.info("Deployment xml [" + loadedFiles + "] loaded.");
|
||||
}
|
||||
|
||||
return ormXmlList;
|
||||
}
|
||||
|
||||
private void readOrmXml(String ormXmlName, ArrayList<Dnode> ormXmlList) {
|
||||
|
||||
try {
|
||||
Dnode ormXml = readOrmXmlFromClasspath(ormXmlName);
|
||||
if (ormXml != null) {
|
||||
ormXml.setAttribute("ebean.filename", ormXmlName);
|
||||
ormXmlList.add(ormXml);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("error reading orm xml deployment " + ormXmlName, e);
|
||||
}
|
||||
}
|
||||
|
||||
private Dnode readOrmXmlFromClasspath(String ormXmlName) throws IOException {
|
||||
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(ormXmlName);
|
||||
if (is == null) {
|
||||
return null;
|
||||
} else {
|
||||
return readOrmXml(is);
|
||||
}
|
||||
}
|
||||
|
||||
private Dnode readOrmXml(InputStream in) throws IOException {
|
||||
DnodeReader reader = new DnodeReader();
|
||||
Dnode ormXml = reader.parseXml(in);
|
||||
in.close();
|
||||
return ormXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the deployment xml for a given entity. This will return null if no
|
||||
* matching deployment xml is found for this entity.
|
||||
* <p>
|
||||
* This searches all the ormXml files and returns the first match.
|
||||
* </p>
|
||||
*/
|
||||
public Dnode findEntityDeploymentXml(String className) {
|
||||
|
||||
for (Dnode ormXml : ormXmlList) {
|
||||
Dnode entityMappings = ormXml.find("entity-mappings");
|
||||
|
||||
List<Dnode> entities = entityMappings.findAll("entity", "class", className, 1);
|
||||
if (entities.size() == 1) {
|
||||
return entities.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Converts logical property names to database columns for the raw sql.
|
||||
* <p>
|
||||
* This is used in building the where and having clauses for SqlSelect queries.
|
||||
* </p>
|
||||
*/
|
||||
public final class DeployPropertyParserRawSql extends DeployParser {
|
||||
|
||||
private final DRawSqlSelect rawSqlSelect;
|
||||
|
||||
public DeployPropertyParserRawSql(DRawSqlSelect rawSqlSelect) {
|
||||
this.rawSqlSelect = rawSqlSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null for raw sql queries.
|
||||
*/
|
||||
public Set<String> getIncludes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String convertWord() {
|
||||
String r = getDeployWord(word);
|
||||
return r == null ? word : r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeployWord(String expression) {
|
||||
DRawSqlColumnInfo columnInfo = rawSqlSelect.getRawSqlColumnInfo(expression);
|
||||
if (columnInfo == null) {
|
||||
return null;
|
||||
} else {
|
||||
return columnInfo.getName();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<!ELEMENT ebean (table | iudextender | findextender | datasource | primarykeys | property)* >
|
||||
<!ELEMENT table EMPTY >
|
||||
<!ATTLIST table name CDATA #REQUIRED>
|
||||
<!ELEMENT iudextender EMPTY >
|
||||
<!ATTLIST iudextender classname CDATA #REQUIRED>
|
||||
<!ELEMENT findextender EMPTY >
|
||||
<!ATTLIST findextender classname CDATA #REQUIRED>
|
||||
<!ELEMENT datasource EMPTY >
|
||||
<!ATTLIST datasource name CDATA #REQUIRED>
|
||||
<!ELEMENT primarykeys EMPTY >
|
||||
<!ATTLIST primarykeys keys CDATA #REQUIRED>
|
||||
<!ELEMENT property EMPTY >
|
||||
<!ATTLIST property name CDATA #REQUIRED
|
||||
datatype CDATA #REQUIRED
|
||||
deploydatatype CDATA #IMPLIED
|
||||
deployname CDATA #IMPLIED >
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.meta;
|
||||
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebeaninternal.api.ConcurrencyMode;
|
||||
import com.avaje.ebean.annotation.DocStore;
|
||||
import com.avaje.ebean.annotation.DocStoreMode;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.TableName;
|
||||
import com.avaje.ebean.config.dbplatform.PlatformIdGenerator;
|
||||
import com.avaje.ebean.config.dbplatform.IdType;
|
||||
import com.avaje.ebean.config.dbplatform.PlatformIdGenerator;
|
||||
import com.avaje.ebean.event.BeanFindController;
|
||||
import com.avaje.ebean.event.BeanPersistController;
|
||||
import com.avaje.ebean.event.BeanPersistListener;
|
||||
@@ -16,6 +15,7 @@ import com.avaje.ebean.event.BeanQueryAdapter;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogFilter;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebean.util.CamelCaseHelper;
|
||||
import com.avaje.ebeaninternal.api.ConcurrencyMode;
|
||||
import com.avaje.ebeaninternal.server.core.CacheOptions;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
@@ -24,9 +24,6 @@ import com.avaje.ebeaninternal.server.deploy.ChainedBeanPersistListener;
|
||||
import com.avaje.ebeaninternal.server.deploy.ChainedBeanPostLoad;
|
||||
import com.avaje.ebeaninternal.server.deploy.ChainedBeanQueryAdapter;
|
||||
import com.avaje.ebeaninternal.server.deploy.CompoundUniqueConstraint;
|
||||
import com.avaje.ebeaninternal.server.deploy.DRawSqlMeta;
|
||||
import com.avaje.ebeaninternal.server.deploy.DeployNamedQuery;
|
||||
import com.avaje.ebeaninternal.server.deploy.DeployNamedUpdate;
|
||||
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
|
||||
import com.avaje.ebeaninternal.server.deploy.parse.DeployBeanInfo;
|
||||
import com.avaje.ebeaninternal.server.idgen.UuidIdGenerator;
|
||||
@@ -40,7 +37,6 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Describes Beans including their deployment information.
|
||||
@@ -72,12 +68,6 @@ public class DeployBeanDescriptor<T> {
|
||||
|
||||
private EntityType entityType;
|
||||
|
||||
private final Map<String, DeployNamedQuery> namedQueries = new LinkedHashMap<String, DeployNamedQuery>();
|
||||
|
||||
private final Map<String, DeployNamedUpdate> namedUpdates = new LinkedHashMap<String, DeployNamedUpdate>();
|
||||
|
||||
private final Map<String, DRawSqlMeta> rawSqlMetas = new LinkedHashMap<String, DRawSqlMeta>();
|
||||
|
||||
private DeployBeanPropertyAssocOne<?> unidirectional;
|
||||
|
||||
/**
|
||||
@@ -309,32 +299,6 @@ public class DeployBeanDescriptor<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<DRawSqlMeta> getRawSqlMeta() {
|
||||
if (!processedRawSqlExtend) {
|
||||
rawSqlProcessExtend();
|
||||
processedRawSqlExtend = true;
|
||||
}
|
||||
return rawSqlMetas.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the "extend" attributes of raw SQL. Aka inherit the query and
|
||||
* column mapping.
|
||||
*/
|
||||
private void rawSqlProcessExtend() {
|
||||
|
||||
for (DRawSqlMeta rawSqlMeta : rawSqlMetas.values()) {
|
||||
String extend = rawSqlMeta.getExtend();
|
||||
if (extend != null) {
|
||||
DRawSqlMeta parentQuery = rawSqlMetas.get(extend);
|
||||
if (parentQuery == null) {
|
||||
throw new RuntimeException("parent query [" + extend + "] not found for sql-select " + rawSqlMeta.getName());
|
||||
}
|
||||
rawSqlMeta.extend(parentQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DeployBeanTable createDeployBeanTable() {
|
||||
|
||||
DeployBeanTable beanTable = new DeployBeanTable(getBeanType());
|
||||
@@ -380,32 +344,6 @@ public class DeployBeanDescriptor<T> {
|
||||
return sequenceAllocationSize;
|
||||
}
|
||||
|
||||
public void add(DRawSqlMeta rawSqlMeta) {
|
||||
rawSqlMetas.put(rawSqlMeta.getName(), rawSqlMeta);
|
||||
if ("default".equals(rawSqlMeta.getName())) {
|
||||
setEntityType(EntityType.SQL);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(DeployNamedUpdate namedUpdate) {
|
||||
namedUpdates.put(namedUpdate.getName(), namedUpdate);
|
||||
}
|
||||
|
||||
public void add(DeployNamedQuery namedQuery) {
|
||||
namedQueries.put(namedQuery.getName(), namedQuery);
|
||||
if ("default".equals(namedQuery.getName())) {
|
||||
setEntityType(EntityType.SQL);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, DeployNamedQuery> getNamedQueries() {
|
||||
return namedQueries;
|
||||
}
|
||||
|
||||
public Map<String, DeployNamedUpdate> getNamedUpdates() {
|
||||
return namedUpdates;
|
||||
}
|
||||
|
||||
public String[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@@ -7,16 +7,12 @@ import com.avaje.ebean.annotation.Draftable;
|
||||
import com.avaje.ebean.annotation.DraftableElement;
|
||||
import com.avaje.ebean.annotation.History;
|
||||
import com.avaje.ebean.annotation.Index;
|
||||
import com.avaje.ebean.annotation.NamedUpdate;
|
||||
import com.avaje.ebean.annotation.NamedUpdates;
|
||||
import com.avaje.ebean.annotation.ReadAudit;
|
||||
import com.avaje.ebean.annotation.UpdateMode;
|
||||
import com.avaje.ebean.annotation.View;
|
||||
import com.avaje.ebean.config.TableName;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
|
||||
import com.avaje.ebeaninternal.server.deploy.CompoundUniqueConstraint;
|
||||
import com.avaje.ebeaninternal.server.deploy.DeployNamedQuery;
|
||||
import com.avaje.ebeaninternal.server.deploy.DeployNamedUpdate;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -25,8 +21,6 @@ import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
@@ -181,53 +175,10 @@ public class AnnotationClass extends AnnotationParser {
|
||||
descriptor.setUpdateChangesOnly(updateMode.updateChangesOnly());
|
||||
}
|
||||
|
||||
NamedQueries namedQueries = cls.getAnnotation(NamedQueries.class);
|
||||
if (namedQueries != null) {
|
||||
readNamedQueries(namedQueries);
|
||||
}
|
||||
NamedQuery namedQuery = cls.getAnnotation(NamedQuery.class);
|
||||
if (namedQuery != null) {
|
||||
readNamedQuery(namedQuery);
|
||||
}
|
||||
|
||||
NamedUpdates namedUpdates = cls.getAnnotation(NamedUpdates.class);
|
||||
if (namedUpdates != null) {
|
||||
readNamedUpdates(namedUpdates);
|
||||
}
|
||||
|
||||
NamedUpdate namedUpdate = cls.getAnnotation(NamedUpdate.class);
|
||||
if (namedUpdate != null) {
|
||||
readNamedUpdate(namedUpdate);
|
||||
}
|
||||
|
||||
Cache cache = cls.getAnnotation(Cache.class);
|
||||
if (cache != null && !disableL2Cache) {
|
||||
descriptor.setCache(cache);
|
||||
}
|
||||
}
|
||||
|
||||
private void readNamedQueries(NamedQueries namedQueries) {
|
||||
NamedQuery[] queries = namedQueries.value();
|
||||
for (int i = 0; i < queries.length; i++) {
|
||||
readNamedQuery(queries[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void readNamedQuery(NamedQuery namedQuery) {
|
||||
DeployNamedQuery q = new DeployNamedQuery(namedQuery);
|
||||
descriptor.add(q);
|
||||
}
|
||||
|
||||
private void readNamedUpdates(NamedUpdates updates) {
|
||||
NamedUpdate[] updateArray = updates.value();
|
||||
for (int i = 0; i < updateArray.length; i++) {
|
||||
readNamedUpdate(updateArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void readNamedUpdate(NamedUpdate update) {
|
||||
DeployNamedUpdate upd = new DeployNamedUpdate(update);
|
||||
descriptor.add(upd);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user