Search the web
Sign In
New User? Sign Up
SimpleORM
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Newbie questions   Message List  
Reply | Forward Message #570 of 1847 |
Re: Newbie questions

Hi Andrea

Before we start make sure you are using my SQLDriver has the one that
is included with simpleorm has some bugs in it. Go in the files
sections for it. Replace the simpleorm one with this one.

1- How can I set a different jdbc driver for a database?

There are 2 ways of doing this.
a) Add a new Driver which Overloads SDriverMSSQL and returns your
identification string instead of weblogic. This might be the best way
because different drivers for the same database often behave
differently. It enables you to overload the methods with different
internal behavior. Also you dont change the SimpleORM code so that if
there is a version update you dont overwrite your code as you would
if you modified the core simpleorm code.

b) Specify driver upon SConnection.attach
with :
attach(Connection con, String connectionName, SDriver driver)
This way simpleorm will ignore the metaname of the driver. That way
you can even put the name of the driver you want in a configuration
file and load the driver at run time like your want.

2- I'm having problems in using SFieldReference for foreign keys.

Very easy to do :

public class Product extends SRecordInstance {
public static final SRecordMeta meta = new SRecordMeta
(Product.class, "Products");
public static final SFieldInteger PROD_ID = new SFieldInteger
(meta,"prod_id",SFD_PRIMARY_KEY);
public static final SFieldString DESCRIPTION = new SFieldString
(meta,"description",255,SFD_MANDATORY);
}

public class PHistory extends SRecordInstance {
public static final SRecordMeta meta = new SRecordMeta
(PHistory.class,"PHistory");
public static final SFieldInteger ID = new SFieldInteger
(meta,"id",SFD_PRIMARY_KEY,SFD_GENERATED_KEY);
public static final SFieldReference
(meta,Product.meta,"prod_",SFD_MANDATORY);
public static final SFieldString REASON = new SFieldString
(meta,"reason",255);
}

/* I added the SFD_GENERATED_KEY as an example though you didnt
mention that your key was generated */

Hope this helps,

Sylvain Hamel

--- In SimpleORM@yahoogroups.com, "Andrea Broglia" <andreab@d...>
wrote:
> Hi,
> I'm a new user of SimpleORM, and I've been having few problems:
>
> 1- How can I set a different jdbc driver for a database? In my case
I was
> using SQLServer as backend with the Microsoft jdbc driver
> (com.microsoft.jdbc.sqlserver.SQLServerDriver).
> To run the test (through the ant script), I've set my jdbc driver
in the
> build.xml file using:
> <property name="database.driver"
> value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
> Unluckily SimpleORM didn't pick that I was using SQLServer and used
the
> generic SDriver class, rather than the specific SDriverMSSQL.
> This resulted into some SQLException because SQLServer doesn't
support the
> "FOR UPDATE" statement.
> Looking at the source code I've noticed that the driver name is
somehow hard
> coded in the driver class (eg. SDriverMSSQL uses
> "weblogic.jdbc.mssqlserver4.Driver").
> I've then changed this value to "SQLServer" (that is the driver name
> returned by the Microsoft jdbc driver) in the SDriverMSSQL.java,
recompiled
> the lot and everything worked fine.
>
> ~~~~~~~ Code snippet ~~~~~~~~
> ...
> public class SDriverMSSQL extends SDriver {
> protected String driverName() {
> //Old value: return "weblogic.jdbc.mssqlserver4.Driver";
> return "SQLServer";
> }
> ...
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> I'm wondering if there is a more elegant and flexible way of doing
this,
> maybe through a configuration file.
>
>
> 2- I'm having problems in using SFieldReference for foreign keys.
> This is my scenario: I have a Products and a PHistory tables with
the
> following columns:
> Products:
> - prod_id (this is the PK of this table and FK for PHistory)
> - description
> PHistory:
> - id (this is the PK of this table)
> - replaced_by
> - reason
>
> I created a class to map the Products table, like:
> ~~~~~~ Code snippet ~~~~~~
> public class Product extends SRecordInstance
> implements Serializable {
>
> public static final SRecordMeta meta =
> new SRecordMeta(Product.class, "Products");
>
> public static final SFieldInteger PROD_ID =
> new SFieldInteger(meta, "prod_id", SFD_PRIMARY_KEY);
>
> ...
>
> public static void main(String[] args) {
> ...
> Product p = (Product)Product.meta.findOrCreate(new Integer(35));
> ...
> }
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Now, how can I extend this code and add a reference field to a
PHistory
> class?
> If I add a line like:
> public static final SFieldReference HIST =
> new SFieldReference(meta, PHistory.meta,
> new SFieldMeta[] {PROD_ID},
> new SPropertyValue[] {});
>
> I get an exception:
> java.lang.ExceptionInInitializerError
> Caused by: simpleorm.core.SException$Error: ???Inconsistent
Primary Key
> flags [FR Product._PHistory] vs [F Product.prod_id]
>
>
> Thanks in advance for your help,
> Andrea




Wed Sep 3, 2003 7:08 pm

sylvainhamel
Offline Offline
Send Email Send Email

Forward
Message #570 of 1847 |
Expand Messages Author Sort by Date

Hi, I'm a new user of SimpleORM, and I've been having few problems: 1- How can I set a different jdbc driver for a database? In my case I was using SQLServer...
Andrea Broglia
andrea_broglia
Offline Send Email
Sep 3, 2003
2:01 am

Hi Andrea Before we start make sure you are using my SQLDriver has the one that is included with simpleorm has some bugs in it. Go in the files sections for...
sylvainhamel
Offline Send Email
Sep 3, 2003
7:09 pm

Hi Sylvain, first of all, thanks for your help. ... Where exactly should I get the new file from? ... I've tried this solution but it doesn't work, because the...
Andrea Broglia
andrea_broglia
Offline Send Email
Sep 4, 2003
8:11 am

Hi Andrea, 1) For the updated driver look in the "Files" section. Look in the group menu on the left of the screen. 2) Forgot to mention it but should you...
sylvainhamel
Offline Send Email
Sep 4, 2003
2:00 pm

