Skip to main content

Home/ SoftwareEngineering/ Group items tagged builder

Rss Feed Group items tagged

kuni katsuya

A proper way for JPA entities instantiation « Paul Szulc's Blog - 0 views

  • A proper way for JPA entities instantiation
  • creating the entities I would like to focus in this post
  • JPA2.0 entities
  • ...31 more annotations...
  • UserService
  • UserDao
  • FacebookWS
  • User u
  • UserService uses UserDAO and FacebookWS
  • but don’t know how those dependencies are instantiated
  • And you shouldn’t really care, all that is important is that UserService depends on dao and webservice object.
  • BDD template given-when-then) tests are easy to read
  • @Entity
  • public class User
  • calling new User(“someName”,”somePassowrd”, “someOtherName”, “someOtherPassword”) becomes hardly readable and maintainable
  • code duplication
  • Maintaining this code would turn into a nightmare in no time
  • running the code above will throw an exception by the JPA provider,
  • since not-nullable password field was never set.
  • Joshua Blooch gives fine example of builder pattern.
  • Instead of making the desired object directly, the client calls a constructor (or static factory) with all of the required parameters and gets a builder object. Then the client calls setter-like methods on the builder object to set each optional parameter of interest. Finally, the client calls a parameterless build method to generate the object, which is immutable. The builder is a static member class of the class it builds.
  • Coffee
  • public static class Builder
  • Builder(CoffeeType type, int cupSize)
  • Builder withMilk()
  • Coffee build()
  • Coffee(this)
  • private Coffee(Builder builder)
  • Coffee coffee = new Coffee.Builder(CoffeeType.Expresso, 3).withMilk().build();2}
  • especially if most of those parameters are optional.
  • For all entity attributes I create private fields
  • those that are obligatory become parameters for the public constructor
  • parameter-less constructor, I create one, but I give him
  • protected access level
  • protected
kuni katsuya

Implementing the Builder Pattern using the Bean Validation API - Musings of a Programmi... - 0 views

  • invariants
  • customer's last name must not be null
  • must be between 3 and 80 characters long
  • ...23 more annotations...
  • @Size(min = 3, max = 80)
  • @NotNull
  • LastName
  • inner class Builder is in charge of creating Customer instances
  • mandatory fields – either primitive (e.g. id) or annotated with @NotNull (e.g. lastName) – are part of the builder's constructor
  • all optional fields setter methods on the builder are provided
  • newly created Customer instance is validated using the Validator#validate() method
  • impossible to retrieve an invalid Customer instance
  • extract the validation routine into a base class:
  • abstract class AbstractBuilder<T>
  • T build() throws ConstraintViolationException
  • protected abstract T buildInternal();
  • private static Validator validator
  • Concrete builder classes have to
  • extend AbstractBuilder
  • must implement the buildInternal() method:
  • Builder extends AbstractBuilder<Customer>
  • @Override protected Customer buildInternal()
  • Implementing the Builder Pattern using the Bean Validation API
  • variation of the Builder design pattern for instantiating objects with multiple optional attributes.
  • this pattern frees you from providing multiple constructors with the different optional attributes as parameters (hard to maintain and hard to read for clients)
  • or providing setter methods for the optional attributes
  • (require objects to be mutable, can leave objects in inconsistent state)
kuni katsuya

Item 2: Consider a builder when faced with many constructor parameters | Creating and D... - 1 views

  • Item 2: Consider a builder when faced with many constructor parameters
  •  
    "Item 2: Consider a builder when faced with many constructor parameters"
kuni katsuya

