1 Reply Latest reply on Nov 2, 2008 9:52 PM by Ilya

    Enumeration entities

    Ivan Pazmino Newbie

      Hi,


      I have a table in the database holding city codes and city names. How do i make a City enumeration with seam?


      I mean just making an enumeration that will auto-load once with the DB data, and after wars I can use the enumeration. Something like an entity-enumeration.


      I hope I explained myself, if not please let me know so I try it againg.


      Thanks in advance.


      IP

        • 1. Re: Enumeration entities
          Ilya Newbie

          just use a @Startup application scoped component to preload data like this:


          @Startup
          @Name("cityCache")
          @Scope(APPLICATION)
          public class CityCache {
            Map<String, City> cityByName;
          
            @Create
            public void preloadCities() {
              // populate cityByName map
            }
          
            public City findCity(String name) {
              return cityByName.get(name);
            }
          }
          



          this approach apparently requires some synchronisation, but i haven't yet read the docs up to that point :)