Sparx Enterprise Architect: BPMN collecting activities from several lane instances - enterprise-architect

I have several business processes modelled in EA. All have the same lanes, so (as I have seen in some tutorial) I added a generic element and the process lanes all reference via the "partitionElementRef" to the same generic element. (See screen, the lower business process contains a lane Capture, which is linked to the upper "Lanes assigned to Roles").
How can I query EA that I can collect all activities within the different business processes that refer to the same lane? Such, that I can collect from all business processes all elements with the same lane "Capture"?
A list or a matrix would be perfect as a result.

I don't think you should use Lane for the generic element, but rather use a BPMN PartnerRole or PartnerEntity element.
Using lanes would be a BPMN syntax violation.
Apart from that, if you want to query the model to get all lanes and their generic element you can use a query like this
select o.ea_guid AS CLASSGUID, o.Object_ID as CLASSTYPE, o.Name, o.Stereotype, gen.Name as GenericElement
from ((t_object o
inner join t_objectproperties tv on (tv.Object_ID = o.Object_ID
and tv.Property = 'PartitionElementRef'))
left join t_object gen on gen.ea_guid = tv.Value)
where o.Stereotype = 'Lane'
The Lane is linked to the generic element with the tagged value PartitionElementRef which contains the guid of the generic element.
If you want to get the Activities in your lane you join again with t_object using the ParentID
select act.ea_guid AS CLASSGUID, act.Object_ID as CLASSTYPE, act.Name, act.Stereotype,
o.Name as Lane, gen.Name as GenericElement
from (((t_object o
inner join t_objectproperties tv on (tv.Object_ID = o.Object_ID
and tv.Property = 'PartitionElementRef'))
left join t_object gen on gen.ea_guid = tv.Value)
inner join t_object act on (act.ParentID = o.Object_ID
and act.Stereotype = 'Activity'))
where o.Stereotype = 'Lane'
Bonus tip: if you leave the name of the lane empty, it will show the name of the generic element on the diagram.

Based on Geert Bellekens solution, I simply added the last where clause...
select act.ea_guid AS CLASSGUID, act.Object_ID as CLASSTYPE, act.Name, act.Stereotype,
o.Name as Lane, gen.Name as GenericElement
from (((t_object o
inner join t_objectproperties tv on (tv.Object_ID = o.Object_ID
and tv.Property = 'PartitionElementRef'))
left join t_object gen on gen.ea_guid = tv.Value)
left join t_object act on (act.ParentID = o.Object_ID
and act.Stereotype = 'Activity'))
where (o.Stereotype = 'Lane' and act.Stereotype = 'Activity')
Finally, in the query result, grouped by Generic Element

Related

How do I return only the first object in an HQL cross join?

I have the following HQL
from
com.kable.web.allotment.model.Issue i
inner join fetch i.title
inner join fetch i.title.magazine
inner join fetch i.barcodes bcs
, Wholesaler w
LEFT join fetch w.localCurrencies c
inner join fetch w.location
where
w.id = :wholesalerId
and i.title.id = :titleid
and i.distributionStatus = :status
and (
(
i.distributionDate is null
and i.onSaleDate >= TRUNC(CURRENT_DATE)
)
or i.distributionDate >= TRUNC(CURRENT_DATE)
)
and bcs.type.id = w.location.id
and (bcs.localCurrency.id = c.localCurrencyType.id OR c.localCurrencyType.id IS NULL)
and i.onSaleDate BETWEEN COALESCE(c.effectiveDate, i.onSaleDate) and COALESCE(c.expirationDate, i.onSaleDate)
order by
i.distributionDate
, i.onSaleDate
All of my previously written code is expecting to get a List<Issue> back, but with the code above, I am also getting the wholesaler and its joins. In my results, I only want Issue, Title, Magazine, and Barcodes. I am using hibernate version 4.2.18.Final. How do I only return the 1st object graph? I found something about CROSS JOIN ON but it is only for Hibernate 5 or later, and I can't switch because the project is quite large and Java dependencies.
You simply need to add an explicit SELECT i clause.
As a side note, JOIN FETCH for Wholesaler associations doesn't make sense if it's not going to be present in the result anyway

