請問CHING明唔明databene是怎樣運作的

我follow佢個steps
但個xml是否我自己寫?
如果是,那同人手入有什麼分別?
http://databene.org/databene-benerator/tutorials/85-database-population-tutorial.html

thanks

I understand now, but how can I generate the xml file from an existing
Schema? Vendor: JavaDB/Derby

TOP

自己寫個script套資料入XML=.=

TOP

本帖最後由 luckiejacky 於 2013-12-9 17:04 編輯

唔系好明點解Total Price = product[1] * db_order_item.number_of_items
Hardcoded? 這個是從Databene 個shop example抽出來的...

  1. <comment>create order items</comment>
  2.         <generate type="db_order_item"
  3.                 count="{customer_count * orders_per_customer * items_per_order}" consumer="db">
  4.                 <variable name="product" source="db" selector=
  5.                      "select ean_code, price from db_product" distribution="cumulated" />
  6.                 <id name="id" generator="idGen" />
  7.                 <attribute name="number_of_items"
  8.                       min="1" max="27" distribution="cumulated" />
  9.                 <reference name="order_id" source="db"
  10.                      selector="select id from db_order where id &gt; 1" cyclic="true" />
  11.                 <reference name="product_ean_code" script="product[0]" />
  12.                 <attribute name="total_price"
  13.                       script="product[1] * db_order_item.number_of_items" />
  14.         </generate>
複製代碼

TOP

本帖最後由 luckiejacky 於 2013-12-9 19:58 編輯

Does anyone know where the problem is? ahh.... extremely tired.
Please help
Thanks


  1. 19:46:31,900 ERROR (main) [DescriptorRunner] Error in Benerator execution
  2. org.databene.benerator.InvalidGeneratorSetupException: 'min' greater than max, '
  3. max' less than min
複製代碼

  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <setup
  3.         xmlns="http://databene.org/benerator/0.7.0"
  4.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.         xsi:schemaLocation="http://databene.org/benerator/0.7.0 http://databene.org/benerator-0.7.0.xsd">

  6. <comment>import stage and database specific properties</comment>
  7.         <include uri="{ftl:cris.properties}" /> <!-- ftl: is the prefix used for scripting with FreeMarker Template Language -->
  8.         <include uri="{ftl:cris.Derby.properties}" />
  9.        
  10. <comment>define a database that will be referred by the id 'cris' subsequently</comment>
  11.     <database id="cris" url="{dbUrl}" driver="{dbDriver}" schema="{dbSchema}"
  12.         user="{dbUser}" password="{dbPassword}" batch="{dbBatch}" />
  13.                
  14. <bean id="idGen" spec="new IncrementGenerator(1000)" />

  15. <import domains="customer, orders, order_details"
  16.       platforms="fixedwidth"/>
  17.           
  18.         <generate type="customer" count="{customer_count}" consumer="cris">
  19.           <variable name="person" generator="org.databene.domain.person.PersonGenerator" dataset="{country}" locale="{locale}"/>
  20.           <id name="CustomerID" type="integer" generator="idGen"/>
  21.           <attribute name="CustomerCode" type="string"
  22.                                         pattern="CUS[0-9]{2}\-[0-9]{2}\-[0-9]{4}" unique="true"/>
  23.           <attribute name="LastName" script="person.familyName" type="string" minLength="1" maxLength="2" />
  24.           <attribute name="FirstName" script="person.givenName" type="string" minLength="1" maxLength="4" />
  25.           <attribute name="Residence" type="integer" min="1" max="4"/>
  26.           <attribute name="PREFERREDCONTACTMETHODID" type="integer" min="1" max="7"/>
  27.           <attribute name="Sex" type="char" values="'M','F'"/>
  28.           <attribute name="Address" type="string" minLength="3" maxLength="255"/>
  29.           <attribute name="JobDutyID" type="integer" min="1" max="20"/>
  30.           <attribute name="ConvenientContactTimeID" type="integer" min="1" max="6"/>
  31.           <attribute name="IDCardNumber" type="string" minLength="19" maxLength="20"/>
  32.           <attribute name="DOB" type="date"/>
  33.           <attribute name="MobilePhoneNumber" type="string" pattern="[0-9]" minLength="11" maxLength="12"/>
  34.           <attribute name="email" type="string" generator="org.databene.domain.person.EMailAddressGenerator"/>
  35.           <attribute name="PostalCode" type="string" pattern="[0-9]" minLength="4" maxLength="5"/>
  36.           <attribute name="QQ" type="string" pattern="[0-9]" minLength="11" maxLength="12"/>
  37.           <attribute name="AgeGroupID" type="integer" min="1" max="5"/>
  38.           <attribute name="OccupationID" type="integer" min="1" max="20"/>
  39.           <attribute name="Weishun" type="string" pattern="[0-9]" minLength="11" maxLength="12"/>
  40.           <attribute name="SalaryRangeID" type="integer" min="1" max="7"/>
  41.           <attribute name="MemoryReasonID" type="integer" min="1" max="7"/>
  42.           <attribute name="MemoryDate" type="date"/>
  43.           <attribute name="EducationID" type="integer" min="1" max="5"/>
  44.           <attribute name="BonusPoints" type="integer" selector="select sum(NetSales) from order_details od, orders o where (o.OrderCode = od.OrderCode) where OrderCode &gt; 1" cyclic="true" />
  45.           <attribute name="GMCustomer" type="boolean" values="0,1"/>
  46.           <attribute name="BlackListed" type="boolean" values="0,1"/>
  47.           <attribute name="RegisterDate" type="date"/>
  48.           <attribute name="CreatePerson" type="string" script="person.familyName + ' ' + person.givenName" minLength="1" maxLength="20"/>
  49.           <attribute name="CustomerCreationDate" type="date"/>
  50.           
  51.           
  52.           
  53.           
  54.           </generate>
  55.           
  56.     <comment>create orders for random customers and random products</comment>
  57.         <generate type="orders" count="{customer_count * orders_per_customer}" consumer="cris">
  58.         <id name="OrderID" generator="idGen" />
  59.                 <attribute name="OrderCode" type="string"
  60.                                         pattern="ORD[0-9]{2}\-[0-9]{2}\-[0-9]{4}" unique="true"/>
  61.             <reference name="CustomerCode" source="cris" targetType="customer" cyclic="true" />
  62.                 <reference name="EmployeeCode" source="cris" targetType="Employee" cyclic="true" />
  63.                 <attribute name="PurchaseDateTime" type="Timestamp"/>
  64.                 <attribute name="PurchaseReason" type="string" minLength="1" maxLength="255" />
  65.         </generate>

  66.         <comment>create order items</comment>
  67.         <generate type="order_details"
  68.                         count="{customer_count * orders_per_customer * items_per_order}" consumer="cris">
  69.                 <variable name="product" source="cris" selector="select categoryCode || SubCategoryCode || SKU AS SKU,  UnitPrice from products" distribution="cumulated" />
  70.         <id name="OrderDetailID" generator="idGen" />
  71.                 <reference name="OrderCode" source="cris" selector="select OrderCode from orders where OrderCode &gt; 1" cyclic="true" />
  72.                 <reference name="SKU" script="SKU[0]" />               
  73.                 <attribute name="Quantity" min="1" max="10" distribution="cumulated" />
  74.                 <attribute name="Price"  type="bigdecimal" min="0.00" max="20000.00"/>
  75.                 <attribute name="NetSales" script="Price * cris.Quantity" />
  76.                 <attribute name="Weight" type="integer" min="1" max="100"/>
  77.         </generate>
  78.          
  79. </setup>
