Skip to content

Latest commit

 

History

History
337 lines (259 loc) · 10.2 KB

File metadata and controls

337 lines (259 loc) · 10.2 KB

MetaObjects Dynamic Framework

Build Status: ✅ All Tests Passing | Migration Complete Maven Central: Maven Central License: License

🎯 Migration Status: Successfully migrated to MetaObjects Core 6.2.6+ 📊 Test Results: 40+ tests passing across all modules 🔧 Build Output: Optimized for clean, minimal console output

Overview

MetaObjects Dynamic Framework provides runtime object construction, data management, persistence, and web integration capabilities built on top of the MetaObjects Core metadata framework.

Key Features

🏗️ Dynamic Object Construction

  • DataObject: Runtime object construction with type-safe property access
  • ValueObject: Immutable value objects with builder patterns
  • Managed Objects: Database-mapped objects with automatic CRUD operations

🗄️ Persistence & Data Management

  • ObjectManager (OM): Abstract persistence layer
  • ObjectManagerDB (OMDB): SQL database persistence with automatic schema generation
  • ObjectManagerNoSQL (OMNOSQL): NoSQL database support (MongoDB, etc.)

🌐 Web Integration

  • MetaViews: Metadata-driven UI component generation
  • Spring Integration: Full Spring Boot and Spring Web support
  • REST APIs: Automatic REST controller generation

📱 Demo Application

  • FishStore Demo: Complete e-commerce application showcasing all features

Architecture

MetaObjects Dynamic extends the core metadata framework with runtime capabilities:

MetaObjects Core (metadata framework)
    ↓ depends on
MetaObjects Dynamic (runtime objects)
    ↓ used by
Your Application (business logic)

Quick Start

Maven Dependencies

<dependency>
    <groupId>com.metaobjects</groupId>
    <artifactId>metaobjects-dynamic-core</artifactId>
    <version>6.2.6-SNAPSHOT</version>
</dependency>

<!-- For database persistence -->
<dependency>
    <groupId>com.metaobjects</groupId>
    <artifactId>metaobjects-omdb</artifactId>
    <version>6.2.6-SNAPSHOT</version>
</dependency>

<!-- For web integration -->
<dependency>
    <groupId>com.metaobjects</groupId>
    <artifactId>metaobjects-web-spring</artifactId>
    <version>6.2.6-SNAPSHOT</version>
</dependency>

Basic Usage

1. Define Metadata

{
  "metadata": {
    "package": "com.example.model",
    "children": [
      {
        "object": {
          "name": "User",
          "subType": "managed",
          "children": [
            {"field": {"name": "id", "subType": "long"}},
            {"field": {"name": "name", "subType": "string", "@required": true}},
            {"field": {"name": "email", "subType": "string", "@required": true}},
            {"identity": {"name": "user_pk", "subType": "primary", "@fields": ["id"], "@generation": "increment"}}
          ]
        }
      }
    ]
  }
}

2. Create Runtime Objects

// Load metadata
MetaDataLoader loader = new FileMetaDataLoader();
loader.setSourceURIs(Arrays.asList(URI.create("classpath:metadata/model.json")));
loader.init();

// Get metadata for User
MetaObject userMeta = loader.getMetaObjectByName("User");

// Create a DataObject
DataObject user = new DataObject(userMeta);
user.setProperty("name", "John Doe");
user.setProperty("email", "john@example.com");

// Create a ValueObject (immutable)
ValueObject userValue = ValueObject.builder(userMeta)
    .property("name", "Jane Doe")
    .property("email", "jane@example.com")
    .build();

3. Database Persistence

// Setup database persistence
ObjectManagerDB omdb = new ObjectManagerDB();
omdb.setDataSource(dataSource);

// Create database schema automatically
MetaClassDBValidatorService validator = new MetaClassDBValidatorService();
validator.setObjectManager(omdb);
validator.setAutoCreate(true);
validator.init();

// Save objects
ObjectConnection connection = omdb.getConnection();
omdb.createObject(connection, user);

4. Web Integration (Spring)

@RestController
@RequestMapping("/api/users")
public class UserController {