how to make a logical exclusion within the query?

I have 3 tables in our ERP database holding all delivery data (table documents holds one row for each delivery note, documentpos holds all positions on delivery notes, documentserialnumbers holds all serial numbers for delivered items).
I want to show all items with their serial number that have been delivered to the customer and still resides there so far.
The above shown output of the following query however shows, that one item that has been delivered was returned (red marks) later. The return delivery note has the document number 527419 (dark red mark) and refers to the the delivery note 319821 (green) which is listed yellow.
The correct list would consequential show only items that are still on customer's site without the returned items (see below).
How do I have to change the query in order to exclude the returned items from the output?
The upper table shows in the image shows the output of my query, the table below how it should be.
select a.BelID, c.ReferenzBelID, a.itemnumber, a.itemname, c.deliverynotenumber,c.documenttype, c.documentmark, b.serialnumber
from dbo.documentpos a
inner join dbo.documentserialnumbers b on a.BelPosID = b.BelPosID
inner join dbo.documents c on a.BelID = c.BelID
inner join sysdba.customers d on d.account = c.A0Name1
where d.AccountID = 'customername' and c.documenttype like '%delivery%'
order by a.BelID
You may exclude positions, which are referenced by any "return" delivery note, like this (edited)
select a.BelID, c.ReferenzBelID, a.itemnumber, a.itemname, c.deliverynotenumber,c.documenttype, c.documentmark, b.serialnumber
from dbo.documentpos a
inner join dbo.documentserialnumbers b on a.BelPosID = b.BelPosID
inner join dbo.documents c on a.BelID = c.BelID
inner join sysdba.customers d on d.account = c.A0Name1
where d.AccountID = 'customername' and c.documenttype like '%delivery%'
and not exists (select 1
from dbo.documents cc
where cc.documenttype like '%delivery%'
and c.ReferenzBelID=cc.BelID
and c.documentmark='VLR')
and not exists (select 1
from dbo.documents ccc
join dbo.documentpos aa on aa.BelID = ccc.BelID
where ccc.ReferenzBelID=c.BelID
and ccc.documentmark='VLR'
and a.itemnumber=aa.itemnumber)
order by a.BelID

Multiple JOIN with FETCH in Criteria API

I have a JPQL that looks like this:
SELECT
DISTINCT b
FROM
Book b
INNER JOIN
FETCH b.volumes as v
INNER JOIN
v.metadata as md
WHERE
b.createdAt IN (
SELECT
MAX(book.createdAt)
FROM
Book book
WHERE
book.author = ?1
)
AND md.genre IN (
?2
)
Since this has to be generated dynamically, I need to use Criteria API to add various conditions. I can get everything right except for the JOINs, because the first one is a fetch and I'm not able to chain that one with the next.
This is what I have so far:
query.distinct(true);
final Join<Book, Metadata> Metadata = root.join("volumes").join("metadata");
final Subquery<LocalDateTime> subquery = query.subquery(LocalDateTime.class);
final Root<Book> plan = subquery.from(Book.class);
subquery.where(criteriaBuilder.equal(plan.get("author"), companyId));
final Expression<LocalDateTime> createdAt = book.get("createdAt");
subquery.select(criteriaBuilder.greatest(createdAt));
predicates.add(criteriaBuilder.in(root.get("createdAt")).value(subquery));
genre.ifPresent(strings -> predicates.add(criteriaBuilder.in(metadata.get("genre")).value(strings)));
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
Any idea on how to make the first join a fetch?
There is a method for it in the Root class. Without second parameter it is inner join fetch
root.fetch("volumes")

Is an images table best practice for an ecommerce site?

