How to get sequence number in windchill through API - java

How to get sequence number for WT.Part or Wt.Document in Windchill through API?
When I create WT.Part - number automatically generated. But I can not find any method that returns the next number. I'm using Info*Engine.

At the time of object WTPart creation windchill use OOTB oracle_seqence in order to auto generate the number.
The sequence name is mentioned in the OIR of respective object.
Like
For
WTPart it is : WTPARTID_seq
For
WTDocument it is : WTDOCUMENTID_seq
etc .
So, if you want to get next number of WTPart then you can directly call the method wt.fc.PersistenceHelper.manager.getNextSequence("WTPARTID_seq");
from your info*engine task.
For different object the name of the sequence will be different.
In 10.2 PTC introduce another method getCurrentSequence("SEQ_NAME") to get the current sequence value without incrementing the same.

Are you familar with using Java with InfoEngine? If so, you can get the sequence by:
wt.fc.PersistenceHelper.manager.getNextSequence("SEQUENCE_NUMBER_OF_YOUR_OBJECT")
The sequence number will be specified inside the "Object Initialization Rule" that is associated with your object type.

As a temporary solution - create a new Part, read the number and either use it or delete.

Related

How to compare two timestamp columns in a Gremlin Java query

Is there a way to do something like that in Gremlin traversals?
I would have thought it would be obvious, but it seems I was wrong.
I have a table containing two dates (both are timestamps), and I would like to select only the records having one greater than the other one. Something like:
has('date_one', P.gt('date_two'))
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp with time zone > character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Then the second argument is not translated into the value of the column 'date_two'.
Based on the answer 1, the full request becomes:
g.V().hasLabel('File').where(or (
__.out('has_Ref1').hasNot('date_one'),
__.out('has_Ref1').as('s1', 's2').where('s1', gt('s2')).by('date_two').by('date_one')))
.as('file').out('has_Ref1').as('ref1').out('has_Content').as('data').select('file','ref1','data')
But in this case: A where()-traversal must have at least a start or end label (i.e. variable): [OrStep([[VertexStep(OUT,[has_Ref1],vertex), NotStep([PropertiesStep([date_one],value)])], [VertexStep(OUT,[has_Ref1],vertex)#[s1, s2], WherePredicateStep(s1,gt(s2),[value(date_two), value(date_one)])]])]
I guess the second argument of the or clause must be a boolean. Then if I try to add '.hasNext()', I've got the following exception:
g.V().hasLabel('File').where(or (
__.out('has_Ref1').hasNot('date_one'),
__.out('has_Ref1').as('s1', 's2').where('s1', gt('s2')).by('date_two').by('date_one').hasNext()))
.as('file').out('has_Ref1').as('ref1').out('has_Content').as('data').select('file','ref1','data')
groovy.lang.MissingMethodException: No signature of method: static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.or() is applicable for argument types: (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal...) values: [[VertexStep(OUT,[has_Ref1],vertex), NotStep([PropertiesStep([date_one],value)])], ...]
The has() step doesn't quite work that way as the P deals with a constant value supplied to it and doesn't treat that value as a property key. You would want to use where() step in this case I think so that you could take advantage of traversal induced values:
gremlin> g.addV('person').property('d1',1).property('d2',2).
......1> addV('person').property('d1',2).property('d2',1).iterate()
gremlin> g.V().as('x','y').where('x', gt('y')).by('d1').by('d2').elementMap()
==>[id:3,label:person,d1:2,d2:1]
Why don't you ask Postgres if the data_one is bigger than date_two
SELECT '2019-11-20'::timestamp > '2019-11-01'::timestamp;
?column?
----------
t
(1 row)
Time: 10.246 ms
this provides you a boolean value
I am assuming you are talking about a columns in a single table.
I have mostly worked with graphDB with gremlin but I think it will still fit right.
do your thing to get the table of concern
g.V().has(...).has()...
then just project the same data twice by using project directly or using as & select
...as('named1', 'named2').select('named1')
it is creating two copies of same data in the flow and then you can compare them on different basis like
...where('named1', gt('named2')).by('value1').by('value2')
above part in literal english means that bring me only those from selected where value1 of named1 is greater than value2 of named2
If you give only one by then it will compare same property

Servlet returns/generate unique string

I need to make a servlet service that does following things
when user request the service, servlet generates a unique 5 letter string that has never been generated. (combination of 0~9 and a~Z)
if user accepts it, save user's info using the unique string(that #1 generated) as a primary key
First thing popped in my head was using static class variable that increments by 1 as requests hit servlet, but searching here and google says this is really really bad idea, as if multiple users hit the service at the same time, it will break...
and now I am clueless what to look into.
What would be the best and the safetest approach to generate a unique string incrementally?
Add a field sequence no in table and when ever a new request comes get the highest sequence number from database and then add one ie plus 1 and save it
According to this site, your highest number (ZZZZZ) is 426088025. In the database world you'd want to used a sequence but, because of your 5 character restriction, you need to make sure that it doesn't go over this number (hopefully you're storing less than 426M records).
To create a sequence you'll do something like:
create sequence your_sequence maxvalue 426088025 no cycle
That is the PostgreSQL syntax - your database may vary.
Then, in your code you can do a
select nextval('your_sequence')
to get your value and then Base64 encode this value. In PostgreSQL the "no cycle" means that if you get to the max it will throw an error.
In Java 8, Base64 is included:
import java.util.Base64;
...
String userNumber = Base64.getEncoder().encodeToString(Integer.toString(integerFromSequenceSelect));
Otherwise, if you're stuck with an old version of Java, use Apache Commons Codec and run:
import org.apache.commons.codec.binary.Base64;
...
String userNumber = Base64.encodeBase64String(Integer.toString(integerFromSequenceSelect));

how can i generate a item code value with auto increment integer plus an identification integer

i'm creating a Itemcode for my inventory system i want the number system of integer values like this using java
for example this
for group 1 the code would be 001 -
0010001,
0010002
for group 2 the code would be 002-
0020003,
0020004
for group 3 the code would be 003-
0030005,
0030006
the items are encoded individually so when i add a new entry it will detect which group it belongs to and generate it desired item code the first 3 digits will be the corresponding Value identification in which group it belongs to the the next 4 digit code will just be the increment value..and would be stored as one integer using MySQL database
You need to decide:
Are the item codes to be represented as: one integer, a pair of integers (group & item), a string ... or something else.
Is the numbering scheme per the first example or the second one. (You seem to have chosen one scheme now ...)
How you are going to populate the items and codes. Do you read the codes? Do you generate them all in one go while loading items from a file. Do you create items and item ids one at a time (e.g. interactively).
How is this information going to be "stored"? In memory only? In a flat file? In a database? (MySQL ... ?)
These decisions will largely dictate how you implement the item id "generation".
Basically, your problem here is that >>you<< need to figure out what the requirements are. Once you have done that, the set of possible solutions will reduce to a manageable size, and you can then either work it out for yourself or ask a sensible question.

What is the meaning of the Value column for an object in the NetBeans Debugger Variable window?

The NetBeans 8 Debugger Variables window has a Value column. The meaning of the column is pretty self explanatory for primitive types and Strings and Arrays, but for Objects, the column displays a "#" character followed by a (typically 4 digit) number. The value is apparently related to the identity of the object because multiple variables referencing the same object have the same number displayed, and objects constructed consecutively seem to have sequential numbers. The number is not object.hashCode(). Can anyone tell me more about the number being shown? I am specifically wondering if that number can be accessed as a method or property of the object similar to hashCode(). If not, then is there a way to access that number programmatically?
My explanation of the column's meaning corresponds to the last section of https://ui.netbeans.org/docs/hi/debugger3.4/variables/index.html#specific which is entitled "Object Rows". It states that "Object rows are used to show references to class instances. Each reference can be thought of as having the number of a class instance (from some table of instances in the VM), so this number is shown in the value column (prefixed by "#") for the reference."
I am trying to get a better explanation of what the article simply calls "some table of instances in the VM".
Thanks
I don't think there is a way to access that number, unless you are creating debugger plugin. Netbeans just assigns a new number to every new object it encounters during debugging session. The "is the object new" check is probably based directly on identity (==) and not on Object.hashCode()/System.identityHashCode().
You can take "some table of instances in the VM" quite literally. Even if JVM doesn't have explicit tables you can still get such list from heap dump(HPROF). The OQL (Object Query Language) allows for SQL-like access to such data. For example:
select f.field1 from my.package.MyClass f where f.field2 = 123
By the way I ended up in this question looking for a way to display toString() instead of that #number - to get that I had to right-click variable table header and select new column "String value". The alternative way is to add Variable formatter in "Tools/ Option /Java / Java Debugger / Variable formatters"

Is there a way to generate timestamp based uuid?

Reading document, I saw there are four types of uuid. I am wondering how to generate type 1(timestamp based) and type2 (DCE security based) uuid. Any idea?
You can also implement your own if for whatever reason you don't want to use JUG (as suggested above).
For this check the class UUID. You need to use System.nanoTime() and ensure successive calls return increasing values (so if you get two times the same time value, then return the greatest returned value so far plus 1).
The layout of the UUID type 1 can be found in: http://www.ietf.org/rfc/rfc4122.txt

Categories