Discussion:
[Middlegen-user] Patch for Oracle Schema w/ middlegen
Matthias Flor
2002-08-27 14:56:01 UTC
Permalink
Hi,
this is for the oracle baseheads out there:
Whenever you set up a database-instance in Oracle it's a good practice
to create an own user for it. Let's say for the Airline-Sample you will
create the user airline. Like this:

create user airline identified by airline;
grant resource, connect, create public synonym, drop public synonym to
airline;
grant create role, alter any role, drop any role, grant any role to airline;
grant create user, alter user, drop user to airline;
grant create snapshot to airline;

With sqlplus can query the existing tables without the schema-prefix.

Run ant create-tables with the user airline.
Whether or not you have put schema=${database.schema} in the
sample-build file Middlegen tries to create Java-Files with the
Schema-Prefix (The table is named airline.persons instead of Persons for
example). The table columns won't be recognized either. You can work
around the former by editing the fields base-class-name in
src/airline.prefs. But you can't create useful Beans without the latter
case.

Thus, I would propose the following patch. It prohibits the reporting of
the oracle schema whenever a oracle database is used.

The drawback of this solution (workaround?) is that you must explicit
name the tables in the sample build-file.

I just posted this topic here to get to know if this patch is reasonable
or if there is a better solution. If it's reasonable I will submit the
patch at sf.

Cheers,
Matthias

--- middlegen-2002-08-26/src/java/middlegen/MiddlegenPopulator.java Mon Aug 26 12:00:33 2002
+++ middlegen-2002-08-26-patched/src/java/middlegen/MiddlegenPopulator.java Tue Aug 27 13:27:52 2002
@@ -96,6 +96,11 @@
private final Collection EMPTY_COLLECTION = new ArrayList(0);

/**
+
* This member gets true if a oracle database is used.
+
*/
+
private static boolean _oracleschema = false;
+
+
/**
* Get static reference to Log4J Logger
*/
private static org.apache.log4j.Category _log =
org.apache.log4j.Category.getInstance(MiddlegenPopulator.class.getName());
@@ -684,6 +689,7 @@

// null will also retrieve objects for which only synonyms exists, but
this objects will not

// be successfully processed anyway - did not check why -probably
columns not retrieved

_types = new String[]{"TABLE", "VIEW"};
+
_oracleschema = true;
}

// MSSQL TUNING
@@ -830,7 +836,7 @@
boolean nullschema = schema == null;
boolean nonameschema = schema.trim().equals("");
boolean alreadyschema = table.indexOf('.') != -1;
-
if (!nullschema && !nonameschema && !alreadyschema) {
+
if (!nullschema && !nonameschema && !alreadyschema && !_oracleschema) {

return schema + "." + table;
}
else {
Aslak Hellesøy
2002-08-27 17:23:02 UTC
Permalink
Hi.

A feature that *might* be useful for other databases than oracle should be
implemented as such.
How about adding an attribute to the middlegen task:

useschemaprefix="true|false"

If you set it to true: -> schema.table
If you set it to false: -> table

/Aslak
-----Original Message-----
Flor
Sent: 27. august 2002 18:55
Subject: [Middlegen-user] Patch for Oracle Schema w/ middlegen
Hi,
Whenever you set up a database-instance in Oracle it's a good practice
to create an own user for it. Let's say for the Airline-Sample you will
create user airline identified by airline;
grant resource, connect, create public synonym, drop public synonym to
airline;
grant create role, alter any role, drop any role, grant any role
to airline;
grant create user, alter user, drop user to airline;
grant create snapshot to airline;
With sqlplus can query the existing tables without the schema-prefix.
Run ant create-tables with the user airline.
Whether or not you have put schema=${database.schema} in the
sample-build file Middlegen tries to create Java-Files with the
Schema-Prefix (The table is named airline.persons instead of Persons for
example). The table columns won't be recognized either. You can work
around the former by editing the fields base-class-name in
src/airline.prefs. But you can't create useful Beans without the latter
case.
Thus, I would propose the following patch. It prohibits the reporting of
the oracle schema whenever a oracle database is used.
The drawback of this solution (workaround?) is that you must explicit
name the tables in the sample build-file.
I just posted this topic here to get to know if this patch is reasonable
or if there is a better solution. If it's reasonable I will submit the
patch at sf.
Cheers,
Matthias
---
middlegen-2002-08-26/src/java/middlegen/MiddlegenPopulator.java
Mon Aug 26 12:00:33 2002
+++
middlegen-2002-08-26-patched/src/java/middlegen/MiddlegenPopulat
or.java Tue Aug 27 13:27:52 2002
@@ -96,6 +96,11 @@
private final Collection EMPTY_COLLECTION = new ArrayList(0);
/**
+
* This member gets true if a oracle database is used.
+
*/
+
private static boolean _oracleschema = false;
+
+
/**
* Get static reference to Log4J Logger
*/
private static org.apache.log4j.Category _log =
org.apache.log4j.Category.getInstance(MiddlegenPopulator.class.getName());
@@ -684,6 +689,7 @@
// null will also retrieve objects for which only synonyms
exists, but
this objects will not
// be successfully processed anyway - did not check why -probably
columns not retrieved
_types = new String[]{"TABLE", "VIEW"};
+
_oracleschema = true;
}
// MSSQL TUNING
@@ -830,7 +836,7 @@
boolean nullschema = schema == null;
boolean nonameschema = schema.trim().equals("");
boolean alreadyschema = table.indexOf('.') != -1;
-
if (!nullschema && !nonameschema && !alreadyschema) {
+
if (!nullschema && !nonameschema && !alreadyschema &&
!_oracleschema) {
return schema + "." + table;
}
else {
-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone? Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Loading...