db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amarnath palavalli <pamarn...@gmail.com>
Subject To generate the Java OM classes from XML schema on the fly
Date Mon, 02 Mar 2009 15:09:05 GMT
Hello,

I am working on an application to use Torque to create XML schema from the
existing database and then generate the Java OM classes from this schema on
the fly. For this I don't want to use the Maven 2 build. Hence I referred to
your JUnit case TorqueOMMojoTest.java and tried something similar like this:

    private void test() throws Exception {
        TorqueJDBCTransformTask task = new TorqueJDBCTransformTask();
        task.setDbDriver("com.mysql.jdbc.Driver");
        task.setDbUrl("jdbc:mysql://127.0.0.1:3306/pump");
        task.setDbUser("user");
        task.setDbPassword("password");
        task.setDbSchema("pump");
        task.setSameJavaName(true);
        task.setOutputFile("test.xml");

        task.execute();

        System.out.println();

        //setupContainer();

        MavenProjectBuilder builder = (MavenProjectBuilder)
lookup(MavenProjectBuilder.ROLE);

 *       ArtifactRepositoryLayout localRepositoryLayout
        = (ArtifactRepositoryLayout) lookup(
                ArtifactRepositoryLayout.ROLE,
                "default");
*
        ArtifactRepository localRepository
                = new DefaultArtifactRepository(
                        "local",
                        "file://" + getBasedir() + File.separator
                            + "target/test-classes/repository",
                        localRepositoryLayout);

        MavenProject mavenProject = builder.buildWithDependencies(
                new File(
                    getBasedir(),

"target/test-classes/projects/TestJDBCtoXMLTransformationTask/pom.xml"),
                localRepository,
                null);


        OMMojo ommojo = new OMMojo();

ommojo.setContextPropertiesPath(mavenProject.getBuild().getDirectory()
                + "/torque/context.om.properties");
        ommojo.setOutputDir(mavenProject.getBuild().getDirectory()
                + "/generated-sources/torque");
        ommojo.setSchemaDir("");
        ommojo.setUseClasspath(true);
        ommojo.setBasePrefix("Base");
        ommojo.setSubpackageMap("map");

        ommojo.setTargetPackage("torque.test");

        ommojo.setSchemaIncludes("test.xml");

        ommojo.setSchemaExcludes("");

        ommojo.setReportFile("om.generation");

        ommojo.setBaseReportFile("om.base.generation");

        ommojo.execute();
    }

When I run the application I get the following exception:

-----------------------------------------------------
org.codehaus.plexus.component.repository.exception.ComponentLookupException:
Unable to lookup component 'org.apache.maven.project.MavenProjectBuilder',
it could not be started.
      role: org.apache.maven.project.MavenProjectBuilder
  roleHint: default
classRealm: plexus.core
    at
org.codehaus.plexus.DefaultComponentRegistry.getComponent(DefaultComponentRegistry.java:342)
    at
org.codehaus.plexus.DefaultComponentRegistry.lookup(DefaultComponentRegistry.java:163)
    at
org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:345)
    at org.codehaus.plexus.PlexusTestCase.lookup(PlexusTestCase.java:197)
    at
torque.tasks.TestJDBCtoXMLTransformationTask.test(TestJDBCtoXMLTransformationTask.java:33)
    at
torque.tasks.TestJDBCtoXMLTransformationTask.main(TestJDBCtoXMLTransformationTask.java:80)
Caused by:
org.codehaus.plexus.component.repository.exception.ComponentLifecycleException:
Error constructing component role:
'org.apache.maven.project.MavenProjectBuilder', implementation:
'org.apache.maven.project.DefaultMavenProjectBuilder', role hint: 'default'
    at
org.codehaus.plexus.component.builder.XBeanComponentBuilder.createComponentInstance(XBeanComponentBuilder.java:174)
    at
org.codehaus.plexus.component.builder.XBeanComponentBuilder.build(XBeanComponentBuilder.java:123)
    at
org.codehaus.plexus.component.manager.AbstractComponentManager.createComponentInstance(AbstractComponentManager.java:181)
    at
org.codehaus.plexus.component.manager.SingletonComponentManager.getComponent(SingletonComponentManager.java:67)
    at
org.codehaus.plexus.DefaultComponentRegistry.getComponent(DefaultComponentRegistry.java:327)
    ... 5 more
Caused by: org.apache.xbean.recipe.ConstructionException: Unable to convert
property value from
org.codehaus.plexus.component.builder.XBeanComponentBuilder$RequirementRecipe
to org.apache.maven.artifact.resolver.ArtifactResolver for injection
protected org.apache.maven.artifact.resolver.ArtifactResolver
org.apache.maven.project.DefaultMavenProjectBuilder.artifactResolver
    at
org.apache.xbean.recipe.ObjectRecipe.setProperty(ObjectRecipe.java:472)
    at
org.apache.xbean.recipe.ObjectRecipe.setProperties(ObjectRecipe.java:367)
    at
org.apache.xbean.recipe.ObjectRecipe.internalCreate(ObjectRecipe.java:282)
    at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:96)
    at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:61)
    at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:49)
    at
org.codehaus.plexus.component.builder.XBeanComponentBuilder.createComponentInstance(XBeanComponentBuilder.java:158)
    ... 9 more
Caused by: org.apache.xbean.recipe.ConstructionException: Composition failed
of field null in object of type
org.apache.maven.project.DefaultMavenProjectBuilder because the requirement
ComponentRequirement{role='org.apache.maven.artifact.resolver.ArtifactResolver',
roleHint='default', fieldName='null'} was missing)
    at
org.codehaus.plexus.component.builder.XBeanComponentBuilder$RequirementRecipe.internalCreate(XBeanComponentBuilder.java:380)
    at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:96)
    at org.apache.xbean.recipe.RecipeHelper.convert(RecipeHelper.java:167)
    at
org.apache.xbean.recipe.ObjectRecipe.setProperty(ObjectRecipe.java:466)
    ... 15 more
-----------------------------------------------------

I could generate the *test.xml* with the schema details of the existing
database.

I know the error is because it is not able to find the "default" artifact
repository layout. If anyone can provide information about how to solve this
issue then it would be of great help.

If you can suggest other alternative way of using the Torque to do the same
then it would be great.

Thank you,

Best Regards,
Amar

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message