You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by wwwebi <ww...@hispeed.ch> on 2008/12/20 23:26:31 UTC

Support for MySQL 5.x VIEWs

Hi,

I was wondering how I can enable VIEWs for MySQL 5.x ?

As far as I can see in the adapter implementation of MySQL 
(org.apache.cayenne.dba.mysql.MySQLAdapter) the following code blocks 
the access to the views:

    /**
     * Returns null, since views are not yet supported in MySQL. Views 
are available on
     * newer versions of MySQL.
     */
    @Override
    public String tableTypeForView() {
        return null;
    }


would it allow views if this override would be deleted for MySQL 5.x ? 
Or would there be a need for another override ?

I want to access a legacy view by a named query but it does not work 
(xxxx not found).

Thanks for advice,
Martin

Re: Support for MySQL 5.x VIEWs

Posted by Andrus Adamchik <an...@objectstyle.org>.
The method that you've mentioned is only used during DB reverse  
engineering. So if you map a view as a regular DbEntity in the modeler  
yourself, running queries against the view should work just fine.

(we still need to update this method in the adapter, as most people  
are on MySQL 5 by now that supports views, so thanks for pointing it  
out).

Andrus

On Dec 21, 2008, at 12:26 AM, wwwebi wrote:

> Hi,
>
> I was wondering how I can enable VIEWs for MySQL 5.x ?
>
> As far as I can see in the adapter implementation of MySQL  
> (org.apache.cayenne.dba.mysql.MySQLAdapter) the following code  
> blocks the access to the views:
>
>  /**
>   * Returns null, since views are not yet supported in MySQL. Views  
> are available on
>   * newer versions of MySQL.
>   */
>  @Override
>  public String tableTypeForView() {
>      return null;
>  }
>
>
> would it allow views if this override would be deleted for MySQL  
> 5.x ? Or would there be a need for another override ?
>
> I want to access a legacy view by a named query but it does not work  
> (xxxx not found).
>
> Thanks for advice,
> Martin
>


Re: Database generation SQL script creation in background

Posted by Joe Baldwin <jf...@earthlink.net>.
Martin,

Good question (I usually use the modeler).

I could find no ant task that generates a sql script, but I did find

	http://cayenne.apache.org/doc30/cdbgen.html