Getting Started · UnquietCode/Flapi Wiki - 0 views

  • UnquietCode / Flapi
  • Getting Started
  • include a block chain
  • ...29 more annotations...
  • builds what is called a descriptor
  • blocks
  • methods
  • Blocks can be reused by using their name later in a addBlockReference(...) method
  • block contains methods
  • block can in turn nest other blocks
  • last()
  • Invocation Tracking
  • allowed invocations:
  • any()
  • exactly(int x)
  • atLeast(int x)
  • atMost(int x)
  • uses to build the Java code model and generate the classes and interfaces of a builder
  • between(int x, int y)
  • last(Class c)
  • Creating a Descriptor
  • Flapi.builder()
  • setPackage(String)
  • setStartingMethodName(String)
  • setDescriptorName(String)
  • setReturnType(Class)
  • enableCondensedClassNames()
  • addMethod(...)
  • startBlock(...)
  • addBlockChain(...)
  • addBlockReference(...)
  • Implementing the Helpers
  • Flapi creates only the interfaces for the helpers
kuni katsuya

Adobe Community: Updated Groovy template for GraniteDS Builder (gas3) - 0 views

  • Updated Groovy template for GraniteDS Builder (gas3)
  • also stripped out the specialized GraniteDS datatypes in favor of the LCDS serialization convention that Adobe uses (i.e. a Java map should translate to an 'Object' type, a Java enum should translate to a 'String', and Java collections should always serialize as 'ArrayCollection')
  • didn't do a 'base' version and a version that doesnt get touched by the code generator, but you could easily do so by modifying this template
  • ...3 more annotations...
  • two versions
  • for Managed entities:
  • meant for non managed entities:
kuni katsuya

Dependency injection discourages object-oriented programming? @ Blog of Adam Warski - 0 views

  • Dependency injection discourages object-oriented programming?
  • if you’re using DI, and you have an X entity, do you have an XService or XManager with lots of method where X is the first argument?
    • kuni katsuya
       
      evidence of the anti-pattern of procedural design in a java ee6 cdi application
  • previous way is more procedural
    • kuni katsuya
       
      ie. ProductService.ship(Product,Customer)
  • ...12 more annotations...
  • service/manager is a set of procedures you can run, where the execution takes a product and a customer as arguments
  • better
  • OO approach
  • not saying that achieving the above is not possible with a DI framework
  • only that DI
  • encourages the ProductService approach
    • kuni katsuya
       
      well, dependency injection, but moreover, the soa approach to service design tends to force otherwise intelligent software engineers into doing procedural design the services just end up being bags of method calls that implement any type of behavior, with the domain objects or entity beans being reduced to mere data structures with little responsibility or behavior beyond persistence. (which, in this anti-pattern, is typically mostly provided by the repository or dao class! ie. domain object crud)
  • it’s just easier
    • kuni katsuya
       
      ... if you just blindly follow the anti-pattern, of course  ;)
  • many benefits
    • kuni katsuya
       
      with the procedural approach, you also cannot implement polymorphic behavior, for instance
  • builder
  • fluent interface
  • it’s not for small projects
    • kuni katsuya
       
      fuckwhat? small or big matters not. if di is applied poorly, regardless of project size, it's an anti-pattern! disregard these comments!
  • problems with DI frameworks:
    • kuni katsuya
       
      not sure i agree with these points, but will refuse in a later sticky note
kuni katsuya

Chris Kelly: Using generics with a fluent API - 0 views

  • Using generics with a fluent API
  • fluent API with builders
  • fluent interface is implemented by using method chaining to relay the instruction context of a subsequent call
kuni katsuya

fernandezpablo85/scribe-java · GitHub - 0 views

  • Configuring scribe
    • kuni katsuya
       
      fluent builder-style api
kuni katsuya

UnquietCode/Flapi · GitHub - 0 views

  • UnquietCode / Flapi
  • Flapi is an API generator for Java, which generates chained API's for improved fluency in your code
  • UnquietCode / Flapi
  • ...3 more annotations...
  • Flapi is an API generator for Java, which generates chained API's for improved fluency in your code
  • code generation utility for creating fluent API in Java
  • stable release
kuni katsuya

