You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Guenther Schmidt <gu...@epost.de> on 2003/03/07 11:04:19 UTC

how to generate random numbers or strings?

Hi all,

I need to generate random numbers or a random string sequence for use as
primary keys in a database app.

How do I generate them within cocoon?

I have good reasons not to use database sequence for primary keys.

Thanks upfront

Guenther


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: how to generate random numbers or strings?

Posted by Guenther Schmidt <gu...@epost.de>.
Hi Antonio,

thanks for your answer.

I've been trying to avoid using XSP and logic sheets quite successfully
sofar, since:

a. I don't know Java :-(

b. It seems possible to do without them.

I think I'll query my database for a random number and just add a prefix
instead via XSLT.

I also use aggregate a lot.

Thanks again

Guenther


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: how to generate random numbers or strings?

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hello!

I meet this problem some months ago. I made a solution using XSP. I think
you can easily enhance this piece of code:

<xsp:logic>
	String key = <xsp-request:get-parameter name="table_id" default=""/>;
	while (key.equals("")) {
		Random aleatorio = new Random();
		int new_key = aleatorio.nextInt(Integer.MAX_VALUE) + 1;
		llave = String.valueOf(new_key);
		/* Check into database if the key exist into the table */
		<esql:execute-query>
			<esql:query>
				SELECT table_id FROM table WHERE table_id=<esql:parameter
type="int"><xsp:expr>new_key</xsp:expr></esql:parameter>
			</esql:query>
			<esql:results>
				<esql:row-results>
					key = "";
				</esql:row-results>
			</esql:results>
		</esql:execute-query>
	}
</xsp:logic>
<parameter name="table_id"><xsp:attribute
name="value"><xsp:expr>key</xsp:expr></xsp:attribute></parameter>

best regards,

Antonio Gallardo



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: how to generate random numbers or strings?

Posted by Guenther Schmidt <gu...@epost.de>.
Hi Chris,

thanks for your answer.

I suppose I should have mentioned that I'm a Cocoon NEWBIE, unfortunately
also a Java NEWBIE.

I've been doing my projects in PHP sofar ;-)

I've seen other replies of yours and you seem to be deep inside Cocoon,
congratulations.
I hope to get there someday too.

Thanks again,

Guenther

Christian Haul wrote:

> On 07.Mar.2003 -- 10:04 AM, Guenther Schmidt wrote:
>> Hi all,
>> 
>> I need to generate random numbers or a random string sequence for use as
>> primary keys in a database app.
>> 
>> How do I generate them within cocoon?
> 
> Use your favourite java pseudo random number generator.
> In case you need it from sitemap, there's an input module that uses
> the stock prng that can be used e.g. "{random:randomNumber}"
> 
> Chris.



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: how to generate random numbers or strings?

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 07.Mar.2003 -- 10:04 AM, Guenther Schmidt wrote:
> Hi all,
> 
> I need to generate random numbers or a random string sequence for use as
> primary keys in a database app.
> 
> How do I generate them within cocoon?

Use your favourite java pseudo random number generator.
In case you need it from sitemap, there's an input module that uses
the stock prng that can be used e.g. "{random:randomNumber}"

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org