    @Autowired
    private ObjectManagerDB omdb;

    @Autowired
    private MetaDataLoader loader;

    @GetMapping
    public List<DataObject> getUsers() {
        MetaObject userMeta = loader.getMetaObjectByName("User");
        return omdb.getAllObjects(userMeta);
    }

    @PostMapping
    public DataObject createUser(@RequestBody Map<String, Object> userData) {
        MetaObject userMeta = loader.getMetaObjectByName("User");
        DataObject user = new DataObject(userMeta);
        userData.forEach(user::setProperty);
        return omdb.createObject(user);
    }
}

Module Overview

Module Description Key Classes
dynamic Core dynamic object implementations DataObject, ValueObject
om Abstract object manager interface ObjectManager, ObjectConnection
omdb SQL database persistence ObjectManagerDB, MetaClassDBValidator
omnosql NoSQL database persistence MongoDBManager, ColumnarManager
web Web components and views MetaView, TextView, FormView
web-spring Spring framework integration MetaDataAutoConfiguration
demo FishStore demo application Complete e-commerce example

Advanced Features

Type-Safe Property Access

// Type-safe property access with validation
DataObject user = new DataObject(userMeta);
user.setStringProperty("name", "John Doe");
user.setLongProperty("id", 123L);

// Automatic validation based on metadata
user.setProperty("email", "invalid-email"); // Throws ValidationException

Automatic Database Schema Generation

// Automatic table creation from metadata
MetaClassDBValidatorService validator = new MetaClassDBValidatorService();
validator.setAutoCreate(true);
validator.init();

// Generates:
// CREATE TABLE users (
//   id BIGINT AUTO_INCREMENT PRIMARY KEY,
//   name VARCHAR(255) NOT NULL,
//   email VARCHAR(255) NOT NULL
// );

Metadata-Driven UI Components

// Automatic form generation from metadata
MetaViewRenderer renderer = new MetaViewRenderer();
String formHtml = renderer.renderForm(userMeta, user);

// Generates HTML form with proper validation, labels, and input types

Building from Source

git clone https://github.com/metaobjectsdev/metaobjects-dynamic.git
cd metaobjects-dynamic
mvn clean install

Build Features

  • Clean Output: Minimal console output for better readability
  • Fast Testing: Test output redirected to files for clean builds
  • JaCoCo Coverage: Optimized to avoid system package instrumentation warnings
# Standard clean build (quiet output)
mvn clean install

# Verbose output for debugging
mvn clean install -X

# Quick build with even less output
mvn clean install -q

Prerequisites

  • Java 17 or higher
  • Maven 3.6 or higher
  • MetaObjects Core 6.2.6+ (automatically resolved from Maven Central)

Migration Notes

Migration Complete: This project has been successfully migrated from the legacy core dependency structure to the updated MetaObjects Core 6.2.6+ framework. All modules are building and testing successfully.

Troubleshooting

Common Build Issues

🔧 Verbose Test Output

If you need verbose logging for debugging:

# Delete the test logging configuration
rm src/test/resources/logback-test.xml

# Or change log levels in the file from WARN to DEBUG

🔧 JaCoCo Instrumentation Warnings

The build is configured to exclude system packages. If you see warnings:

# These are normal and don't affect functionality:
# "WARNING: sun.misc.Unsafe::staticFieldBase has been called"

🔧 Type Registration Issues

If you encounter MetaData type registration problems:

  1. Ensure CoreObjectsMetaDataProvider is properly registered
  2. Check that DataMetaObject.registerTypes() and ValueMetaObject.registerTypes() are called
  3. Verify service files in META-INF/services/ are intact

🔧 Derby Database Test Failures

If OMDB tests fail with Derby driver issues:

<!-- Ensure all Derby artifacts are included -->
<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derbyshared</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derbytools</artifactId>
    <scope>test</scope>
</dependency>

Documentation

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for your changes
  5. Submit a pull request

Support

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Related Projects


MetaObjects Dynamic Framework - Bringing your metadata to life with runtime object construction and enterprise-grade persistence.