Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

LPS-18440 Source formatting

  • Loading branch information...
commit 1d3e0ed92c3ff9ee29af41ecb41c6d24db92751f 1 parent e2530cd
@brianchandotcom brianchandotcom authored
View
2  definitions/liferay-service-builder_6_0_0.dtd
@@ -280,7 +280,7 @@ the type value is String. This is particularly useful if your entity is
referencing a read only table or a database view so that Hibernate does not try
to issue unnecessary updates. The default value is true.
-The lazy value is only valid when type is Blob. It specifies whether or not to
+The lazy value is only valid when type is Blob. It specifies whether or not to
do a lazy fetch for Blob. The default value is true.
The localized value specifies whether or not the value of the column can have
View
2  definitions/liferay-service-builder_6_1_0.dtd
@@ -280,7 +280,7 @@ the type value is String. This is particularly useful if your entity is
referencing a read only table or a database view so that Hibernate does not try
to issue unnecessary updates. The default value is true.
-The lazy value is only valid when type is Blob. It specifies whether or not to
+The lazy value is only valid when type is Blob. It specifies whether or not to
do a lazy fetch for Blob. The default value is true.
The localized value specifies whether or not the value of the column can have
View
2  portal-impl/src/META-INF/portal-hbm.xml
@@ -1336,7 +1336,7 @@
<property name="repositoryId" type="com.liferay.portal.dao.orm.hibernate.LongType" />
<property name="path" type="com.liferay.portal.dao.orm.hibernate.StringType" column="path_" />
<property name="version" type="com.liferay.portal.dao.orm.hibernate.StringType" />
- <one-to-one name="dataBlobModel" class="com.liferay.portlet.documentlibrary.model.DLContentDataBlobModel" constrained="true" outer-join="false" cascade="save-update" />
+ <one-to-one name="dataBlobModel" class="com.liferay.portlet.documentlibrary.model.DLContentDataBlobModel" cascade="save-update" outer-join="false" constrained="true" />
<property name="size" type="com.liferay.portal.dao.orm.hibernate.LongType" column="size_" />
</class>
<class name="com.liferay.portlet.documentlibrary.model.DLContentDataBlobModel" table="DLContent" lazy="true">
View
25 portal-impl/src/com/liferay/portal/tools/servicebuilder/Entity.java
@@ -109,9 +109,10 @@ public Entity(
_txRequiredList = txRequiredList;
if ((_blobList != null) && !_blobList.isEmpty()) {
- for (EntityColumn entityColumn : _blobList) {
- if (!entityColumn.isLazy()) {
+ for (EntityColumn col : _blobList) {
+ if (!col.isLazy()) {
_cacheEnabled = false;
+
break;
}
}
@@ -390,13 +391,13 @@ public int hashCode() {
return _name.hashCode();
}
- public boolean hasLazyBlob() {
+ public boolean hasLazyBlobColumn() {
if ((_blobList == null) || _blobList.isEmpty()) {
return false;
}
- for (EntityColumn entityColumn : _blobList) {
- if (entityColumn.isLazy()) {
+ for (EntityColumn col : _blobList) {
+ if (col.isLazy()) {
return true;
}
}
@@ -418,20 +419,6 @@ public boolean hasLocalService() {
return _localService;
}
- public boolean hasNonLazyBlob() {
- if ((_blobList == null) || _blobList.isEmpty()) {
- return false;
- }
-
- for (EntityColumn entityColumn : _blobList) {
- if (!entityColumn.isLazy()) {
- return true;
- }
- }
-
- return false;
- }
-
public boolean hasPrimitivePK() {
return hasPrimitivePK(true);
}
View
88 portal-impl/src/com/liferay/portal/tools/servicebuilder/ServiceBuilder.java
@@ -178,6 +178,7 @@ public static void main(String[] args) {
"\t-Dservice.tpl.bad_json_types=" + _TPL_ROOT + "bad_json_types.txt\n"+
"\t-Dservice.tpl.bad_table_names=" + _TPL_ROOT + "bad_table_names.txt\n"+
"\t-Dservice.tpl.base_mode_impl=" + _TPL_ROOT + "base_mode_impl.ftl\n"+
+ "\t-Dservice.tpl.blob_model=" + _TPL_ROOT + "blob_model.ftl\n"+
"\t-Dservice.tpl.copyright.txt=copyright.txt\n"+
"\t-Dservice.tpl.ejb_pk=" + _TPL_ROOT + "ejb_pk.ftl\n"+
"\t-Dservice.tpl.exception=" + _TPL_ROOT + "exception.ftl\n"+
@@ -437,6 +438,7 @@ public ServiceBuilder(
_tplBadJsonTypes = _getTplProperty("bad_json_types", _tplBadJsonTypes);
_tplBadTableNames = _getTplProperty(
"bad_table_names", _tplBadTableNames);
+ _tplBlobModel = _getTplProperty("blob_model", _tplBlobModel);
_tplEjbPk = _getTplProperty("ejb_pk", _tplEjbPk);
_tplException = _getTplProperty("exception", _tplException);
_tplExtendedModel = _getTplProperty(
@@ -645,7 +647,6 @@ public ServiceBuilder(
_getTransients(entity, true));
_createModel(entity);
- _createModelBlobs(entity);
_createExtendedModel(entity);
_createModelClp(entity);
@@ -653,6 +654,8 @@ public ServiceBuilder(
_createModelSoap(entity);
+ _createBlobModels(entity);
+
_createPool(entity);
if (entity.getPKList().size() > 1) {
@@ -1524,6 +1527,45 @@ private void _addElements(
}
}
+ private void _createBlobModels(Entity entity) throws Exception {
+ List<EntityColumn> blobList = new ArrayList<EntityColumn>(
+ entity.getBlobList());
+
+ Iterator<EntityColumn> itr = blobList.iterator();
+
+ while (itr.hasNext()) {
+ EntityColumn col = itr.next();
+
+ if (!col.isLazy()) {
+ itr.remove();
+ }
+ }
+
+ if (blobList.isEmpty()) {
+ return;
+ }
+
+ Map<String, Object> context = _getContext();
+
+ context.put("entity", entity);
+
+ for (EntityColumn col : blobList) {
+ context.put("column", col);
+
+ // Content
+
+ String content = _processTemplate(_tplBlobModel, context);
+
+ // Write file
+
+ File blobModelFile = new File(
+ _serviceOutputPath + "/model/" + entity.getName() +
+ col.getMethodName() + "BlobModel.java");
+
+ writeFile(blobModelFile, content, _author);
+ }
+ }
+
private void _createEJBPK(Entity entity) throws Exception {
Map<String, Object> context = _getContext();
@@ -1986,44 +2028,6 @@ private void _createModel(Entity entity) throws Exception {
}
}
- private void _createModelBlobs(Entity entity) throws Exception {
- List<EntityColumn> blobList = entity.getBlobList();
- Iterator<EntityColumn> blobIterator = blobList.iterator();
-
- while (blobIterator.hasNext()) {
- EntityColumn entityColumn = blobIterator.next();
- if (!entityColumn.isLazy()) {
- blobIterator.remove();
- }
- }
-
- if (blobList.isEmpty()) {
- return;
- }
-
- Map<String, Object> context = _getContext();
-
- context.put("entity", entity);
-
- for (EntityColumn entityColumn : blobList) {
- context.put("column", entityColumn);
-
- String columnName = entityColumn.getName();
-
- // Content
-
- String content = _processTemplate(_tplBlobModel, context);
-
- // Write file
-
- File modelBlobFile = new File(
- _serviceOutputPath + "/model/" + entity.getName() +
- entityColumn.getMethodName() + "BlobModel.java");
-
- writeFile(modelBlobFile, content, _author);
- }
- }
-
private void _createModelClp(Entity entity) throws Exception {
if (Validator.isNull(_pluginName)) {
return;
@@ -4380,11 +4384,11 @@ private void _parseEntity(Element entityElement) throws Exception {
collectionList.add(col);
}
else {
+ regularColList.add(col);
+
if (columnType.equals("Blob")) {
blobList.add(col);
}
-
- regularColList.add(col);
}
columnList.add(col);
@@ -4710,6 +4714,7 @@ private String _processTemplate(String name, Map<String, Object> context)
private String _tplBadColumnNames = _TPL_ROOT + "bad_column_names.txt";
private String _tplBadJsonTypes = _TPL_ROOT + "bad_json_types.txt";
private String _tplBadTableNames = _TPL_ROOT + "bad_table_names.txt";
+ private String _tplBlobModel = _TPL_ROOT + "blob_model.ftl";
private String _tplEjbPk = _TPL_ROOT + "ejb_pk.ftl";
private String _tplException = _TPL_ROOT + "exception.ftl";
private String _tplExtendedModel = _TPL_ROOT + "extended_model.ftl";
@@ -4718,7 +4723,6 @@ private String _processTemplate(String name, Map<String, Object> context)
private String _tplFinder = _TPL_ROOT + "finder.ftl";
private String _tplFinderUtil = _TPL_ROOT + "finder_util.ftl";
private String _tplHbmXml = _TPL_ROOT + "hbm_xml.ftl";
- private String _tplBlobModel = _TPL_ROOT + "blob_model.ftl";
private String _tplJsonJs = _TPL_ROOT + "json_js.ftl";
private String _tplJsonJsMethod = _TPL_ROOT + "json_js_method.ftl";
private String _tplModel = _TPL_ROOT + "model.ftl";
View
5 portal-impl/src/com/liferay/portal/tools/servicebuilder/dependencies/blob_model.ftl
@@ -3,7 +3,7 @@ package ${packagePath}.model;
import java.sql.Blob;
/**
- * The Blob model class for lazy loading the ${entity.name}.${column.name}.
+ * The Blob model class for lazy loading the ${column.name} column in ${entity.name}.
*
* @author ${author}
* @see ${entity.name}
@@ -18,11 +18,13 @@ public class ${entity.name}${column.methodName}BlobModel {
public ${entity.name}${column.methodName}BlobModel(
${pkColumn.type} ${pkColumn.name}) {
+
_${pkColumn.name} = ${pkColumn.name};
}
public ${entity.name}${column.methodName}BlobModel(
${pkColumn.type} ${pkColumn.name}, Blob ${column.name}Blob) {
+
_${pkColumn.name} = ${pkColumn.name};
_${column.name}Blob = ${column.name}Blob;
}
@@ -46,7 +48,6 @@ public class ${entity.name}${column.methodName}BlobModel {
<#if entity.hasCompoundPK()>
private ${entity.PKClassName} _${entity.PKVarName};
<#else>
- <#assign pkColumn = entity.getPKList()?first>
private ${pkColumn.type} _${pkColumn.name};
</#if>
View
5 portal-impl/src/com/liferay/portal/tools/servicebuilder/dependencies/hbm_xml.ftl
@@ -103,10 +103,11 @@
</#if>
<#if (column.type == "Blob") && column.lazy>
- <one-to-one name="${column.name}BlobModel" class="${packagePath}.model.${entity.name}${column.methodName}BlobModel" constrained="true" outer-join="false" cascade="save-update" />
+ <one-to-one name="${column.name}BlobModel" class="${packagePath}.model.${entity.name}${column.methodName}BlobModel" cascade="save-update" outer-join="false" constrained="true" />
</#if>
</#list>
</class>
+
<#list entity.blobList as blobColumn>
<#if blobColumn.lazy>
<class name="${packagePath}.model.${entity.name}${blobColumn.methodName}BlobModel" table="${entity.table}" lazy="true">
@@ -117,7 +118,7 @@
<param name="property">${packagePath}.model.impl.${entity.name}Impl</param>
</generator>
</id>
- <property column="${blobColumn.DBName}" name="${blobColumn.name}Blob" type="org.hibernate.type.BlobType"/>
+ <property column="${blobColumn.DBName}" name="${blobColumn.name}Blob" type="org.hibernate.type.BlobType" />
</class>
</#if>
</#list>
View
31 portal-impl/src/com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl
@@ -152,7 +152,11 @@ public class ${entity.name}ModelImpl extends BaseModelImpl<${entity.name}> imple
public static final String TX_MANAGER = "${entity.getTXManager()}";
- <#if !entity.hasNonLazyBlob()>
+ <#if entity.hasLazyBlobColumn()>
+ public static final boolean ENTITY_CACHE_ENABLED = false;
+
+ public static final boolean FINDER_CACHE_ENABLED = false;
+ <#else>
public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(${propsUtil}.get("value.object.entity.cache.enabled.${packagePath}.model.${entity.name}"),
<#if entity.isCacheEnabled()>
@@ -172,10 +176,6 @@ public class ${entity.name}ModelImpl extends BaseModelImpl<${entity.name}> imple
</#if>
);
- <#else>
- public static final boolean ENTITY_CACHE_ENABLED = false;
-
- public static final boolean FINDER_CACHE_ENABLED = false;
</#if>
<#if entity.hasRemoteService()>
@@ -364,11 +364,13 @@ public class ${entity.name}ModelImpl extends BaseModelImpl<${entity.name}> imple
<#if (column.type == "Blob") && column.lazy>
if (_${column.name}BlobModel == null) {
try {
- _${column.name}BlobModel = (${entity.name}${column.methodName}BlobModel)${entity.name}LocalServiceUtil.fetchEntity(${entity.name}${column.methodName}BlobModel.class, getPrimaryKey());
+ _${column.name}BlobModel = ${entity.name}LocalServiceUtil.get${column.methodName}BlobModel(getPrimaryKey());
- return _${column.name}BlobModel.get${column.methodName}Blob();
+ if (_${column.name}BlobModel != null) {
+ return _${column.name}BlobModel.get${column.methodName}Blob();
+ }
}
- catch(SystemException se) {
+ catch (Exception e) {
}
}
@@ -754,6 +756,7 @@ public class ${entity.name}ModelImpl extends BaseModelImpl<${entity.name}> imple
${entity.varName}ModelImpl._setOriginal${column.methodName} = false;
</#if>
</#if>
+
<#if (column.type == "Blob") && column.lazy>
_${column.name}BlobModel = null;
</#if>
@@ -799,18 +802,6 @@ public class ${entity.name}ModelImpl extends BaseModelImpl<${entity.name}> imple
return sb.toString();
}
- <#list entity.blobList as column>
- <#if column.lazy>
- private ${entity.name}${column.methodName}BlobModel get${column.methodName}BlobModel() {
- return _${column.name}BlobModel;
- }
-
- private void set${column.methodName}BlobModel(${entity.name}${column.methodName}BlobModel ${column.name}BlobModel) {
- _${column.name}BlobModel = ${column.name}BlobModel;
- }
- </#if>
- </#list>
-
private static ClassLoader _classLoader = ${entity.name}.class.getClassLoader();
private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {${entity.name}.class};
View
43 portal-impl/src/com/liferay/portal/tools/servicebuilder/dependencies/service_base_impl.ftl
@@ -6,6 +6,7 @@ import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
import ${beanLocatorUtil};
import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
+import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
@@ -28,6 +29,13 @@ import javax.sql.DataSource;
</#if>
import ${packagePath}.model.${entity.name};
+
+ <#list entity.blobList as column>
+ <#if column.lazy>
+ import ${packagePath}.model.${entity.name}${column.methodName}BlobModel;
+ </#if>
+ </#list>
+
import ${packagePath}.model.impl.${entity.name}Impl;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
@@ -99,22 +107,25 @@ import javax.sql.DataSource;
*/
</#if>
- <#if entity.hasLazyBlob()>
- /**
- * Returns the model instance with the primary key or returns
- * <code>null</code> if it could not be found.
- *
- * @param primaryKey the primary key of the model instance
- * @return the model instance, or <code>null</code> if an instance of this
- * model with the primary key could not be found
- * @throws SystemException if the primary key is <code>null</code>, or if a
- * system exception occurred
- */
- public Object fetchEntity(Class<?> entityClass, Serializable primaryKey)
- throws SystemException {
- return ${entity.varName}Persistence.fetchEntity(entityClass, primaryKey);
- }
- </#if>
+ <#list entity.blobList as column>
+ <#if column.lazy>
+ public ${entity.name}${column.methodName}BlobModel get${column.methodName}BlobModel(Serializable primaryKey) throws SystemException {
+ Session session = null;
+
+ try {
+ session = ${entity.varName}Persistence.openSession();
+
+ return (${packagePath}.model.${entity.name}${column.methodName}BlobModel)session.get(${entity.name}${column.methodName}BlobModel.class, primaryKey);
+ }
+ catch (Exception e) {
+ throw ${entity.varName}Persistence.processException(e);
+ }
+ finally {
+ ${entity.varName}Persistence.closeSession(session);
+ }
+ }
+ </#if>
+ </#list>
<#if sessionTypeName == "Local" && entity.hasColumns()>
<#assign serviceBaseExceptions = serviceBuilder.getServiceBaseExceptions(methods, "add" + entity.name, [packagePath + ".model." + entity.name], ["SystemException"])>
View
22 portal-service/src/com/liferay/portal/service/persistence/BasePersistence.java
@@ -16,6 +16,8 @@
import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
+import com.liferay.portal.kernel.dao.orm.ORMException;
+import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.model.BaseModel;
@@ -66,6 +68,8 @@
*/
public void clearCache(T model);
+ public void closeSession(Session session);
+
/**
* Returns the number of rows that match the dynamic query.
*
@@ -89,20 +93,6 @@ public long countWithDynamicQuery(DynamicQuery dynamicQuery)
public T fetchByPrimaryKey(Serializable primaryKey) throws SystemException;
/**
- * Returns the model instance with the primary key for the given Entity
- * class or returns <code>null</code> if it could not be found.
- *
- * @param entityClass the class of the model instance
- * @param primaryKey the primary key of the model instance
- * @return the model instance, or <code>null</code> if an instance of this
- * model with the primary key could not be found
- * @throws SystemException if the primary key is <code>null</code>, or if a
- * system exception occurred
- */
- public <T> T fetchEntity(Class<T> entityClass, Serializable primaryKey)
- throws SystemException;
-
- /**
* Returns the model instance with the primary key or throws a {@link
* NoSuchModelException} if it could not be found.
*
@@ -199,6 +189,10 @@ public List findWithDynamicQuery(
*/
public ModelListener<T>[] getListeners();
+ public Session openSession() throws ORMException;
+
+ public SystemException processException(Exception e);
+
/**
* Registers a new listener for this model.
*
View
17 portal-service/src/com/liferay/portal/service/persistence/impl/BasePersistenceImpl.java
@@ -92,23 +92,6 @@ public T fetchByPrimaryKey(Serializable primaryKey) throws SystemException {
throw new UnsupportedOperationException();
}
- public <T> T fetchEntity(Class<T> entityClass, Serializable primaryKey)
- throws SystemException {
- Session session = null;
-
- try {
- session = openSession();
-
- return (T)session.get(entityClass, primaryKey);
- }
- catch (Exception e) {
- throw processException(e);
- }
- finally {
- closeSession(session);
- }
- }
-
@SuppressWarnings("unused")
public T findByPrimaryKey(Serializable primaryKey)
throws NoSuchModelException, SystemException {
Please sign in to comment.
Something went wrong with that request. Please try again.