Relational queries through JDBC with the help of Kodo's metadata for O/R mapping

Due to JDOQL's limitations (inability to express joins, when relationships
are not modeled as object references), I find myself needing to drop down to
expressing some queries in SQL through JDBC. However, I still want my Java
code to remain independent of the O/R mapping. I would like to be able to
formulate the SQL without hardcoding any knowledge of the relational table
and column names, by using Kodo's metadata. After poking around the Kodo
Javadocs, it appears as though the relevant calls are as follows:
ClassMetaData cmd = ClassMetaData.getInstance(MyPCObject.class, pm);
FieldMetaData fmd = cmd.getDeclaredField( "myField" );
PersistenceManagerFactory pmf = pm.getPersistenceManagerFactory();
JDBCConfiguration conf = (JDBCConfiguration)
((EEPersistenceManagerFactory)pmf).getConfiguration();
ClassResolver resolver = pm.getClassResolver(MyPCObject.class);
Connector connector = new PersistenceManagerConnector(
(PersistenceManagerImpl) pm );
DBDictionary dict = conf.getDictionary( connector );
FieldMapping fm = ClassMapping.getFieldMapping(fmd, conf, resolver, dict);
Column[] cols = fm.getDataColumns();
Does that look about right?
Here's what I'm trying to do:
class Foo
String name; // application identity
String bar; // foreign key to Bar
class Bar
String name; // application identity
int weight;
Let's say I want to query for all Foo instances for which its bar.weight >
100. Clearly this is trivial to do in JDOQL, if Foo.bar is an object
reference to Bar. But there are frequently good reasons for modeling
relationships as above, for example when Foo and Bar are DTOs exposed by the
remote interface of an EJB. (Yeah, yeah, I'm lazy, using my
PersistenceCapable classes as both the DAOs and the DTOs.) But I still want
to do queries that navigate the relationship; it would be nice to do it in
JDOQL directly. I will also want to do other weird-ass queries that would
definitely only be expressible in SQL. Hence, I'll need Kodo's O/R mapping
metadata.
Is there anything terribly flawed with this logic?
Ben

I have a one point before I get to this:
There is nothing wrong with using PC instances as both DAO and DTO
objects. In fact, I strongly recommend this for most J2EE/JDO design.
However, there should be no need to expose the foreign key values... use
application identity to quickly reconstitute an object id (which can in
turn find the persistent version), or like the j2ee tutorial, store the
object id in some form (Object or String) and use that to re-find the
matching persistent instance at the EJB tier.
Otherwise, there is a much easier way of finding ClassMapping instances
and in turn FieldMapping instances (see ClassMapping.getInstance () in
the JavaDocs).
Ben Eng wrote:
Due to JDOQL's limitations (inability to express joins, when relationships
are not modeled as object references), I find myself needing to drop down to
expressing some queries in SQL through JDBC. However, I still want my Java
code to remain independent of the O/R mapping. I would like to be able to
formulate the SQL without hardcoding any knowledge of the relational table
and column names, by using Kodo's metadata. After poking around the Kodo
Javadocs, it appears as though the relevant calls are as follows:
ClassMetaData cmd = ClassMetaData.getInstance(MyPCObject.class, pm);
FieldMetaData fmd = cmd.getDeclaredField( "myField" );
PersistenceManagerFactory pmf = pm.getPersistenceManagerFactory();
JDBCConfiguration conf = (JDBCConfiguration)
((EEPersistenceManagerFactory)pmf).getConfiguration();
ClassResolver resolver = pm.getClassResolver(MyPCObject.class);
Connector connector = new PersistenceManagerConnector(
(PersistenceManagerImpl) pm );
DBDictionary dict = conf.getDictionary( connector );
FieldMapping fm = ClassMapping.getFieldMapping(fmd, conf, resolver, dict);
Column[] cols = fm.getDataColumns();
Does that look about right?
Here's what I'm trying to do:
class Foo
String name; // application identity
String bar; // foreign key to Bar
class Bar
String name; // application identity
int weight;
Let's say I want to query for all Foo instances for which its bar.weight >
100. Clearly this is trivial to do in JDOQL, if Foo.bar is an object
reference to Bar. But there are frequently good reasons for modeling
relationships as above, for example when Foo and Bar are DTOs exposed by the
remote interface of an EJB. (Yeah, yeah, I'm lazy, using my
PersistenceCapable classes as both the DAOs and the DTOs.) But I still want
to do queries that navigate the relationship; it would be nice to do it in
JDOQL directly. I will also want to do other weird-ass queries that would
definitely only be expressible in SQL. Hence, I'll need Kodo's O/R mapping
metadata.
Is there anything terribly flawed with this logic?
Ben
Steve Kim
[email protected]
SolarMetric Inc.
http://www.solarmetric.com

