Tomislav Capan - Muzika Hr Dodatak Primjeri (IT Showoff)

626 views

Published on

Primjeri iz predavanja Tomislava Capana

Published in: News & Politics, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
626
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Tomislav Capan - Muzika Hr Dodatak Primjeri (IT Showoff)

  1. 1. © Copyright Muzika.hr 2010.<br />IT ShowOff – Dodatak- Primjeri -<br />12. veljače 2010.<br />
  2. 2. NHibernate<br />© Copyright Muzika.hr 2010.<br />2<br />
  3. 3. © Copyright Muzika.hr 2010.<br />3<br />NHibernate- Primjer mapiranja objekta -<br />namespace MuzikaHr.Core.Model<br />{<br /> public class City<br /> {<br /> /// <summary>Protected constructor. Used internally by NHibernate.</summary><br /> protected City() { }<br /> public City(int id) { Id = id; }<br />protectedvirtual int Id { get; set; }<br /> public virtual string Name { get; set; }<br /> public virtualRegionAssociatedRegion { get; set; }<br /> public virtual IList<EventLocation> EventLocations { get; protected set; }<br /> // -- domain logic methods here...<br /> }<br />}<br />
  4. 4. © Copyright Muzika.hr 2010.<br />4<br />NHibernate- Primjer mapiranja objekta -<br /><?xml version="1.0" encoding="utf-8" ?><br /><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"><br /><class name=“MuzikaHr.Core.Model.City, MuzikaHr.Core" table="grad" lazy="true"><br /><idname="Id" column="sifGrad"><br /> <generator class="native" /><br /></id><br /><propertyname="Name" column="imeGrad"/><br /><many-to-onename="AssociatedRegion" column="sifRegija"<br /> class="MuzikaHr.Core.Model.Region, MuzikaHr.Core” /><br /><bagname="EventLocations" table="eventLocation" inverse="true" cascade="none"><br /><keycolumn="cityId"/><br /><one-to-many class="MuzikaHr.Core.Model.EventLocation, MuzikaHr.Core" /><br /></bag><br /></class><br /></hibernate-mapping><br />
  5. 5. © Copyright Muzika.hr 2010.<br />5<br />NHibernate- Primjer dohvata podataka -<br />namespace MuzikaHr.Data.NHibernate<br />{<br /> public class CityDao : AbstractNHibernateDao<City, int>, ICityDao<br /> {<br /> // -- constructor here<br />public List<City> GetCitiesByRegion(int regionId)<br />{<br /> ICriteria criteria = NHibernateSession.CreateCriteria(typeof(City))<br />.Add(Expression.Eq("AssociatedRegion.Id", regionId))<br />.AddOrder(Order.Asc("Name"));<br /> try { return criteria.List<City>() as List<City>; }<br /> catch (HibernateException exc) {...}<br />}<br /> }<br />}<br />
  6. 6. SparkViewEngine<br />© Copyright Muzika.hr 2010.<br />6<br />
  7. 7. © Copyright Muzika.hr 2010.<br />7<br />SparkViewEngineViewData Dictionary, lokalne varijable<br />Template:<br /><s:viewdataArticles="IList[[MuzikaHr.Models.Article]]"/><br /><s:varstyles="new[] {‘left',’right'}"/><br /><ps:each="var article in Articles"<br />class="${styles[articleIndex%2]}“>${article.Title}<br /></p><br />Rezultat:<br /><p class="left">Vangelis</p><br /><p class="right">Simple Minds</p><br /><p class="left">The Stranglers</p><br /><p class="right">Michael Jackson (1958.–2009.)</p><br /><p class="left">A Perfect Circle</p><br /><p class="right">Suede (1989.–2003.)</p><br />
  8. 8. © Copyright Muzika.hr 2010.<br />8<br />SparkViewEngineIterator (for-each), if-clause<br />automatske iterator-varijable: Index, Count, IsFirst, IsLast<br />Template:<br /><s:foreach="var lineItem in CurrentInvoice.LineItems"><br /><tr><td>Item ${lineItemIndex + 1} of ${lineItemCount}</td><br /> <td>${lineItem.Etc}</td></tr><br /><trs:if="lineItemIsLast"><td>Grand total</td><td>${grandTotal}</td></tr><br /></s:for><br />Rezultat:<br /><tr><td>Item 1 of 14</td><td>5</td></tr><br /><tr><td>Item 2 of 14</td><td>2</td></tr><br /><tr><td>Item 3 of 14</td><td>9</td></tr><br />...<br /><tr><td>Item 14 of 14</td><td>14</td></tr><br /><tr><td>Grand total</td><td>97</td></tr><br />
  9. 9. © Copyright Muzika.hr 2010.<br />9<br />SparkViewEngineConditional attribute output<br />Template:<br /><s:viewdatafeaturedHeading=“MuzikaHr.Models.Heading"/><br /><s:viewdataHeadings=“IList[[MuzikaHr.Models.Heading]]"/><br /><ul><br /><lis:each="var heading in Headings"><br /><a ... class="selected?{heading.Id==featuredHeading.Id}">${heading.Name}</a><br /><li><br /></ul><br />Rezultat:<br /><ul><br /> <li><a href="...">Sve</a></li><br /> <li><a href="...">Interview</a></li><br /> <li><a href="..."class="selected">Biografije</a></li><br /> <li><a href="...">B Scena</a></li><br /> <li><a href="...">Zanimljivosti</a></li><br /></ul><br />
  10. 10. © Copyright Muzika.hr 2010.<br />10<br />SparkViewEngine: Macro<br />Macro helper function:<br />Metoda koja prima argumente i kao rezultat vraća string<br />Macro definicija:<br /><s:macro name="ShowError"caption="string" message="string"><br /><div class="message error"><br /> <h3>${caption}</h3><br /> <div>${message}</div><br /> <% logger.Warn(caption); %><br /></div><br /></s:macro><br />Macro poziv iz templatea:<br /><s:viewdataerrorMessage="string" /><br /><h2>Place Order</h2><br /><s:test if="!string.IsNullOrEmpty(errorMessage)"><br />${ShowError("Failed to place order", errorMessage)}<br /></s:test><br />...<br />

×