which provides the capability to generate the actual DBMS-schema.  (I don't think this can be used to create a SQL file.)

Joe



On Aug 13, 2012, at 5:15 PM, Martin Weber wrote:

> Hi,
> 
> Is there a solution to create the database generation SQL script without starting the GUI modeler ? I would like to create the db generation script within an ant task or a shell/batch script.
> 
> Thanks,
> Martin


Re: Database generation SQL script creation in background

Posted by Joe Baldwin <jf...@earthlink.net>.
Martin,

Unless you are changing the DB Schema often, then you could another method is to export the SQL by saving a version via the modeler and then using an ant task to execute the sql (I use this method since I have different structures defined via my SQL files previously generated from the modeler):

<target name="load-struct" description="load DB struct only - no datafiles, image">
	<sql driver="${jdbc.driver}" url="${jdbc.url}" userid="${dbms.userid}" password="${dbms.password}" print="yes">
		<transaction src="${dataset.struct.dir}/struct.sql"/>
	</sql>
</target>

but the cdbgen method is more appropriate if the struct is changing.

Joe



On Aug 14, 2012, at 1:57 AM, Martin Weber wrote:

> Hi John,
> 
> main purpose is to make a fresh database installation during an automated nightly build. After the build I have scripts which create databases and then load data and run tests. The creation is only possible if I don't need a GUI. But I think the cdbgen ant task could be what I'm looking at.
> 
> Cheers,
> Martin
> 
> On 14.08.2012 05:38, John Huss wrote:
>> For what purpose?  What is your broader goal?  There are a few different
>> ways of creating the scheme using Cayenne.
>> 
>> John
>> 
>> On Monday, August 13, 2012, Martin Weber wrote:
>> 
>>> Hi,
>>> 
>>> Is there a solution to create the database generation SQL script without
>>> starting the GUI modeler ? I would like to create the db generation script
>>> within an ant task or a shell/batch script.
>>> 
>>> Thanks,
>>> Martin
>>> 
>> 
> 


Re: Database generation SQL script creation in background

Posted by Mike Kienenberger <mk...@gmail.com>.
If you want to do it from java code, this is how I used to set up test
databases in Cayenne 1.1.  It's probably slightly different now.

    public static void createSchemaForObjEntityName(Configuration
configuration, String objEntityName) throws Exception
    {
        DataNode dataNode =
getDataNodeForConfigurationAndObjEntityName(configuration,
objEntityName);

		DataSource dataSource = dataNode.getDataSource();
        DbAdapter dbAdapter = dataNode.getAdapter();
        Iterator dataMapIterator = dataNode.getDataMaps().iterator();
        while (dataMapIterator.hasNext())
        {
            DataMap dataMap = (DataMap) dataMapIterator.next();

            DbGenerator dbGenerator = new DbGenerator(dbAdapter, dataMap);
            boolean notCleanState = true;
//            if (CayenneTestDatabaseFramework.isHsqldbDriver())
//            {
//                // assume we're using the in-memory version
//                notCleanState = false;
//            }
            dbGenerator.setShouldDropTables(notCleanState);
            dbGenerator.setShouldDropPKSupport(notCleanState);
            dbGenerator.setShouldCreatePKSupport(true);
            dbGenerator.setShouldCreateTables(true);
            dbGenerator.setShouldCreateFKConstraints(false);
            dbGenerator.runGenerator(dataSource);
        }
    }

On Tue, Aug 14, 2012 at 1:57 AM, Martin Weber <ww...@hispeed.ch> wrote:
> Hi John,
>
> main purpose is to make a fresh database installation during an automated
> nightly build. After the build I have scripts which create databases and
> then load data and run tests. The creation is only possible if I don't need
> a GUI. But I think the cdbgen ant task could be what I'm looking at.
>
> Cheers,
> Martin
>
>
> On 14.08.2012 05:38, John Huss wrote:
>>
>> For what purpose?  What is your broader goal?  There are a few different
>> ways of creating the scheme using Cayenne.
>>
>> John
>>
>> On Monday, August 13, 2012, Martin Weber wrote:
>>
>>> Hi,
>>>
>>> Is there a solution to create the database generation SQL script without
>>> starting the GUI modeler ? I would like to create the db generation
>>> script
>>> within an ant task or a shell/batch script.
>>>
>>> Thanks,
>>> Martin
>>>
>>
>

Re: Database generation SQL script creation in background

Posted by John Huss <jo...@gmail.com>.
There are 2 existing ways of doing this, and one proposed one.  See here
for a comparison of the schema creation methods:
https://docs.google.com/document/d/1-ZGTCZdw5sksamJCKMT4bdw0zhrftKQptIgozk3ojbc/edit

The new proposed one is available in the sandbox here:
http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-migrations/

All of these are be something your java application does at startup time,
although if you really wanted a separate external process I'm sure you
could find a way.

John

On Tue, Aug 14, 2012 at 12:57 AM, Martin Weber <ww...@hispeed.ch> wrote:

> Hi John,
>
> main purpose is to make a fresh database installation during an automated
> nightly build. After the build I have scripts which create databases and
> then load data and run tests. The creation is only possible if I don't need
> a GUI. But I think the cdbgen ant task could be what I'm looking at.
>
> Cheers,
> Martin
>
>
> On 14.08.2012 05:38, John Huss wrote:
>
>> For what purpose?  What is your broader goal?  There are a few different
>> ways of creating the scheme using Cayenne.
>>
>> John
>>
>> On Monday, August 13, 2012, Martin Weber wrote:
>>
>>  Hi,
>>>
>>> Is there a solution to create the database generation SQL script without
>>> starting the GUI modeler ? I would like to create the db generation
>>> script
>>> within an ant task or a shell/batch script.
>>>
>>> Thanks,
>>> Martin
>>>
>>>
>>
>

Re: Database generation SQL script creation in background

Posted by Martin Weber <ww...@hispeed.ch>.
Hi John,

main purpose is to make a fresh database installation during an 
automated nightly build. After the build I have scripts which create 
databases and then load data and run tests. The creation is only 
possible if I don't need a GUI. But I think the cdbgen ant task could be 
what I'm looking at.

Cheers,
Martin

On 14.08.2012 05:38, John Huss wrote:
> For what purpose?  What is your broader goal?  There are a few different
> ways of creating the scheme using Cayenne.
>
> John
>
> On Monday, August 13, 2012, Martin Weber wrote:
>
>> Hi,
>>
>> Is there a solution to create the database generation SQL script without
>> starting the GUI modeler ? I would like to create the db generation script
>> within an ant task or a shell/batch script.
>>
>> Thanks,
>> Martin
>>
>


Re: Database generation SQL script creation in background

Posted by John Huss <jo...@gmail.com>.
For what purpose?  What is your broader goal?  There are a few different
ways of creating the scheme using Cayenne.

John

On Monday, August 13, 2012, Martin Weber wrote:

> Hi,
>
> Is there a solution to create the database generation SQL script without
> starting the GUI modeler ? I would like to create the db generation script
> within an ant task or a shell/batch script.
>
> Thanks,
> Martin
>

Database generation SQL script creation in background

Posted by Martin Weber <ww...@hispeed.ch>.
Hi,

Is there a solution to create the database generation SQL script without 
starting the GUI modeler ? I would like to create the db generation 
script within an ant task or a shell/batch script.

Thanks,
Martin