I'm building an ecommerce system with products and variants, where each has between 1 and 5 images that are stored on Amazon S3. Is it considered best practice to have a separate images table where I store the S3 URLs, or is acceptable to just add 5 image columns to each of the products and variants tables? Having a separate images table means that on import I need to do 6 SELECTS and then INSERTS (to make sure the product and each of its images don't already exist and then to import them) rather than 1. And, on retrieval, I need to join the images table to the products table 5 times to have it return the images with the product, like this:
SELECT prd."id" AS id, prd."title" AS title, prd."description" AS description,
prd."createdAt" AS productcreatedate,
prdPic1."url" AS productpic1,
prdPic2."url" AS productpic2,
prdPic3."url" AS productpic3,
prdPic4."url" AS productpic4,
prdPic5."url" AS productpic5,
brd."name" AS brandname, brd."id" AS brandid,
cat."name" AS categoryname, cat."id" AS categoryid,
prt."name" AS partnername, prt."id" AS partnerid
FROM "Products" prd
LEFT OUTER JOIN "Pictures" prdPic1 ON prdPic1."entityId" = prd."id" AND prdPic1."entity" = '1'
AND prdPic1."sortOrder" = 1
LEFT OUTER JOIN "Pictures" prdPic2 ON prdPic2."entityId" = prd."id" AND prdPic2."entity" = '1'
AND prdPic2."sortOrder" = 2
LEFT OUTER JOIN "Pictures" prdPic3 ON prdPic3."entityId" = prd."id" AND prdPic3."entity" = '1'
AND prdPic3."sortOrder" = 3
LEFT OUTER JOIN "Pictures" prdPic4 ON prdPic4."entityId" = prd."id" AND prdPic4."entity" = '1'
AND prdPic4."sortOrder" = 4
LEFT OUTER JOIN "Pictures" prdPic5 ON prdPic5."entityId" = prd."id" AND prdPic5."entity" = '1'
AND prdPic5."sortOrder" = 5
INNER JOIN "Brands" brd ON brd."id" = prd."BrandId"
INNER JOIN "Categories" cat ON cat."id" = prd."CategoryId"
INNER JOIN "Partners" prt ON prt."id" = brd."PartnerId";
The value of normalizing Brands, Categories, and Partners is clear to me to reduce redundancy. I'm less clear on the value for an images table. Explain Analyze on Postgres says this query takes 3310 msec to return 22000 rows. However, I haven't created indexes on Pictures yet, so that's not a fair analysis.
In this case, I think I would add single column, of text[] type (array of text). In this way, you have the images where you need them, and you're not bound to end in hell when you'll add more images for a product.

Joining several tables: table specified more than once error

I am attempting to call data after joining all of my tables in a postgreSQL query.
I am getting the following error:
Error in postgresqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not Retrieve the result : ERROR: table name "place" specified more than once
)
Failed to execute SQL chunk
After referring to similar posts and online resources, I have attempted setting aliases (which only create new errors about not referring to the other tables in the FROM clause), reordering the table names (the cleanest, reordered chunk is posted below), and experimenting with UPDATE/FROM/JOIN as an alternative to SELECT/FROM/JOIN. However, I think I ultimately need to be using the SELECT clause.
SELECT *
FROM place
INNER JOIN place ON place.key = form.key
INNER JOIN form ON form.id = items.formid
INNER JOIN items ON items.recid = rec.id
INNER JOIN rec ON rec.id = sub.recid
INNER JOIN sub ON sub.id = type.subid
INNER JOIN type ON type.name = det.typeid;
You have "place" in your query twice, which is allowed but you would have to alias the second use of the table "place". Also you reference something called "det", but it's not a table or alias anywhere in your query. If you want only one place that's fine, just remove the INNER JOIN place and move your place.key = form.key to the form join or to a where clause.
If you want to place tables in their because you are trying to join the table to itself the alias the second one, but you will want to make sure that you then have a clause to join those two tables on (could be part of an on or a where)
The issue ended up being the order of table names. The code below joined everything just fine:
SELECT *
FROM place
INNER JOIN form ON place.key = form.key
INNER JOIN items ON form.id = items.formid
INNER JOIN rec ON items.recid = rec.id
INNER JOIN sub ON rec.id = sub.recid
INNER JOIN type ON sub.id = type.subid
INNER JOIN det ON type.name = det.typeid;