Hi Sylvain, 1) OK, I got it now. Originally I though that you were referring to a "files" section in the Simpleorm.org web site. Now I've realised that it's in...
Andrea Broglia
andrea_broglia
Offline Send Email
Sep 5, 2003
2:05 am

Hi again Andrea, 1) Sorry for the error there. This is because I am using SimpleORM through .NET and object has both an Equal method and an equal method (same...
sylvainhamel
Offline Send Email
Sep 5, 2003
2:29 pm

Hello Sylvain, I love what you hve done with .Net. I am revising SimpleORM now, and will add SThreadLocal and SArrayList. Will also use your new driver. I...
Melissa & Anthony Ber...
berglas@...
Send Email
Sep 7, 2003
10:42 pm

... Its always good to hear that your work is appreciated. As for the driver list. I have mixed feelings regarding this. Wouldnt it be better if we just...
sylvainhamel
Offline Send Email
Sep 8, 2003
2:18 pm

Hi I have been watching your efforts to get SimpleORM running with interest. 1) SimpleORM uses a very poor hard coded method of selecting a driver, which...
Richard Schmidt
informhandstrap
Offline Send Email
Sep 5, 2003
3:26 am

Hi, 1) I would suggest against using the version of attach in which you dont specify the driver. Instead use the version which enables you to specify the...
sylvainhamel
Offline Send Email
Sep 5, 2003
2:49 pm

Good point about the drivers, I've added comments. Foreign keys are inherintly tricky. But if somebody wants to add support for over lapping keys then great. ...
Melissa & Anthony Ber...
berglas@...
Send Email
Sep 6, 2003
11:24 pm

Hi Richard, thanks for your answer and suggestions. 1) I agree, as I pointed out in my first email, that probably a simple property file would be much easier...
Andrea Broglia
andrea_broglia
Offline Send Email
Sep 9, 2003
4:08 am

Hi Richard, another thing I found in your ColumnGenerate class: I had to change the line 102 from: if (sField.equalsIgnoreCase("SFieldDouble")) { return...
Andrea Broglia
andrea_broglia
Offline Send Email
Sep 9, 2003
7:06 am

Please send me the SQL that generated / defined this table. My 'test' database doesn't use doubles. Thanks Richard ... the ... to ... represent ... fully ... ...
Richard Schmidt
informhandstrap
Offline Send Email
Sep 9, 2003
8:12 pm

Hi Richard, in the test database created by SimpleORM, the class Employee creates a table XX_EMPLOYEE whose 'salary' column is a duoble. Cheers, Andrea...
Andrea Broglia
andrea_broglia
Offline Send Email
Sep 9, 2003
11:22 pm

Hi Thanks for the feedback. a) Schema and Catalogs are one of the things that vary between SQL databases. I generally use an Interbase database that requires a...
Richard Schmidt
informhandstrap
Offline Send Email
Sep 9, 2003
8:27 pm

Hi Richard, ... I think that the javadoc for java.sql.DatabaseMetaData.getTables() specifies that there is a difference between empty value and null for...
Andrea Broglia
andrea_broglia
Offline Send Email
Sep 10, 2003
12:28 am

... and ... Odd, when I ran it against a MS-SQL Server database I had to specify both the schema and catalog. It returned the user defined tables and the ...
Richard Schmidt
informhandstrap
Offline Send Email
Sep 10, 2003
12:49 am

Hi Richard, I'm also having some serious struggles understanding & getting SFieldReference class to work with my preexisting DB that has different field names...
Eric B.
ebenzacar
Offline Send Email
Oct 21, 2003
7:11 am

If you dont want to use the SFieldReference just use your foreign key as a SFieldInt (in your case). That way when you want to obtain a foreign reference you...
sylvainhamel
Offline Send Email
Oct 22, 2003
7:38 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help