Similar Messages

  • Transfer Of Data from Sap to Oracle with the help of Enterprise Services.

    Hello,
    We want to transfer data from Sap to Oracle using standard Enterprise Services.Some fields were not available in the existing standard Enterprise Services,so we have enhanced the existing Services by writing code inside BADI available with Enterprise Services.Rest of the fields we have mapped with the existing fields available in standard Enterprise Services.But,the Oracle people want to fetch all data from Sap without entering any input as a mandatory field in the Enterprise Services.The existing standard Enterprise Services require to enter any field as mandatory and are not accepting the range in input for multiple records.e.g.All enterprise Services related to Sales Orders are displaying only one sales Order.We have searched all Enterprise Services for Sales Order(related to reading of data),but not able to find service which would display mutiple records without entering any input.ECC_SALESORDER009QR is the only service which is displaying multiple records without entering any input,but the required fields are not available in this service.So,kindly suggest what we need to do further.
    1.Should we go for customization of services completely,so that it would fulfil our requirement.
    2.Are there  standard Enterprise Services exists which would we give us data in range(all records).
    If they exists,please specify the names of Services for reading Purchase Order,Production Order,BOM etc.
    Thanks & Regards,
    Divya.

    Hi Vaibhav,
    Let me tell you the objective in detail.
    Objective.
    To develop a package solution which will work as a bridge between Oracle APS and SAP system so that customers using SAP will be able to use advantages of Oracle APS for their planning needs.
    This will consist of following major components:
    OA Templates is an Oracle utility to load data from any legacy system to Oracle APS using standard flat files.
    Oracle has developed an Application Integration Architecture which is a standard architecture used for integration of Oracle products with other systems.
    Enterprise services is an SAP utility to communicate with SAP.
    AIA canonicals are standard canonicals developed by Oracle where we have to map data fields from destination system (Oracle APS) and source system (SAP)
    Fusion middleware is being used to develop application interfaces following AIA standards.
    Tasks at stake:
    Mapping of Oracle APS fields and SAP Enterprise Service fields to AIA canonicals
    Technical work of developing middleware using Oracle Fusion
    From Sap side,we have to map fields which we have received from Oracle with the help of Enterprise Services,rest  consumption of these services is done by Oracle guys.So,suggest is there enterprise services available which would give us multiple records .
    Thanks & Regards,
    Divya.

  • I want to pick the Exp.GL A/c of GRN with the help of IR Doc.(INv.Verifica)

    Dear All,
            CAn i know how can i pick the GL Account of GRN Doc.No.with the help of Invoice Doc.No.(Inv.Verification).From which table i can take these information.
    Please answer me immediately so that i can also reward point & the requirement is urgent.
    Best Regards,
    R.Rajakumaran

    Hi,
    Invoice you will have the Purchase Order no. Display the purchase order through ME23N and at the item details you can find the GRN No. Or double click on the purchasing doc no. system will display the PO.
    Thanks
    VK

  • Getting all types of files with the help of get_file_name function

    hi all,
    i am using Forms [32 Bit] Version 6.0.8.24.1 (Production).
    i have used get_file_name function to the file name of all type of files
    but i am able to get only the folders when i tried like below
    :FILE_NAME := GET_FILE_NAME(NULL,NULL,NULL,'Choose a Directory',OPEN_FILE,FALSE);my requirement to get all types of files on the window(user will selects whichever way he wants)
    Can i acheive it through get_file_name or i have to go for any alternative to get the file list, so that user can select by browsing the folders.
    Please help.
    Thanks..

    hi,
    in my code the select file was set to false(so showing only the directories) now i have set it to 'true'. its showing the files now.
    with the help of my above shown code i can get the full path of the file.
    is there any way to get only the file name?(other than the last occurance of '/' logic or that is only the way?)
    Please help.
    Thanks..

  • COST CENTRE EXPENSES WITH THE HELP OF COSP

    hi all,
        i have to make a report on cost centre expenses with the help table COSP.I have to put cost centre  from OBJNR in which last five haraters are cost centre and period like month  and year.After that in report display i want KSTAR i.e. in down the line and cost centres of selection in vertical it may increase or decrease depending on selection.After that i have to add all the WTG001-WTG016.if in seletion period is 1 to 2 then i have to add WTG001 and WTG002 in corresponding in KSTAR and so on in desired cost centre column below that facing respective KSTAR.If anyone can send any report relating that i will be thankful.
    Regards,
    Praveen

    Answered

  • Program related ENHANCEMENT-POINT/SECTION with the name LMEPOF8D_02 exists

    Hello
    In an upgrade, after finishing with the SPAU task we got the following error in the standard object LMEPOF8D:
    A program related ENHANCEMENT-POINT/SECTION with the name "LMEPOF8D_02" already exists.
    Anyone knows which cause could be generate this kind of error?
    Thanks in advance for your help
    Best Regards,
    Leonardo

    Hello Sandra,
    We have finished with SPAU. Regarding LMEPOF8D include, we kept with the ECC6 standard code. Therefore, from a point of view of code, it should be ok. However, we have this sintax error.
    As you said, the include contains the enhancement point LMEPOF8D_02 which generates the sintax error, but we couldn't find if this enhancement is used in another place.
    We also found note 1331844 and tried to fix the issue by using the 2nd solution propose in the note. But, it didn't work neither.
    Do you have any idea about what cause could generates this error?
    Thanks in advance for your support.
    Best Regards,
    Leonardo

  • I can't activate my programs even though I paid for a subscription.  I did a chat with the help desk and they didn't solve my problem.  I want to cancel my account.  Please contact me since the chat is down

    I can't activate my programs even though I paid for a subscription.  I did a chat with the help desk and they didn't solve my problem.  I want to cancel my account.  Please contact me since the chat is down

    Activating after a Find My iPhone lock bricks the device if you don't know the password used by Find My iPhone.
    Read through this article to find if your device has an activation lock.
    http://www.macworld.com/article/2048739/get-to-know-ios-7-activation-lock.html
    If this is what you have - the news is bad:
    http://www.cultofmac.com/246755/why-ios-7s-activation-lock-is-a-disaster-waiting -to-happen/

  • Using pc broadband internet in n85 with the help o...

    Hi,
    i have n85 and a pc broadband internet. i want share my pc internet in my N85 phone and laptop using wifi with the help of wireless router.Is it possible?????
    plz suggest what equipment i need to use my pc internet into my n85 using wifi.
    Solved!
    Go to Solution.

    You're going about it the wrong way.
    You should connect the wireless router to the internet and then let both the PC and the N85 connect to the router and gain access to the internet through it.
    The PC doesn't share the connection, the router does.
    Was this post helpful? If so, please click on the white "Kudos!" star below. Thank you!

  • Creation of report with the help of report painter

    Dear Experts,
                         I need report painter material, if any body have  pls  farward to me.
    my intension to create controlling report with the help of report painter.
    I am ready to award full points.
    Thanks in advance
    Regards
    avudaiappan
    Moderator - Please read this:
    /thread/931177 [original link is broken]
    Thread locked

    Hello Chinasammy,
    Report Painter allows you to create reports using data from SAP application components, which you can adapt to meet your individual requirements.
    Many of your reporting requirements can already be met by using the standard reports provided by various SAP application components. If these SAP standard reports do not meet your reporting needs, Report Painter enables you to define your specific reports quickly and easily.
    When executing a Report Painter report, it is displayed by the system in Report Writer format. You thus have access to the same functions as for Report Writer reports defined in the same way, and can combine Report Painter and Report Writer reports together in a report group.
    Report Painter uses a graphical report structure, which forms the basis for your report definition and displays the rows and columns as they appear in the final report output.
    To facilitate report definition, you can use many of the standard reporting objects provided by SAP (such as libraries, row/column models, and standard layouts) in your own specific reports. When you define a Report Painter report you can use groups (sets). You can also enter characteristic values directly.
    Advantages of Report Painter include:
    Flexible and simple report definition
    Report definition without using sets
    Direct layout control: The rows and columns are displayed in the report definition as they appear in the final report output, making test runs unnecessary.
    =============================================
    Below mentioned is the process for creating reports using Report Painter as a tool.
    Selecting and maintaining a library for your report: As the transfer structure to Report Painter you use a report table, which is defaulted by SAP and can not be maintained. This table contains characteristics, key figures and predefined columns. In a library, you collect the characteristics, key figures, and predefined columns from the report table, which you need for your Report Painter reports.
    When you define a Report Painter report, you assign it to a library. Reports assigned to one library can only use the characteristics, key figures, and predefined columns selected for that library.
    When you create or maintain a library, the Position field determines the sequence in which the characteristics, key figures or (predefined) key figures appear in the Report Painter selection lists when you define a report. This allows you to position the objects that you use regularly in your reports at the beginning of the selection lists. If you do not make an entry in the Position field, you will not be able to use this object in Report Painter reports.
    You can use either the standard SAP libraries for your reports or define your own.
    (ii) Selecting or maintaining a standard layout for your report: Standard layouts determine report layout features and the format of your report data.If the SAP standard layouts do not meet your reporting requirements, you can create a new  standard layout or change an existing one.
    (iii) Defining row and column models: A model is a one-dimensional, predefined reporting structure that you can insert in either the rows or columns of your report.If you often use the same or similar row or column definitions in your reports, it is recommended that you create row or column models.
    You must define the row and/or column models that you want to include in your report definition before you define the report.
    You can also use the standard column models supplied by SAP.
    (iv) Defining the report: Defining a Report Painter report involves the following steps.
    (a) Define the report columns: You define the report columns using the characteristics, key figures, and predefined columns selected for the library that the report uses. Alternatively, you can use a column model for column definition. Column models are predefined column structures which you insert into your entire column definition, instead of defining each individual column.
    (b) Define the report rows: You define the report rows using the characteristics selected for the library selected for the report.
    Alternatively, you can use a row model for your row definition. Row models serve the same purpose as column models, but are used to define a report row.
    Edit and format the report rows and columns in line with your requirements. (For example, you can hide rows or columns, define the column width or define colors for your report rows).
    (iii)Define general data selection criteria for the selection of your report data: Selection criteria are the characteristics used to select data for the entire report. You cannot enter characteristics as data selection criteria if they are already being used in the report rows or columns.
    (iv) Assigning the report to a report group: Once you have defined a report, you must assign it to a report group. A report group can contain one or more reports from the same library. However, reports that share the same data will select data more quickly and improve processing time.
    Hopw this helps you. Please let me know if you need anything more and assign points.
    Rgds
    Manish

  • Custom report templates with the help of BI Publisher.

    Hi All,
    I have created custom report templates with the help of BI Publisher it is working as we excepted.
    refered : https://blogs.oracle.com/kyle/tags/reports
    But our requirement want to change the color of heading and include filters in output report, It is possible, if yes pls share you comments?
    Best Regards
    Pradeep

    how silly of me!
    just restarting the tomcat sorted the problem!!!

  • Replication of Berkeley DB Xml Edition with the help of JAVA API

    hi,
    i am trying to replicate berkeley DB to 2 other replicas.with the help of small program which along with its documentation(of chapter 3). And i'm using java API for the same(specifically replication framework program.)
    All necessary files are get created at host side like log files, dll files, db files. But at replica(client) side nothing get created. Host and clients are placed in the same network.
    But unfortunately its not working. don't know the reason. And its not giving any sort of error. And i dont know how to go ahead. Or is there any other way should i proceed with.
    So could you help me out to get rid of this problem.
    Thanks

    What compiler are you running?
    See this message and thread:
    Re: Problem after update to 2.3.8
    It may be necessary to apply the -fno-strict-aliasing flag to the Berkeley DB Java library as well.
    Regards,
    George

  • Hi...i bought the new iphone 4 and would like to ask how can i transfer all my data from my old iphone to the new one?  If I will do "synchronization" through itunes with the old phone and the plug in the new one will that be the case?

    Hi...i bought the new iphone 4 and would like to ask how can i transfer all my data from my old iphone to the new one?  If I will do "synchronization" through itunes with the old phone and the plug in the new one will that be the case?

    Follow the instructions in this article to transfer your info: iPhone: Transferring information from your current iPhone to a new iPhone

  • I had to restore all the files on my pc using carbonite.  I reinstalled iTunes and was able to find my music with the help of Apple support.  How do I find my podcasts?

    I had to restore all the files on my pc using carbonite.  I reinstalled iTunes and was able to find my music with the help of Apple support.  How do I find my podcasts?

    This helped, I restored them, but when I go to iTunes they are not there.    Is there another step?

  • With the help of script i want to identify each and every thing in a indesign file

          i want to identify the each and every thing in a .indd file with help of script.and also i have to find totally how many farmes or things present in that file
    kindly guys help me out.
    and also suggest me some ideas.
    thanks in advance
    regards,
    siv 

    thanks ya...
    Actually my recuirment is there will be so many number of frame or text frame will present there in a indd file
    >with the help script im giving number to the script label . it follows the order of Stack
    (the frame designed latest will get the latest script label)
    >in a particular order the frame has to get numbered in script label
    i.e
    either from right to left or left to right.
    hope u got my point
    kindly help me out
    regards siv

  • I've installed windows 7 with the help of bootcamp on my macbook pro 2011. Please help me how to install mac drivers for windows7 64 bit???

    I've installed windows 7 with the help of bootcamp on my macbook pro 2011.
    Please help me how to install mac drivers for windows7 64 bit???

    You either download drivers from within Boot Camp Assistant and save to USB FAT disk, or you insert and use 10.6.x OS X DVD when in Windows and install and run the SETUP from there.
    General Help:
    Boot Camp 4.0, OS X Lion: Frequently asked question
    http://support.apple.com/kb/HT4818
    http://manuals.info.apple.com/en_US/boot_camp_install-setup_10.7.pdf
    create a Windows support software (drivers) CD or USB storage media
    http://support.apple.com/kb/HT4407
    Installation Guide   Instructions for all features and settings.
    Boot Camp 4.0 FAQ   Get answers to commonly asked Boot Camp questions.
    Windows 7 FAQ   Answers to commonly asked Windows 7 questions.
    - support articles and tips, how to.
    http://www.apple.com/support/bootcamp/
    Macs that work with 64-bit editions of Microsoft Windows Vista and Windows 7
    http://support.apple.com/kb/HT1846
    Step 4: Install the Boot Camp Drivers for Windows
    After installing Windows, install Mac-specific drivers and other software for Windows using your Mac OS X installation disc.  The Mac OS X disc installs drivers to support Mac components, including AirPort,built-in iSight camera, the Apple Remote, the trackpad on a portable Mac, and thefunction keys on an Apple keyboard. 
    The Mac OS X disc also installs the Boot Camp control panel for Windows and theApple Boot Camp system tray item.
    To install the Boot Camp drivers:
    1 Eject the Windows installation disc.
    2 Insert the Mac OS X disc.  If the installer doesn’t start automatically, browse the disc using Windows Explorerand double-click the setup.exe file in the Boot Camp directory.
    3 Follow the onscreen instructions.
    If a message appears that says the software you’re installing has not passed Windows  Logo testing, click Continue Anyway.
    Windows that appear only briefly during the installation don’t require your input.
    If nothing appears to be happening, there may be a hidden window that you mustrespond to. Check the taskbar and look behind open windows.
    Important: Do not click the Cancel button in any of the installer dialogs.
    4 After your computer restarts, follow the instructions in the Found New Hardware  Wizard to update your software drivers (Windows XP only).
    5 Follow the instructions for any other wizards that appear.
    6 Check for updated Boot Camp drivers by using Apple Software Update or going to www.apple.com/support/bootcamp.
      If You Have Problems Installing the Device Drivers 
    If it appears that the Boot Camp drivers weren’t successfully installed, try repairing them.
    To repair Boot Camp drivers:
    1 Start up your computer in Windows.
    2 Insert your Mac OS X installation disc.
    3 If the installer doesn’t start automatically, browse the disc using Windows Explorerand double-click the setup.exe file in the Boot Camp directory.
    4 Click Repair and follow the onscreen instructions.
    If a message appears that says the software you’re installing has not passed Windows  Logo testing, click Continue Anyway. 
    If you need to reinstall specific drivers, you can install one driver at a time. For example,if your built-in iSight camera isn’t working, you can reinstall just the iSight driver.
    Individual drivers are in the Drivers folder on the Mac OS X installation disc.

Maybe you are looking for