Exemple #1
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();
  }
}
Exemple #2
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);
  }
}
 @SuppressWarnings("unchecked")
 private void initTransient(Class<?> persistentClass) {
   LazyInitializer rawLazyInitializer = this.lazyInitializer;
   if (persistentClass == null) {
     persistentClass = getPersistentClass((BasicLazyInitializer) rawLazyInitializer);
   }
   HibernateObjectModelMetadata objectModelMetadata = HibernateMetadatas.of(persistentClass);
   this.objectModelMetadata = objectModelMetadata;
   this.omFactory =
       (ObjectModelFactory<ObjectModel>)
           ObjectModelFactoryFactory.factoryOf(objectModelMetadata.getObjectModelClass());
   try {
     this.getIdentifierMethod = (Method) GET_IDENTIFIER_METHOD_FIELD.get(rawLazyInitializer);
     this.setIdentifierMethod = (Method) SET_IDENTIFIER_METHOD_FIELD.get(rawLazyInitializer);
   } catch (IllegalArgumentException | IllegalAccessException e) {
     throw new AssertionError();
   }
   if (!rawLazyInitializer.isUninitialized()) {
     ObjectModel targetOM = this.omFactory.get(rawLazyInitializer.getImplementation());
     ScalarListener listener = this.new TargetScalarListener();
     targetOM.removeScalarListener(listener);
     targetOM.addScalarListener(listener);
   }
 }