@SuppressWarnings("unchecked")
 @Override
 public void modifying(ScalarEvent e) {
   FrozenLazyInitializerImpl declaring = FrozenLazyInitializerImpl.this;
   if (!declaring.disableTargetListener) {
     ObjectModelFactory<ObjectModel> omFactory = declaring.omFactory;
     LazyInitializer rawLazyInitializer = declaring.lazyInitializer;
     EventAttributeContext localAttributeContext = e.getAttributeContext(AttributeScope.LOCAL);
     if (rawLazyInitializer.isUninitialized()
         || omFactory.get(rawLazyInitializer.getImplementation()) != e.getSource()) {
       ((ObjectModel) e.getSource()).removeScalarListener(this);
       return;
     }
     localAttributeContext.addAttribute(AK_MODIFIYING_EXECUTED, true);
     if (e.getProperty() == declaring.objectModelMetadata.getEntityIdProperty()) {
       FrozenContext<Object> ctx = (FrozenContext<Object>) declaring.idFrozenContext;
       localAttributeContext.addAttribute(AK_FROZENCONTEXT, ctx);
       FrozenContext.suspendFreezing(ctx, declaring.owner);
     }
     ScalarListener scalarListener = declaring.scalarListener;
     if (scalarListener != null) {
       declaring.executeModifying(e.dispatch(declaring.omFactory.get(declaring.owner)));
     }
   }
 }
Ejemplo n.º 2
0
/** @author Tao Chen */
public class Employee {

  private static final ObjectModelFactory<OM> OM_FACTORY =
      ObjectModelFactoryFactory.factoryOf(OM.class);

  private OM om = OM_FACTORY.create(this);

  public Long getId() {
    return this.om.getId();
  }

  @SuppressWarnings("unused")
  private void setId(Long id) {
    this.om.setId(id);
  }

  public String getName() {
    return this.om.getName();
  }

  public void setName(String name) {
    this.om.setName(name);
  }

  public Department getDepartment() {
    return this.om.getDepartmentReference().get();
  }

  public void setDepartment(Department department) {
    this.om.getDepartmentReference().set(department);
  }

  public void clearDepartment() {
    this.om.getDepartmentReference().set(null);
  }

  @StaticMethodToGetObjectModel
  static OM om(Employee employee) {
    return employee.om;
  }

  @ObjectModelDeclaration(provider = "jpa")
  private interface OM {

    @EntityId
    Long getId();

    void setId(Long id);

    @Scalar
    String getName();

    void setName(String name);

    @Association(opposite = "employees")
    @Inverse
    Reference<Department> getDepartmentReference();
  }
}
Ejemplo n.º 3
0
/** @author Tao Chen */
public class Address {

  private static final ObjectModelFactory<OM> OM_FACTORY =
      ObjectModelFactoryFactory.factoryOf(OM.class);

  private OM om = OM_FACTORY.create(this);

  @StaticMethodToGetObjectModel
  static OM om(Address address) {
    return address.om;
  }

  public String getCity() {
    return om.getCity();
  }

  public void setCity(String city) {
    om.setCity(city);
  }

  public int getStreetNo() {
    return om.getStreetNo();
  }

  public void setStreetNo(int streeNo) {
    om.setStreetNo(streeNo);
  }

  @Override
  public String toString() {
    return "{ city: '" + this.getCity() + "', streetNo: " + this.getStreetNo() + " }";
  }

  @ObjectModelDeclaration(
      mode = ObjectModelMode.EMBEDDABLE,
      declaredPropertiesOrder = "city, streetNo")
  private interface OM {

    @Scalar
    String getCity();

    void setCity(String city);

    @Scalar
    int getStreetNo();

    void setStreetNo(int streeNo);
  }
}