部署代码在Hybris中的用途是什么?

huangapple go评论89阅读模式
英文:

what is the use of deployment code in hybris?

问题

<itemtype code="IntegrationSystemCredentials" autocreate="true" generate="true">
    <deployment table="IntegrationSystemCredentials" typecode="11000" />
</itemtype>

在上述代码中,我已经提到了部署表和类型代码。为什么我们同时使用这两者呢?
英文:
&lt;itemtype code=&quot;IntegrationSystemCredentials&quot; autocreate=&quot;true&quot; generate=&quot;true&quot;&gt;
                &lt;deployment **table**=&quot;IntegrationSystemCredentials&quot; typecode=&quot;11000&quot; /&gt;
&lt;/itemtype&gt;

In the above code i have mentioned deployment table and typecode. why we are using both?

答案1

得分: 1

> 在上面的代码中,我已经提到了部署表和类型代码(typecode)。为什么我们要同时使用它们呢?

简短的回答是:因为它们有不同的用途。

部署表(deployment table)

使用部署表,您将数据库表映射到itemtype。如果您不提到部署表itemtype的属性值将保存在其父itemtype部署表中;换句话说,在itemtype定义中缺少部署表的情况下,父itemtype的数据库表将与itemtype映射。

如果您通过扩展GenericItem来创建itemtype,则必须声明一个部署表(这是一种避免itemtype的属性保存在GenericItem表中的机制)。然而,如果您扩展了其他一些itemtype,例如Product,应尽量避免在执行Flexible Search Query时声明部署表,以避免需要太多的连接操作。

请注意,GenericItemitemtype的默认父类型,即如果在itemtype定义中不声明extends...,则itemtype将默认扩展为GenericItem。例如,以下itemtype定义将无法编译,因为DummyItem默认扩展为GenericItem,但没有为其指定部署表

<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="items.xsd">
	<itemtypes>
		<itemtype code="DummyItem" autocreate="true">
			<attributes>
				<attribute qualifier="uname" type="java.lang.String">
					<modifiers read="true" write="true" search="true" initial="true" optional="false"/>
					<defaultvalue>"Hello"</defaultvalue>
					<persistence type="property"></persistence>
				</attribute>
			</attributes>
		</itemtype>
	</itemtypes>
</items>

类型代码(typecode)

类型代码属性是引用类型的唯一数字。类型代码属性的值必须是介于032767(2^15-1)之间的正整数,并且在整个您的 hybris 应用程序中必须是唯一的,因为它是PK生成机制的一部分,如下所示:

private static PK createPK_Counter(int typecode, long counter) {
	if (typecode >= 0 && typecode <= 32767) {
		//...
	} else {
		throw new IllegalArgumentException("illegal typecode : " + typecode + ", allowed range: 0-" + 32767);
	}
}

查阅此链接此链接以获取更多信息。

英文:

> In the above code i have mentioned deployment table and typecode. why
> we are using both?

The short answer is: It's because they serve different purposes.

deployment table

Using deployment table, you map a database table to the itemtype. If you do not mention deployment table, the values of the attributes of the itemtype will be saved into the deployment table of its parent itemtype; in other words, in absence of the deployment table in the itemtype definition, the database table of the patent itemtype will be mapped with the itemtype.

If you are creating an itemtype by extending GenericItem, you must declare a deployment table (a mechanism to avoid the attributes of the itemtype getting saved in GenericItem table). However, if you are extending some other itemtype e.g. Product, you should avoid declaring deployment table as much as possible in order to avoid too many joins required during the execution of the Flexible Search Query.

Note that GenericItem is the default parent of an itemtype i.e. if you do not declare extends... in the itemtype definition, the itemtype will, by default, extend GenericItem e.g. the following itemtype definition will fail compilation because DummyItem extends GenericItem by default but there is no deployment table mentioned for it.

&lt;items xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:noNamespaceSchemaLocation=&quot;items.xsd&quot;&gt;
	&lt;itemtypes&gt;
		&lt;itemtype code=&quot;DummyItem&quot; autocreate=&quot;true&quot;&gt;
			&lt;attributes&gt;
				&lt;attribute qualifier=&quot;uname&quot; type=&quot;java.lang.String&quot;&gt;
					&lt;modifiers read=&quot;true&quot; write=&quot;true&quot; search=&quot;true&quot; initial=&quot;true&quot; optional=&quot;false&quot;/&gt;
					&lt;defaultvalue&gt;&quot;Hello&quot;&lt;/defaultvalue&gt;
					&lt;persistence type=&quot;property&quot;&gt;&lt;/persistence&gt;
				&lt;/attribute&gt;
			&lt;/attributes&gt;
		&lt;/itemtype&gt;
	&lt;/itemtypes&gt;
&lt;/items&gt;

typecode

The typecode attribute is a unique number to reference the type. The value of the typecode attribute must be a positive integer between 0 and 32767 (2^15-1) and must be unique throughout your hybris application as it is part of the PK generation mechanism as shown below:

private static PK createPK_Counter(int typecode, long counter) {
	if (typecode &gt;= 0 &amp;&amp; typecode &lt;= 32767) {
		//...
	} else {
		throw new IllegalArgumentException(&quot;illegal typecode : &quot; + typecode + &quot;, allowed range: 0-&quot; + 32767);
	}
}

Check this and this to learn more about it.

答案2

得分: 0

> 什么是Hybris中的部署表?

SAP Commerce中的项通过将值写入数据库而变为持久化。在数据库内,这些值被存储在表中。SAP Commerce允许您明确地定义实例值将被写入的给定类型的数据库表。这可以通过定义部署标签来实现。例如:
&lt;deployment table=&quot;mytype_deployment&quot; typecode=&quot;12345&quot; /&gt;


> 何时定义部署表?

当以下情况之一成立时,应为项目类型定义部署表:

  • 您的项目类型不扩展任何其他项目类型(默认情况下除外的GenericItem类型)

  • 您的项目类型扩展了尚未定义部署表的现有项目类型

了解更多信息,请阅读为平台类型指定部署

英文:

> what is the deployment table in hybris?

Items within SAP Commerce are made persistent by writing values into a database. Within the database, the values are stored in tables. SAP Commerce allows you to explicitly define the database tables where the values of instances of a given type will be written. This can be done by defining the deployment tag.
Like.
&lt;deployment table=&quot;mytype_deployment&quot; typecode=&quot;12345&quot; /&gt;


> When to define the deployment table?

One should define the deployment table for an item type when

  • Your item type doesn't extend any other item type (except GenericItem, which is by default)

  • Your item type extend existing item type for which there is no deployment table defined

Read more Specifying a Deployment for Platform Types

huangapple
  • 本文由 发表于 2020年8月30日 03:11:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63650838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定