-1

This is a line I've encountered inside a DAO class:

pages.addAll((List<Page>)getCurrentSession()
        .createCriteria(Page.class)
        .add(Restrictions.eq("path", pagePath))
        .setMaxResults(1).list());

I've never seen a method call right after a set of brackets, with no dot in between. Is it just an optional different syntax, or does it do something beyond getting the session associated with the List?

(Note: Using Java / Spring, and Hibernate @Transactional business here)

EDIT: updated to the complete line of code, didn't realise it was significant. Mostly I was thrown by the method-like syntax without the dot.


Passing Credentials to a Web Service using ASP.NET from PHP Sample Code

I am trying to use the Despatch Bay shipping API within an ASP.NET application, but all their sample code is in PHP.

I've used web services before, but am having trouble passing the credentials to this.

The PHP sample code creates a new instance of the API as follows:

$soapOptions = array ('login' => APIUSER, 'password' => APIKEY);
$DespatchBay = new SoapClient("http://api.despatchbaypro.com/api/soap/v10/addressing?wsdl",$soapOptions);

Using Visual Web developer Express, I have added a service reference to my Project, and can now create an instance like this:

Dim dbService As New DespatchBayAddresses.AddressingServicePortTypeClient

And attempt to write out an address from a post code as follows:

Response.Write(dbService.GetDomesticAddressKeysByPostcode("INSERT POSTCODE").ToString())

But, quite naturally, I get an error:

The remote server returned an error: (401) Unauthorized.

I know why, because I haven't passed in my API_KEY or API_USER credentials.

But, I'm being dumb I am sure, but can't figure out how.

I tried

dbService.ClientCredentials.UserName.UserName = MY_USER
dbService.ClientCredentials.UserName.Password = MY_KEY

But same error. I need to be able to pass these values from a variable retrieved from my database, not a static value in web.config, so could someone please point me in the direction of getting these details to the API?

Thanks

4

2 に答える 2

2

簡単に言えば、ステートメント

getCurrentSession().createCriteria(Page.class)
    .add(Restrictions.eq("path", pagePath))
    .setMaxResults(1).list()

Listキャストされるa を返します

List<Page>

次に、キャストされたオブジェクトがpage.addAll()メソッドに渡されます。

于 2013-09-17T13:44:41.383 に答える
1

ほとんどの場合、完全な行を見逃しました

(List<Object>) getCurrentSession().createCriteria(Page.class).list();

Page データベースからオブジェクト (pojo) のリストを返します。

あなたのライン

pages.addAll((List<Page>)getCurrentSession().createCriteria(Page.class)
        .add(Restrictions.eq("path", pagePath))
        .setMaxResults(1).list()); 

1)pagesはリスト

2)

 (List<Page>)getCurrentSession()
                .createCriteria(Page.class)
                .add(Restrictions.eq("path", pagePath))
                .setMaxResults(1).list()

ここではlist()、クライテリア オブジェクトのメソッドがオブジェクトのリストを返します。ここでは、それらが Page オブジェクトであることがわかっているため、それらを Page オブジェクトにキャスト バックしています。

取得する基準です

3)addAll すべての結果を追加するメソッドpages

于 2013-09-17T13:43:02.493 に答える