List<Element> columnElements = entityElement.elements("column");
boolean permissionedModel = false;
if (uuid) {
Element columnElement = SAXReaderUtil.createElement("column");
columnElement.addAttribute("name", "uuid");
columnElement.addAttribute("type", "String");
columnElements.add(0, columnElement);
}
for (Element columnElement : columnElements) {
String columnName = columnElement.attributeValue("name");
if (columnName.equals("resourceBlockId") &&
!ejbName.equals("ResourceBlock")) {
permissionedModel = true;
}
String columnDBName = columnElement.attributeValue("db-name");
if (Validator.isNull(columnDBName)) {
columnDBName = columnName;
if (_badColumnNames.contains(columnName)) {
columnDBName += StringPool.UNDERLINE;
}
}
String columnType = columnElement.attributeValue("type");
boolean primary = GetterUtil.getBoolean(
columnElement.attributeValue("primary"));
boolean accessor = GetterUtil.getBoolean(
columnElement.attributeValue("accessor"));
boolean filterPrimary = GetterUtil.getBoolean(
columnElement.attributeValue("filter-primary"));
String collectionEntity = columnElement.attributeValue("entity");
String mappingTable = columnElement.attributeValue("mapping-table");
if (Validator.isNotNull(mappingTable)) {
if (_badTableNames.contains(mappingTable)) {
mappingTable += StringPool.UNDERLINE;
}
if (_autoNamespaceTables) {
mappingTable =
_portletShortName + StringPool.UNDERLINE + mappingTable;
}
}
String idType = columnElement.attributeValue("id-type");
String idParam = columnElement.attributeValue("id-param");
boolean convertNull = GetterUtil.getBoolean(
columnElement.attributeValue("convert-null"), false);
boolean lazy = GetterUtil.getBoolean(
columnElement.attributeValue("lazy"), true);
boolean localized = GetterUtil.getBoolean(
columnElement.attributeValue("localized"));
boolean colJsonEnabled = GetterUtil.getBoolean(
columnElement.attributeValue("json-enabled"), jsonEnabled);
boolean containerModel = GetterUtil.getBoolean(
columnElement.attributeValue("container-model"));
boolean parentContainerModel = GetterUtil.getBoolean(
columnElement.attributeValue("parent-container-model"));
EntityColumn col = new EntityColumn(
columnName, columnDBName, columnType, primary, accessor,
filterPrimary, collectionEntity, mappingTable, idType, idParam,
convertNull, lazy, localized, colJsonEnabled, containerModel,
parentContainerModel);
if (primary) {
pkList.add(col);
}
if (columnType.equals("Collection")) {
collectionList.add(col);
}
else {
regularColList.add(col);
if (columnType.equals("Blob")) {
blobList.add(col);
}
}
columnList.add(col);
if (Validator.isNotNull(collectionEntity) &&
Validator.isNotNull(mappingTable)) {
EntityMapping entityMapping = new EntityMapping(
mappingTable, ejbName, collectionEntity);
int ejbNameWeight = StringUtil.startsWithWeight(
mappingTable, ejbName);
int collectionEntityWeight = StringUtil.startsWithWeight(
mappingTable, collectionEntity);
if ((ejbNameWeight > collectionEntityWeight) ||
((ejbNameWeight == collectionEntityWeight) &&
(ejbName.compareTo(collectionEntity) > 0))) {
_entityMappings.put(mappingTable, entityMapping);
}
}
}
EntityOrder order = null;
Element orderElement = entityElement.element("order");
if (orderElement != null) {
boolean asc = true;
if ((orderElement.attribute("by") != null) &&
orderElement.attributeValue("by").equals("desc")) {
asc = false;
}
List<EntityColumn> orderColsList = new ArrayList<EntityColumn>();
order = new EntityOrder(asc, orderColsList);
List<Element> orderColumnElements = orderElement.elements(
"order-column");
for (Element orderColElement : orderColumnElements) {
String orderColName = orderColElement.attributeValue("name");
boolean orderColCaseSensitive = GetterUtil.getBoolean(
orderColElement.attributeValue("case-sensitive"), true);
boolean orderColByAscending = asc;
String orderColBy = GetterUtil.getString(
orderColElement.attributeValue("order-by"));
if (orderColBy.equals("asc")) {
orderColByAscending = true;
}
else if (orderColBy.equals("desc")) {
orderColByAscending = false;
}
EntityColumn col = Entity.getColumn(orderColName, columnList);
col.setOrderColumn(true);
col = (EntityColumn)col.clone();
col.setCaseSensitive(orderColCaseSensitive);
col.setOrderByAscending(orderColByAscending);
orderColsList.add(col);
}
}
List<EntityFinder> finderList = new ArrayList<EntityFinder>();
List<Element> finderElements = entityElement.elements("finder");
if (uuid) {
if (columnList.contains(new EntityColumn("companyId"))) {
Element finderElement = SAXReaderUtil.createElement("finder");
finderElement.addAttribute("name", "Uuid_C");
finderElement.addAttribute("return-type", "Collection");
Element finderColumnElement = finderElement.addElement(
"finder-column");
finderColumnElement.addAttribute("name", "uuid");
finderColumnElement = finderElement.addElement("finder-column");
finderColumnElement.addAttribute("name", "companyId");
finderElements.add(0, finderElement);
}
if (columnList.contains(new EntityColumn("groupId"))) {
Element finderElement = SAXReaderUtil.createElement("finder");
if (ejbName.equals("Layout")) {
finderElement.addAttribute("name", "UUID_G_P");
}
else {
finderElement.addAttribute("name", "UUID_G");
}
finderElement.addAttribute("return-type", ejbName);
finderElement.addAttribute("unique", "true");
Element finderColumnElement = finderElement.addElement(
"finder-column");
finderColumnElement.addAttribute("name", "uuid");
finderColumnElement = finderElement.addElement("finder-column");
finderColumnElement.addAttribute("name", "groupId");
if (ejbName.equals("Layout")) {
finderColumnElement = finderElement.addElement(
"finder-column");
finderColumnElement.addAttribute("name", "privateLayout");
}
finderElements.add(0, finderElement);
}
Element finderElement = SAXReaderUtil.createElement("finder");
finderElement.addAttribute("name", "Uuid");
finderElement.addAttribute("return-type", "Collection");
Element finderColumnElement = finderElement.addElement(
"finder-column");
finderColumnElement.addAttribute("name", "uuid");
finderElements.add(0, finderElement);
}
if (permissionedModel) {
Element finderElement = SAXReaderUtil.createElement("finder");
finderElement.addAttribute("name", "ResourceBlockId");
finderElement.addAttribute("return-type", "Collection");
Element finderColumnElement = finderElement.addElement(
"finder-column");
finderColumnElement.addAttribute("name", "resourceBlockId");
finderElements.add(0, finderElement);
}
String alias = TextFormatter.format(ejbName, TextFormatter.I);
if (_badAliasNames.contains(StringUtil.toLowerCase(alias))) {
alias += StringPool.UNDERLINE;
}
for (Element finderElement : finderElements) {
String finderName = finderElement.attributeValue("name");
String finderReturn = finderElement.attributeValue("return-type");
boolean finderUnique = GetterUtil.getBoolean(
finderElement.attributeValue("unique"));
String finderWhere = finderElement.attributeValue("where");
if (Validator.isNotNull(finderWhere)) {
for (EntityColumn column : columnList) {
String name = column.getName();
if (finderWhere.contains(name)) {
finderWhere = finderWhere.replaceAll(
name, alias + "." + name);
}
}
}
boolean finderDBIndex = GetterUtil.getBoolean(
finderElement.attributeValue("db-index"), true);
List<EntityColumn> finderColsList = new ArrayList<EntityColumn>();
List<Element> finderColumnElements = finderElement.elements(
"finder-column");
for (Element finderColumnElement : finderColumnElements) {
String finderColName = finderColumnElement.attributeValue(
"name");
boolean finderColCaseSensitive = GetterUtil.getBoolean(
finderColumnElement.attributeValue("case-sensitive"), true);
String finderColComparator = GetterUtil.getString(
finderColumnElement.attributeValue("comparator"), "=");
String finderColArrayableOperator =
GetterUtil.getString(
finderColumnElement.attributeValue(
"arrayable-operator"));
EntityColumn col = Entity.getColumn(finderColName, columnList);
if (!col.isFinderPath()) {