複製代碼

TOP

http://www.w3schools.com/xpath/
take a look at xpath (way to extract content from xml file)

TOP

Thanks kin ching

TOP

本帖最後由 luckiejacky 於 2013-12-10 08:01 編輯

What is this?
  1. 04:50:05,795 INFO  (main) [TaskExecutor] Running task StateTrackingTaskProxy[Gen
  2. erateAndConsumeTask(CUSTOMER)] 100 times with page size 1 in a single thread
  3. 04:50:05,821 ERROR (main) [DescriptorRunner] Error in Benerator execution
  4. java.lang.RuntimeException: Error in persisting CUSTOMER[CustomerID=1000, Custom
  5. erCode=CUS10-10-3210, LastName=Day, FirstName=Mark, Residence=3, PREFERREDCONTAC
  6. TMETHODID=7, Sex=M, Address=DATZSNKXGSCKIDYFKOGMNARWGRWPHALBJHVLBTUVRFLMYCXKTOGX
  7. GHLIAJZOCVXTIDRXYFYOOLZJXPAMQGUZMZYMFZTFMCUBNESMRPQNAIKSJHHGTBFMONXNELSNNXCTEFCN
  8. PNEW, JobDutyID=8, ConvenientContactTimeID=5, IDCardNumber=3299777279508, DOB=19
  9. 93-09-13, MobilePhoneNumber=38601626092, email=mark.frederick@efj.org, PostalCod
  10. e=6441, QQ=34816821649, AgeGroupID=3, OccupationID=10, Weishun=82854997396, Sala
  11. ryRangeID=3, MemoryReasonID=4, MemoryDate=1998-11-27, EducationID=5, BonusPoints
  12. =78399408, GMCustomer=false, BlackListed=false, RegisterDate=1997-06-25, CreateP
  13. erson=Day Mark, CustomerCreationDate=2009-10-26T02:41:00]
複製代碼

  1. org.databene.benerator.InvalidGeneratorSetupException: Unable to create generato
  2. r for atomic dataset: HK:
複製代碼

TOP