Chapter 15. Data Management - 0 views

  • Data Management
  • Tide provides an integration between the Flex/LCDS concept of managed entities and the server persistence context (JPA or Hibernate)
  • Tide maintains a client-side cache of entity instances and ensures that every instance is unique in the Flex client context
  • ...5 more annotations...
  • highly recommended to use JPA optimistic locking in a multi-tier environment (@Version annotation)
  • Tip The easiest and recommended way for getting Tide enabled managed entities is to generate them from Java classes with Gas3 or the GDS Eclipse builder using the tide="true" option.
  • In a typical Flex/app server/database application, an entity lives in three layers: the Flex client the Hibernate/JPA persistence context the database
  • only invariant is the id.
  • id reliably links the different existing versions of the entity in the three layers
kuni katsuya

Externalizing Service Configuration using BlazeDS and LCDS - 0 views

  • Externalizing Service Configuration using BlazeDS
  • RemoteObject
  • *when* the configuration of your services is being read.
  • ...26 more annotations...
  • application stops working when you move it to another server
  • project in Flex Builder
  • check “use remote object access service”
  • This adds a compiler argument pointing to the location of your
  • services-config.xml
  • -services
  • services-config.xml
  • When you then
  • compile
  • your application, the required
  • values
  • of services-config.xml are
  • baked into the SWF
  • read at
  • compile time
  • not at runtime
  • {server.name}
  • {server.port}
  • {context.root}
  • {server.name} and {server.port} are replaced at
  • server the SWF was loaded from
  • {context.root} is still substituted at
  • compile time
  • Flex SDK provides an API that allows you to configure your channels at runtime
  • number of ways you can pass values to a SWF at runtime
  • read a configuration file using HTTPService at application startup
kuni katsuya

15 Tips on JPA Rich Domain Modelling - Thinking In Objects - Not Mappings [For Greenfie... - 0 views

  • [For Greenfields]
  • Try to identify concepts and abstractions from the target domain. Use them as candidates for entities.
  • Do not obfuscate them with additional technical naming conventions like XYZEntity or "BOs".
  • ...10 more annotations...
  • Write unit tests
  • without involving the EntityManager
  • - Thinking In Objects
  • JPA Rich Domain Modelling
    • kuni katsuya
       
      strategy to use when less or unconstrained by legacy db schema baggage. ie. the *proper* and *ideal* way to model domain classes... using oo, not dumb structs!  :)
  • Build objects, not structs
  • Think about builders
  • Let the tool (JPA-provider) generate the DDL
    • kuni katsuya
       
      generated ddl can be optimized by hand if required
    • kuni katsuya
       
      eg. see step 12 below
  • Provide a lean facade/service layer
  • only contain crosscutting concerns
kuni katsuya

Quick start with GraniteDS | Granite Data Services - 0 views

  • install the GraniteDS wizard and builder plugins in Eclipse
  • graniteds-tide-cdi-jpa
  • you don’t need to have a Flex SDK installed as it will be retrieved from the Maven repository
  • ...12 more annotations...
  • 3 separate projects: a Java project, a Flex project and a Webapp project.
  • GraniteDS archetypes
  • archetypeGroupId: org.graniteds.archetypes archetypeVersion: 1.1.0.GA archetypeArtifactId:
  • Maven 3.x required
  • mvn archetype:generate    -DarchetypeGroupId=org.graniteds.archetypes    -DarchetypeArtifactId=graniteds-tide-spring-jpa-hibernate    -DarchetypeVersion=1.1.0.GA    -DgroupId=org.example    -DartifactId=springgds    -Dversion=1.0-SNAPSHOT
  • cd springgdsmvn clean package
  • build the project
  • CDI archetype requires a Java EE 6 server and uses an embedded GlassFish
  • cd webappmvn embedded-glassfish:run
  • With the Eclipse Maven integration (the M2E plugin), you can simply choose one of the archetypes when doing New Maven Project.
  • mvn war:war
  • two very easy ways to quickly create a new GraniteDS project
1 - 20 of 21 Next ›
Showing 20 items per page