Liferay6.1中service的定义规则文件

来源:互联网 发布:卸载linux自带jdk 编辑:程序博客网 时间:2024/05/17 09:36

在写liferay中service builder工具的定义文件的时候,都有那些功能呢,该怎么写xml配置文件呢?比如和另外的表关联等。

这个看看dtd文件就大致明白了。

<!--<!DOCTYPE service-builder PUBLIC    "-//Liferay//DTD Service Builder 6.1.0//EN"    "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">--><!--The service-builder element is the root of the deployment descriptor fora Service Builder descriptor that is used to generate services available toportlets. The Service Builder saves the developer time by generating Springutilities, SOAP utilities, and Hibernate persistence classes to ease thedevelopment of services.--><!ELEMENT service-builder (author?, namespace?, entity*, exceptions?,service-builder-import*)><!--The package-path value specifies the package of the generated code.The auto-namespace-tables value specifies whether or not to automaticallynamespace tables. The default value is false for core services and true forplugin services.--><!ATTLIST service-builder    package-path CDATA #IMPLIED    auto-namespace-tables CDATA #IMPLIED><!--The author element is the name of the user associated with the generated code.--><!ELEMENT author (#PCDATA)><!--The namespace element must be a unique namespace for this component. Table nameswill be prepended with this namespace. Generated JSON JavaScript will be scopedto this namespace as well (i.e., Liferay.Service.Test.* if the namespace isTest).--><!ELEMENT namespace (#PCDATA)><!--An entity usually represents a business facade and a table in the database. Ifan entity does not have any columns, then it only represents a business facade.The Service Builder will always generate an empty business facade POJO if itdoes not exist. Upon subsequent generations, the Service Builder will check tosee if the business facade already exists. If it exists and has additionalmethods, then the Service Builder will also update the SOAP wrappers.If an entity does have columns, then the value object, the POJO class thatis mapped to the database, and other persistence utilities are also generatedbased on the order and finder elements.--><!ELEMENT entity (column*, order?, finder*, reference*, tx-required*)><!--The name value specifies the name of the entity.The human-name value specifies the readable name to use when generatingdocumentation for this entity. If none is specified, one will be generated fromthe name.The table value specifies the name of the table that this entity maps to in thedatabase. If this value is not set, then the name of the table is the same asthe name of the entity.If the uuid value is true, then the service will generate a UUID column for theservice. This column will automatically be populated with a UUID. Developerswill also be able to find and remove based on that UUID. The default value isfalse.If the uuid-accessor value is true, then the service will generate a UUID columnaccessor for the service. This accessor will provide a fast and type-safe way toaccess entity's UUID.If the local-service value is true, then the service will generate the localinterfaces for the service. The default value is false.If the remote-service value is true, then the service will generate remoteinterfaces for the service. The default value is true.The persistence-class value specifies the name of your custom persistence class.This class must implement the generated persistence interface or extend thegenerated persistence class. This allows you to override default behaviorwithout modifying the generated persistence class.You can generate classes to use a custom data source and session factory.Point "spring.configs" in portal.properties to load your custom Spring XML withthe definitions of your custom data source and session factory. Then set thedata-source and session-factory values to your custom values.The data-source value specifies the data source target that is set to thepersistence class. The default value is the Liferay data source. This is used inconjunction with session-factory. See data-source-spring.xml.The session-factory value specifies the session factory that is set to thepersistence class. The default value is the Liferay session factory. This isused in conjunction with data-source. See data-source-spring.xml.The tx-manager value specifies the transaction manager that Spring uses. Thedefault value is the Spring Hibernate transaction manager that wraps the Liferaydata source and session factory. See data-source-spring.xml. Set this attributeto "none" to disable transaction management.The cache-enabled value specifies whether or not to cache this queries for thisentity. Set this to false if data in the table will be updated by otherprograms. The default value is true.The json-enabled value specifies whether or not the entity should be annotatedfor JSON serialization. By default, if the remote-service value is true, thenthe json-enabled value is true.--><!ATTLIST entity    name CDATA #REQUIRED    human-name CDATA #IMPLIED    table CDATA #IMPLIED    uuid CDATA #IMPLIED    uuid-accessor CDATA #IMPLIED    local-service CDATA #IMPLIED    remote-service CDATA #IMPLIED    persistence-class CDATA #IMPLIED    data-source CDATA #IMPLIED    session-factory CDATA #IMPLIED    tx-manager CDATA #IMPLIED    cache-enabled CDATA #IMPLIED    json-enabled CDATA #IMPLIED><!--The column element represents a column in the database.--><!ELEMENT column (#PCDATA)><!--The name value specifies the getter and setter name in the entity.The type value specifies whether the column is a String, Boolean, or int, etc.For example:<column name="companyId" db-name="companyId" type="String" />The above column specifies that there will be a getter calledpojo.getCompanyId() that will return a String.Set db-name to map the field to a physical database column that is differentfrom the column name.If the primary value is set to true, then this column is part of the primary keyof the entity. If multiple columns have the primary value set to true, then acompound key will be created.See com.liferay.portal.service.persistence.LayoutPK for an example of a compoundprimary key.If the entity and mapping-key attributes are specified and mapping-table is not,then the Service Builder will assume you are specifying a one to manyrelationship.For example:<column    name="shoppingItemPrices"    type="Collection"    entity="ShoppingItemPrice"    mapping-key="itemId"/>The above column specifies that there will be a getter calledpojo.getShoppingItemPrices() that will return a collection. It will map to acolumn called itemId in the table that maps to the entity ShoppingItemPrice.If the entity and mapping-table attributes are specified and mapping-key is not,then the Service Builder will assume you are specifying a many to manyrelationship.For example:<column    name="roles"    type="Collection"    entity="Role"    mapping-table="Groups_Roles"/>The above column specifies that there will be a getter calledpojo.getRoles() that will return a collection. It will use a mapping tablecalled Groups_Roles to give a many to many relationship between groups androles.If you are creating a mapping table for an entity defined in anotherservice.xml, you need to specify the full package path.For example:<column    name="organizations"    type="Collection"    entity="com.liferay.portal.Organization"    mapping-table="Foo_Organizations"/>The id-type and id-param values are used in order to create an auto-generated,auto-incrementing primary key when inserting records into a table. This can beimplemented in 4 different ways, depending on the type of database being used.In all cases, the primary key of the model object should be assigned a value ofnull, and Hibernate will know to replace the null value with an auto-generated,auto-incremented value. If no id-type value is used, it is assumed that theprimary key will be assigned and not auto-generated.The first implementation uses a class to generate a primary key.For example:<column    name="id"    type="Integer"    primary="true"    id-type="class"    id-param="com.liferay.counter.service.persistence.IDGenerator"/>In this implementation, the class specified in the id-param value will be calledto retrieve a unique identifier (in the example above, an Integer) that will beused as the primary key for the new record. This implementation works for allsupported databases.The second implementation generates identifiers that are unique only when noother process is inserting data into the same table. This implementation shouldNOT be used in a clustered environment, but it does work for all supporteddatabases.For example:<column    name="id"    type="Integer"    primary="true"    id-type="increment"/>The third implementation uses an identity column to generate a primary key.For example:<column    name="id"    type="Integer"    primary="true"    id-type="identity"/>In this implementation, the create table SQL generated for this entity willcreate an identity column that natively auto-generates a primary key wheneveran insert occurs. This implementation is only supported by DB2, MySQL, andMS SQL Server.The fourth implementation uses a sequence to generate a primary key.For example:<column    name="id"    type="Integer"    primary="true"    id-type="sequence"    id-param="id_sequence"/>In this implementation, a create sequence SQL statement is created based onthe id-param value (stored in /sql/sequences.sql). This sequence is thenaccessed to generate a unique identifier whenever an insert occurs. Thisimplementation is only supported by DB2, Oracle, PostgreSQL, and SAP DB.This accessor value specifies whether or not to generate an accessor for thiscolumn. This accessor will provide a fast and type-safe way to access column value.The filter-primary value specifies the column to use as the primary key columnwhen using filter finders. Only one column should ever have this value set totrue. If no column has this set to true, then the default primary column beused.The convert-null value specifies whether or not the column value isautomatically converted to a non null value if it is null. This only applies ifthe type value is String. This is particularly useful if your entity isreferencing a read only table or a database view so that Hibernate does not tryto issue unnecessary updates. The default value is true.The lazy value is only valid when type is Blob. It specifies whether or not todo a lazy fetch for Blob. The default value is true.The localized value specifies whether or not the value of the column can havedifferent values for different locales. The default value is false.The json-enabled value specifies whether or not the column should be annotatedfor JSON serialization. By default, if the json-enabled value in the entityelement is true, then the json-enabled value in the column element is true.--><!ATTLIST column    name CDATA #REQUIRED    db-name CDATA #IMPLIED    type CDATA #REQUIRED    primary CDATA #IMPLIED    accessor CDATA #IMPLIED    filter-primary CDATA #IMPLIED    entity CDATA #IMPLIED    mapping-key CDATA #IMPLIED    mapping-table CDATA #IMPLIED    id-type CDATA #IMPLIED    id-param CDATA #IMPLIED    convert-null CDATA #IMPLIED    lazy CDATA #IMPLIED    localized CDATA #IMPLIED    json-enabled CDATA #IMPLIED><!--The order element specifies a default ordering and sorting of the entities whenthey are retrieved from the database.--><!ELEMENT order (order-column+)><!--Set the by attribute to "asc" or "desc" to order by ascending or descending.--><!ATTLIST order    by CDATA #IMPLIED><!--The order-column element allows you to order the entities by specific columns.--><!ELEMENT order-column (#PCDATA)><!--The attributes of the order-column element allows you to fine tune the orderingof the entity.For example:<order by="asc">    <order-column name="parentLayoutId" />    <order-column name="priority" /></order>The above settings will order by parentLayoutId and then by priority in anascending manner.For example:<order by="asc">    <order-column name="name" case-sensitive="false" /></order>The above settings will order by name and will not be case sensitive.For example:<order>    <order-column name="articleId" order-by="asc" />    <order-column name="version" order-by="desc" /></order>The above settings will order by articleId in an ascending manner and then byversion in a descending manner.--><!ATTLIST order-column    name CDATA #REQUIRED    case-sensitive CDATA #IMPLIED    order-by CDATA #IMPLIED><!--The finder element represents a generated finder method.--><!ELEMENT finder (finder-column+)><!--The name value specifies the name of the finder method.The return-type value specifies the return type of the finder. Valid values are"Collection" or the name of the entity. If the value is "Collection", then thisfinder returns a list of entities. If the value is the name of the entity, thenthis finder returns at most one entity.If the unique value is true, then the finder must return a unique entity.If the db-index value is true, then the service will automatically generate aSQL index for this finder. The default value is true.--><!ATTLIST finder    name CDATA #REQUIRED    return-type CDATA #REQUIRED    unique CDATA #IMPLIED    where CDATA #IMPLIED    db-index CDATA #IMPLIED><!--The finder-column element specifies the columns to find by.--><!ELEMENT finder-column (#PCDATA)><!--The name value specifies the name of the finder method.For example:<finder name="CompanyId" return-type="Collection">    <finder-column name="companyId" /></finder>The above settings will create a finder with the name findByCompanyId that willreturn a Collection and require a given companyId. It will also generateseveral more findByCompanyId methods that take in pagination fields (int begin,int end) and more sorting options. The easiest way to understand this is tolook at a generated PersistenceImpl class. The Service Builder will alsogenerate removeByCompanyId and countByCompanyId.See com.liferay.portal.service.persistence.LayoutPersistenceImpl for a goodexample.The attribute case-sensitive is a boolean value and is only used if the columnis a String value.The attribute comparator takes in the values =, !=, <, <=, >, >=, or LIKE and isused to compare this column.The attribute arrayable-operator takes in the values AND or OR and willgenerate an additional finder where this column's parameter takes an arrayinstead of a single value. Every value in this array will be compared with thecolumn using the comparator, and the conditions will be combined with either anAND or OR operator. For example, a finder column with the = comparator and anarrayable-operator of OR will act like an IN clause.--><!ATTLIST finder-column    name CDATA #REQUIRED    case-sensitive CDATA #IMPLIED    comparator CDATA #IMPLIED    arrayable-operator CDATA #IMPLIED><!--The reference element allows you to inject services from another service.xmlwithin the same class loader. For example, if you inject the Resource entity,then you'll be able to reference the Resource services from your serviceimplementation via the methods getResourceLocalService and getResourceService.You'll also be able to reference the Resource services via the variablesresourceLocalService and resourceService.--><!ELEMENT reference (#PCDATA)><!--See the comments in reference element.--><!ATTLIST reference    package-path CDATA #IMPLIED    entity CDATA #IMPLIED><!--The tx-required element has a text value that will be used to match method namesthat require transactions. By default, the methods: add*, check*, clear*,delete*, set*, and update* require propagation of transactions. All othermethods support transactions but are assumed to be read only. If you wantadditional methods to fall under transactions, add the method name to thiselement.--><!ELEMENT tx-required (#PCDATA)><!--The exceptions element contain a list of generated exceptions. This doesn't savea lot of typing, but can still be helpful.--><!ELEMENT exceptions (exception*)><!--See the comments in exceptions element.--><!ELEMENT exception (#PCDATA)><!--The service-builder-import allows you to split up a large Service Builder fileinto smaller files by aggregrating the smaller Service Builder into one file.Note that there can be at most one author element among all the files. There canalso only be one and only one namespace element among all the files.The attribute file is interpreted as relative to the file that is importing it.--><!ELEMENT service-builder-import (#PCDATA)><!--Set the comments in the service-builder-import element.--><!ATTLIST service-builder-import    file CDATA #REQUIRED>


原创粉丝点击