Large array of objects/multiple types in an array

I've been working on a program over the last several months, and I am bothered because I am using an two-dimensional array containing multiple types. A visual representation is as follows:
______label1 label2 label3
label 1 Int Int Int
label 2 Int Int Int
label 3 Int Int Int
The labels are strings, Int represents a numeric value representing a relationship between labelx and labely. Ultimately with the dataset I'm working with, there are hundreds of rows and columns. To complicate matters, I've been putting summary data (e.g. an average) at the end of each row and column to sort the whole thing.
Because this data structure mirrors the ultimate output--a matrix in text file--it is appealing. But it also violates the rule of only having one datatype in an array. Currently it is declared as Object[][], which gives me the flexibility I need. I can think of other solutions, but they are not as intuitive and seem needlessly complex.
Any thoughts?
Thanks.

I'd be thinking of writing a class that represents the data (labels, values and calculated summaries). Perhaps using one of the already existing implementations of TableModel.
Because this data structure mirrors the ultimate output--a matrix in text file--it is appealing. Perhaps the appeal is deceptive. Outputting the data to a file is, presumably, only one of the things you are going to do with it. The methods of a class written to represent this data can model the actual behaviour of the data, something beyond the capacities of the jack-of-all-trades array.
But it also violates the rule of only having one datatype in an array. Currently it is declared as Object[][], which gives me the flexibility I need. Of course I have no idea of the flexibility you need. (Or what imposes this constraint.) But I would consider it more flexible if I were able to change the actual implementation later - without affecting the code that uses this data. For instance if the data were to grow truely huge I might want to obtain it from a database and never have the whole thing in memory at once (whether as an array or any other way). Or I could desire the data to be obtained from sources on the internet via a URL. Or I could learn more about Collections and end up considering their utility methods of such great value that the array based implementation should give way.
---Edited by: pbrockway2 on Apr 20, 2008 1:07 PM
The point is that a MyTableModel type (especially if it were an interface) would enable users of the data to keep on doing whatever they needed to with the data (including saving it to file). While the actual implemention could change: double array one day, Lists the next, a database after that, user interaction via a JTable...
I can think of other solutions, but they are not as intuitive and seem needlessly complex.Try them, compare them.
Bear in mind that one's intuitions and needs are apt to change.

Similar Messages

  • How to add new elements in an array of Objects of Type Figure??

    I have a Figure class which has many attributes(variables). Then I create an array of Figures for example
    Figs[] figures = new Figure[18];
    Later I need to add new Figures to this array at different positions. In my case I have to use the same array.
    Is there any way so I can add new Figure elements to this array??
    If u have an answer to this question, please share with me.
    Thanks
    Amit

    There are many ways to solve this problem, including creating new arrays as needed, and using System.arraycopy() to move things around. However, the best way is to use ArrayList, as discussed above.
    What you cannot do is use toArray() and cast back to String[]. Object[] is not a subclass of String[], even if all of the objects in the Object[] are Strings!
    There are two ways to get around this. Create a String[] and copy the Object[] into it with System.arraycopy, or the easy way, which is to use the toArray(Object[]) method. It allows you to specify by example the array class you wish returned. If the array is large enough, it will populate the array directly, otherwise it will create a new one of the same base class. That means any of the following approaches will work, the final decision is mostly a matter of style:
        // create a zero length array to pass as an exemplar
        public final static String STRING_ARRAY_TYPE[]  new String[0];
        String s[] = (String[]) a.toArray(STRING_ARRAY_TYPE);Or:
        String t[] = new String[a.size()];
        a.toArray(t);Or:
        String t[] = a.toArray(new String[a.size()]);;I prefer the first approach generally, and it avoids any race conditions between the evaluation of the ArrayList size and the toArray; however, since ArrayList methods are not synchronized, you probably should do some synchronizing of your own.
    Hope this helps.

  • Trying to send multiple types in a byte array -- questions?

    Hi,
    I have a question which I would really appreciate any help on.
    I am trying to send a byte array, that contains multiple types using a UDP app. and then receive it on the other end.
    So far I have been able to do this using the following code. Please note that I create a new String, Float or Double object to be able to correctly send and receive. Here is the code:
    //this is on the client side...
    String mymessage ="Here is your stuff from your client" ;
    int nbr = 22; Double nbr2 = new Double(1232.11223);
    Float nbr3 = new Float(8098098.809808);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(mymessage);
    oos.writeInt(nbr);
    oos.writeObject(nbr2);
    oos.writeObject(nbr3);
    oos.close();
    byte[] buffer = baos.toByteArray();
    socket.send(packet);
    //this is on the server side...
    byte [] buffer = new byte [5000];
    String mymessage = null; int nbr = 0; Double nbr2 = null;
    Float nbr3 = null;
    mymessage = (String)ois.readObject();
    nbr = ois.readInt();
    nbr2 = (Double) ois.readObject();
    nbr3 = (Float) ois.readObject();
    My main question here is that I have to create a new Float and Double object to be able to send and receive this byte array correctly. However, I would like to be able to have to only create 1object, stuff it with the String, int, Float and Double, send it and then correctly receive it on the other end.
    So I tried creating another class, and then creating an obj of this class and stuffing it with the 4 types:
    public class O_struct{
    //the indiv. objects to be sent...
    public String mymessage; public int nbr; public Double nbr2;
    public Float nbr3;
    //construct...
    public O_struct(String mymessage_c, int nbr_c, double nbr2_c, float nbr3_c){
    my_message = my_message_c;
    nbr = nbr_c;
    nbr2 = new Double(nbr2_c);
    nbr3 = new Float(nbr3_c);
    Then in main, using this new class:
    in main():
    O_struct some_obj_client = new O_struct("Here is your stuff from your client", 22, 1232.1234, 890980980.798);
    oos.writeObject(some_obj_client);
    oos.close();
    send code....according to UDP
    However on the receiving side, I am not sure how to be able to correctly retrieve the 4 types. Before I was explicitely creating those objects for sending, then I was casting them again on the receiving side to retrieve then and it does work.
    But if I create a O_struct object and cast it as I did before with the indiv objects on the receiving end, I can't get the correct retrievals.
    My code, on the server side:
    O_struct some_obj_server = new O_struct(null, null, null. null);
    some_obj_server = (O_struct)ois.readObject();
    My main goal is to be able to send 4 types in a byte array, but the way I have written this code, I have to create a Float and Double obj to be able to send and receive correctly. I would rather not have to directly create these objects, but instead be able to stuff all 4 types into a byte array and then send it and correctly be able to retrieve all the info on the receiver's side.
    I might be making this more complicated than needed, but this was the only way I could figure out how to do this and any help will be greatly appreciated.
    If there an easier way to do I certainly will appreciate that advise as well.
    Thanks.

    public class O_struct implements Serializable {
    // writing
    ObjectOutputStream oos = ...;
    O_struct struct = ...;
    oos.writeObject(struct);
    // reading
    ObjectInputStream ois = ...;
    O_struct struct = (O_struct)ois.readObject();
    I will be sending 1000s of these byte arrays, and I'm sure having to create a new Double or Float on both ends will hinder this.
    I am worried that having to create new objs every time it is sending a byte array will affect my application.
    That's the wrong way to approach this. You're talking about adding complexity to your code and fuglifying it because you think it might improve performance. But you don't know if it will, or by how much, or even if it needs to be improved.
    Personally, I'd guess that the I/O will have a much bigger affect on performance than object creation (which, contrary to popular belief, is generally quite fast now: http://www-128.ibm.com/developerworks/java/library/j-jtp01274.html)
    If you think object creation is going to be a problem, then before you go and cock up your real code to work around it, create some tests that measure how fast it is one way vs. the other. Then only use the cock-up if the normal, easier to write and maintain way is too slow AND the cock-up is significantly faster.

  • Another question?? being able to send byte arrays containing multiple types

    Hi,
    I have a question which I would really appreciate any help on.
    I am trying to send a byte array, that contains multiple types using a UDP app. and then receive it on the other end.
    So far I have been able to do this using the following code. Please note that I create a new String, Float or Double object to be able to correctly send and receive. Here is the code:
    //this is on the client side...
    String mymessage ="Here is your stuff from your client" ;
    int nbr = 22; Double nbr2 = new Double(1232.11223);
    Float nbr3 = new Float(8098098.809808);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(mymessage);
    oos.writeInt(nbr);
    oos.writeObject(nbr2);
    oos.writeObject(nbr3);
    oos.close();
    byte[] buffer = baos.toByteArray();
    socket.send(packet);
    //this is on the server side...
    byte [] buffer = new byte [5000];
    String mymessage = null; int nbr = 0; Double nbr2 = null;
    Float nbr3 = null;
    mymessage = (String)ois.readObject();
    nbr = ois.readInt();
    nbr2 = (Double) ois.readObject();
    nbr3 = (Float) ois.readObject();
    My main question here is that I have to create a new Float and Double object to be able to send and receive this byte array correctly. However, I would like to be able to have to only create 1object, stuff it with the String, int, Float and Double, send it and then correctly receive it on the other end.
    So I tried creating another class, and then creating an obj of this class and stuffing it with the 4 types:
    public class O_struct{ 
    //the indiv. objects to be sent...
    public String mymessage; public int nbr; public Double nbr2;
    public Float nbr3;
    //construct...
    public O_struct(String mymessage_c, int nbr_c, double nbr2_c, float nbr3_c){
    my_message = my_message_c;
    nbr = nbr_c;
    nbr2 = new Double(nbr2_c);
    nbr3 = new Float(nbr3_c);
    Then in main, using this new class:
    in main():
    O_struct some_obj_client = new O_struct("Here is your stuff from your client", 22, 1232.1234, 890980980.798);
    oos.writeObject(some_obj_client);
    oos.close();
    send code....according to UDP
    However on the receiving side, I am not sure how to be able to correctly retrieve the 4 types. Before I was explicitely creating those objects for sending, then I was casting them again on the receiving side to retrieve then and it does work.
    But if I create a O_struct object and cast it as I did before with the indiv objects on the receiving end, I can't get the correct retrievals.
    My code, on the server side:
    O_struct some_obj_server = new O_struct(null, null, null. null);
    some_obj_server = (O_struct)ois.readObject();
    My main goal is to be able to send 4 types in a byte array, but the way I have written this code, I have to create a Float and Double obj to be able to send and receive correctly. I would rather not have to directly create these objects, but rather just create one object and be able to send and receive the information on both ends
    I might be making this more complicated than needed, but this was the only way I could figure out how to do this and any help will be greatly appreciated.
    If there an easier way to do I certainly will appreciate that advise as well.
    Thanks.

    which forum should I be posting this on?Serialization.
    To get you started...
    public class O_struct implements Serializable {                                                                                                                                                                                                                                                                                   

  • How to pass a array of object to oracle procedure using callable

    Hi,
    I am calling a oracle stored procedure using callable statement which has IN and OUT parameter of same type.
    IN and OUT are array of objects. (ie) IN parameter as Array of Objects and OUT parameter as Array of Objects
    here are the steps i have done as advised from oracle forum. correct me if i am in wrong direction
    ORACLE types and Stored Procedure
    CREATE OR REPLACE
    TYPE APPS.DEPARTMENT_TYPE AS OBJECT (
    DNO NUMBER (10),
    NAME VARCHAR2 (50),
    LOCATION VARCHAR2 (50)
    CREATE OR REPLACE
    TYPE APPS.DEPT_ARRAY AS TABLE OF department_type;
    CREATE OR REPLACE package body APPS.insert_object
    IS
    PROCEDURE insert_object_prc (d IN dept_array, d2 OUT dept_array)
    IS
    BEGIN
    d2 := dept_array ();
    FOR j IN 1 .. d.COUNT
    LOOP
    d2.EXTEND;
    d2 (j) := department_type (d (j).dno, d (j).name, d(j).location);
    END LOOP;
    END insert_object_prc;
    END insert_object;
    JAVA CODE
    Value Object
    package com.custom.vo;
    public class Dep {
    public int empNo;
    public String depName;
    public String location;
    public int getEmpNo() {
    return empNo;
    public void setEmpNo(int empNo) {
    this.empNo = empNo;
    public String getDepName() {
    return depName;
    public void setDepName(String depName) {
    this.depName = depName;
    public String getLocation() {
    return location;
    public void setLocation(String location) {
    this.location = location;
    to call stored procedure
    package com.custom.callable;
    import com.custom.vo.Dep;
    import oracle.jdbc.OracleCallableStatement;
    import oracle.jdbc.OracleConnection;
    import oracle.jdbc.OracleTypes;
    import oracle.jdbc.pool.OracleDataSource;
    import oracle.sql.ARRAY;
    import oracle.sql.ArrayDescriptor;
    import oracle.sql.Datum;
    import oracle.sql.STRUCT;
    import oracle.sql.StructDescriptor;
    public class CallableArrayTryOut {
    private static OracleDataSource odcDataSource = null;
    public static void main(String[] args) {
    OracleCallableStatement callStatement = null;
    OracleConnection connection = null;
    try {
    odcDataSource = new OracleDataSource();
    odcDataSource
    .setURL("......");
    odcDataSource.setUser("....");
    odcDataSource.setPassword("....");
    connection = (OracleConnection) odcDataSource.getConnection();
    } catch (Exception e) {
    System.out.println("DB connection Exception");
    e.printStackTrace();
    Dep[] dep = new Dep[2];
    dep[0] = new Dep();
    dep[0].setEmpNo(100);
    dep[0].setDepName("aaa");
    dep[0].setLocation("xxx");
    dep[1] = new Dep();
    dep[1].setEmpNo(200);
    dep[1].setDepName("bbb");
    dep[1].setLocation("yyy");
    try {
    StructDescriptor structDescriptor = new StructDescriptor(
    "APPS.DEPARTMENT_TYPE", connection);
    STRUCT priceStruct = new STRUCT(structDescriptor, connection, dep);
    STRUCT[] priceArray = { priceStruct };
    ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor(
    "APPS.DEPT_ARRAY", connection);
    ARRAY array = new ARRAY(arrayDescriptor, connection, priceArray);
    callStatement = (OracleCallableStatement) connection
    .prepareCall("{call insert_object.insert_object_prc(?,?)}");
    ((OracleCallableStatement) callStatement).setArray(1, array);
    callStatement.registerOutParameter(2, OracleTypes.ARRAY,
    "APPS.DEPT_ARRAY");
    callStatement.execute();
    ARRAY outArray = callStatement.getARRAY(2);
    Datum[] datum = outArray.getOracleArray();
    for (int i = 0; i < datum.length; i++) {
    oracle.sql.STRUCT os = (oracle.sql.STRUCT) datum[0];
    Object[] a = os.getAttributes();
    for (int j = 0; j < a.length; j++) {
    System.out.print("Java Data Type :"
    + a[j].getClass().getName() + "Value :" + a[j]
    + "\n");
    connection.commit();
    callStatement.close();
    } catch (Exception e) {
    System.out.println("Mapping Error");
    e.printStackTrace();
    THE ERROR
    Mapping Errorjava.sql.SQLException: Inconsistent java and sql object types
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1130)
    at oracle.sql.StructDescriptor.toOracleArray(StructDescriptor.java:823)
    at oracle.sql.StructDescriptor.toArray(StructDescriptor.java:1735)
    at oracle.sql.STRUCT.<init>(STRUCT.java:136)
    at com.custom.callable.CallableArrayTryOut.main(CallableArrayTryOut.java:48)

    You posted this question in the wrong forum section. There is one dedicated to Java that was more appropriate.
    Anyway here is a link that describes what you should do.
    http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/oraarr.htm#i1049179
    Bye Alessandro

  • Creating a generic class with a constructor that takes an array of objects

    I am relatively new to java and want to build a quick utility class that can generate a Run Length Encoding of any object. The idea is to take an array of objects of type "O" and then encode a string of objects that are "equal" to each other as an integer that counts the number of such equal instances and a single copy of the instance. This has the potential to very quickly reduce the size of some objects that I want to store. I would like to implement this class as a generic.
    public class RunLengthEncoding<O> {
         private class RLEPair {
              private int length;
              private O object;
         public RunLengthEncoding(O[]) {
    }As you can see, I need to make a constructor that takes an array of type "O". Is this possible to do? I can't seem to find the right syntax for it.
    Thanks,
    Sean

    Sorry. Obvious answer:
    public RunLengthEncoding(O[] oarray) {Again, sorry for the noise.

  • How can I check an object is an instance of any type within an array of related types?

    In LabVIEW, it's possible to check the runtime type of an object using To More Specific Class.vi. One usage of this would be to perform a safety check if some kind of class uses instances of another kind of class but is only able to handle a subset of that class' child types.
    For instance, let's say you had Beverage.lvclass, which represents an abstract type of product, and several subclasses: Coffee.lvclass, Tea.lvclass and Soda.lvclass.
    We also have a Person.lvclass which can drink beverages. A person also has preferences about the drinks they do or do not like:
    Attached is an implementation of this in LabVIEW.
    In Person.lvclass : Drink.vi, I have the following code. For whatever reason the wire appears broken in these snippets but it's all fine in the actual code.
    In Scenario.vi, I have the following code:
    What I'm finding is that no error is generated and instead I get "Yum, I love tea!", "Yum, I love coffee!" and "Yum, I love soda!". My guess is that To More Specific Class.vi casts to the static type of the "target class" input wire rather than its runtime type - and because I'm passing in elements from an array of types, the wire's static type is upcasted to the most specific type that is a superclass of the types in the array - which would be Beverage.lvclass. And so the cast is trying to determine if an object of static type Beverage.lvclass is an instance of Beverage.lvclass, which will of course be the case all the time.
    Is there any way to make LabVIEW check against the most specific runtype type of an object? As in, is there something I could do that, in this example case, would allow me to get the required behaviour of Joe throwing an error when he's made to drink soda? Or is this another limitation of LabVIEW that I'm going to have to live with?
    Solved!
    Go to Solution.
    Attachments:
    TypeCastingExample.zip ‏64 KB

    tst wrote:
    Your guess seems reasonable. I can't check right now, but there's a primitive called preserve run time type, which should do what you want.
    Cheers, that seems to have got it! I've never really looked at Preserve Run-Time Class before, but it seems to do the right thing.

  • Converting object wrapper type array into equivalent primary type array

    Hi All!
    My question is how to convert object wrapper type array into equivalent prime type array, e.g. Integer[] -> int[] or Float[] -> float[] etc.
    Is sound like a trivial task however the problem is that I do not know the type I work with. To understand what I mean, please read the following code -
    //Method signature
    Object createArray( Class clazz, String value ) throws Exception;
    //and usage should be as follows:
    Object arr = createArray( Integer.class, "2%%3%%4" );
    //"arr" will be passed as a parameter of a method again via reflection
    public void compute( Object... args ) {
        a = (int[])args[0];
    //or
    Object arr = createArray( Double.class, "2%%3%%4" );
    public void compute( Object... args ) {
        b = (double[])args[0];
    //and the method implementation -
    Object createArray( Class clazz, String value ) throws Exception {
         String[] split = value.split( "%%" );
         //create array, e.g. Integer[] or Double[] etc.
         Object[] o = (Object[])Array.newInstance( clazz, split.length );
         //fill the array with parsed values, on parse error exception will be thrown
         for (int i = 0; i < split.length; i++) {
              Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
              o[i] = meth.invoke( null, new Object[]{ split[i] });
         //here convert Object[] to Object of type int[] or double[] etc...
         /* and return that object*/
         //NB!!! I want to avoid the following code:
         if( o instanceof Integer[] ) {
              int[] ar = new int[o.length];
              for (int i = 0; i < o.length; i++) {
                   ar[i] = (Integer)o;
              return ar;
         } else if( o instanceof Double[] ) {
         //...repeat "else if" for all primary types... :(
         return null;
    Unfortunately I was unable to find any useful method in Java API (I work with 1.5).
    Did I make myself clear? :)
    Thanks in advance,
    Pavel Grigorenko

    I think I've found the answer myself ;-)
    Never thought I could use something like int.class or double.class,
    so the next statement holds int[] q = (int[])Array.newInstance( int.class, 2 );
    and the easy solution is the following -
    Object primeArray = Array.newInstance( token.getPrimeClass(), split.length );
    for (int j = 0; j < split.length; j++) {
         Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
         Object val = meth.invoke( null, new Object[]{ split[j] });
         Array.set( primeArray, j, val );
    }where "token.getPrimeClass()" return appropriate Class, i.e. int.class, float.class etc.

  • Invoking stored procedure that returns array(oracle object type) as output

    Hi,
    We have stored procedures which returns arrays(oracle type) as an output, can anyone shed some light on how to map those arrays using JPA annotations? I tried using jdbcTypeName but i was getting wrong type or argument error, your help is very much appreciated. Below is the code snippet.
    JPA Class:
    import java.io.Serializable;
    import java.sql.Array;
    import java.util.List;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import org.eclipse.persistence.annotations.Direction;
    import org.eclipse.persistence.annotations.NamedStoredProcedureQuery;
    import org.eclipse.persistence.annotations.StoredProcedureParameter;
    * The persistent class for the MessagePublish database table.
    @Entity
    @NamedStoredProcedureQuery(name="GetTeamMembersDetails",
         procedureName="team_emp_maintenance_pkg.get_user_team_roles",
         resultClass=TeamMembersDetails.class,
         returnsResultSet=true,
         parameters={  
         @StoredProcedureParameter(queryParameter="userId",name="I_USER_ID",direction=Direction.IN,type=Long.class),
         @StoredProcedureParameter(queryParameter="employeeId",name="I_EMPLOYEEID",direction=Direction.IN,type=Long.class),
         @StoredProcedureParameter(queryParameter="TEAMMEMBERSDETAILSOT",name="O_TEAM_ROLES",direction=Direction.OUT,jdbcTypeName="OBJ_TEAM_ROLES"),
         @StoredProcedureParameter(queryParameter="debugMode",name="I_DEBUGMODE",direction=Direction.IN,type=Long.class)
    public class TeamMembersDetails implements Serializable {
         private static final long serialVersionUID = 1L;
    @Id
         private long userId;
         private List<TeamMembersDetailsOT> teamMembersDetailsOT;
         public void setTeamMembersDetailsOT(List<TeamMembersDetailsOT> teamMembersDetailsOT) {
              this.teamMembersDetailsOT = teamMembersDetailsOT;
         public List<TeamMembersDetailsOT> getTeamMembersDetailsOT() {
              return teamMembersDetailsOT;
    Procedure
    PROCEDURE get_user_team_roles (
    i_user_id IN ue_user.user_id%TYPE
    , o_team_roles OUT OBJ_TEAM_ROLES_ARRAY
    , i_debugmode IN NUMBER :=0)
    AS
    OBJ_TEAM_ROLES_ARRAY contains create or replace TYPE OBJ_TEAM_ROLES_ARRAY AS TABLE OF OBJ_TEAM_ROLES;
    TeamMembersDetailsOT contains the same attributes defined in the OBJ_TEAM_ROLES.

    A few things.
    You are not using a JDBC Array type in your procedure, you are using a PLSQL TABLE type. An Array type would be a VARRAY in Oracle. EclipseLink supports both VARRAY and TABLE types, but TABLE types are more complex as Oracle JDBC does not support them, they must be wrapped in a corresponding VARRAY type. I assume your OBJ_TEAM_ROLES is also not an OBJECT TYPE but a PLSQL RECORD type, this has the same issue.
    Your procedure does not return a result set, so "returnsResultSet=true" should be "returnsResultSet=false".
    In general I would recommend you change your stored procedure to just return a select from a table using an OUT CURSOR, that is the easiest way to return data from an Oracle stored procedure.
    If you must use the PLSQL types, then you will need to create wrapper VARRAY and OBJECT TYPEs. In EclipseLink you must use a PLSQLStoredProcedureCall to access these using the code API, there is not annotation support. Or you could create your own wrapper stored procedure that converts the PLSQL types to OBJECT TYPEs, and call the wrapper stored procedure.
    To map to Oracle VARRAY and OBJECT TYPEs the JDBC Array and Struct types are used, these are supported using EclipseLink ObjectRelationalDataTypeDescriptor and mappings. These must be defined through the code API, as there is currently no annotation support.
    I could not find any good examples or doc on this, your best source of example is the EclipseLink test cases in SVN,
    http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/plsql/
    http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/customsqlstoredprocedures/
    James : http://www.eclipselink.org

  • Multiple SDO_GEOMETRY Objects of type CIRCLE with the same LOCATION

    Can i have a single MERCHANT LOCATION hold multiple SDO_GEOMETRY Objects of type CIRCLE ?
    For example the use case , i need to have a SDO_GEOMETRY TYPE CIRCLE circle defined for a single MERCHANT LOCATION with a 2 Mile radius as well as a 5 Mile Radius.
    is that even possible with Spatial? I know i can add a single geometry for a merchant at once, but i want to give the user the flexibility of choosing the type of geometry for the merchant based on set of rules. hence want to check if this can be done or not?
    Thanks in Advance

    Person with no name,
    Not clear exactly what you need to do here.
    You can store two circles with the same centre in a single sdo_geometry but only if you use a polygon with the circle with the greatest radius being the outer ring and the smaller radius the inner ring.
    I have a utility in my free COGO plsql package that allows me to create circles for PLANAR data pretty easily as follows:
    -- Function...
    Create
        function CreateCircle(dCentreX in Number,
                              dCentreY in Number,
                              dRadius in Number)
        return mDSYS.sdo_geometry
        IS
          dPnt1X NUMBER;
          dPnt1Y NUMBER;
          dPnt2X NUMBER;
          dPnt2Y NUMBER;
          dPnt3X NUMBER;
          dPnt3Y NUMBER;
        BEGIN
          -- Compute three points on the circle's circumference
          dPnt1X := dCentreX - dRadius;
          dPnt1Y := dCentreY;
          dPnt2X := dCentreX + dRadius;
          dPnt2Y := dCentreY;
          dPnt3X := dCentreX;
          dPnt3Y := dCentreY + dRadius;
          RETURN MDSYS.SDO_GEOMETRY(2003,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,4),MDSYS.SDO_ORDINATE_ARRAY(dPnt1X, dPnt1Y, dPnt2X, dPnt2Y, dPnt3X, dPnt3Y));
        End;
    select sdo_geometry(f.geom.sdo_gtype,
                        f.geom.sdo_srid,
                        sdo_point_type(f.centreX,f.centreY,null),
                        f.geom.sdo_elem_info,
                        f.geom.sdo_ordinates) as mcircle
      from (select 10 as centreX,
                   10 as centreY,
                   sdo_geom.sdo_xor(cogo.CreateCircle(10,10,2),
                                    cogo.CreateCircle(10,10,5),
                                    0.005) as geom
              from dual ) f;
    -- Results
    MCIRCLE
    SDO_GEOMETRY(2003,NULL,SDO_POINT_TYPE(10.0,10.0,NULL),SDO_ELEM_INFO_ARRAY(1,1003,2, 11,2003,2),SDO_ORDINATE_ARRAY(10.0,15.0, 5.0,10.0, 10.0,5.0, 15.0,10.0, 10.0,15.0, 10.0,8.0, 8.0,10.0, 10.0,12.0, 12.0,10.0, 10.0,8.0))(This geometry looks like a donut.)
    Note that I have included the centre coordinates in the sdo_point of the result sdo_geometry.
    To extract each ring:
    -- We need a function to return number of rings in a polygon as sdo_util.getNumElems() does not
    Create
      Function GetNumRings( p_geometry  in mdsys.sdo_geometry,
                            p_ring_type in integer /* 0 = ALL; 1 = OUTER; 2 = INNER */ )
        Return Number
      Is
        v_elements   pls_integer := 0;
        v_ring_count pls_integer := 0;
        v_etype      pls_integer;
        v_ring_type  pls_integer := case when ( p_ring_type is null OR
                                                p_ring_type not in (0,1,2) )
                                         Then 0
                                         Else p_ring_type
                                     End;
      Begin
        If ( p_geometry is not null ) Then
          v_elements := ( ( p_geometry.sdo_elem_info.COUNT / 3 ) - 1 );
          <<element_extraction>>
          FOR v_i IN 0 .. v_elements LOOP
            v_etype := p_geometry.sdo_elem_info(v_i * 3 + 2);
            If ( ( v_etype in (1003,1005,2003,2005) and 0 = v_ring_type )
              OR ( v_etype in (1003,1005)           and 1 = v_ring_type )
              OR ( v_etype in (2003,2005)           and 2 = v_ring_type ) ) Then
               v_ring_count := v_ring_count + 1;
            End If;
          END LOOP element_extraction;
        End If;
        Return v_ring_count;
      End GetNumRings;
    -- Query
    with circles as (
      SELECT SDO_GEOMETRY(2003,NULL,SDO_POINT_TYPE(10.0,10.0,NULL),SDO_ELEM_INFO_ARRAY(1,1003,2, 11,2003,2),SDO_ORDINATE_ARRAY(10.0,15.0, 5.0,10.0, 10.0,5.0, 15.0,10.0, 10.0,15.0, 10.0,8.0, 8.0,10.0, 10.0,12.0, 12.0,10.0, 10.0,8.0))
             as geom
        FROM dual
    select sdo_util.extract(a.geom,1,e.ringNo) as circle
      from circles a,
           (select level as ringNo from circles a connect by level <= GETNUMRINGS(a.geom)) e;
    -- Result
    CIRCLE
    SDO_GEOMETRY(2003,NULL,SDO_POINT_TYPE(10.0,10.0,NULL),SDO_ELEM_INFO_ARRAY(1,1003,2),SDO_ORDINATE_ARRAY(10.0,15.0, 5.0,10.0, 10.0,5.0, 15.0,10.0, 10.0,15.0))
    SDO_GEOMETRY(2003,NULL,SDO_POINT_TYPE(10.0,10.0,NULL),SDO_ELEM_INFO_ARRAY(1,1003,2),SDO_ORDINATE_ARRAY(10.0,8.0, 12.0,10.0, 10.0,12.0, 8.0,10.0, 10.0,8.0))Not sure if this helps you at all....
    regards
    Simon

  • Vectors with multiple types of objects

    Ok, this is what i need. I have a main class, EquationVector, and i have four smaller classes, MathPrimitive, which is abstract and all of the following classes extend, Number which just holds numbers, Operator which takes care of what type it is and what to do, and Variable, which knows its value, its coef and its power. I use the MathPrimitive class because all of the other classes need to have a common getType() method, plus it holds static values for all the possible types. What i need is some sort of storage method that is dynamically resizeable, and can handle multiple types of objects. I tried vector, but it doesnt work, even when i cast. I want to be able to do something to the effect of
    myArray.elementAt(index).getOperatorType()
    and be able to get the operator type if its an operator, but at the same time be able to do
    myArray.elementAt(index).getCoef()
    and be able to get the coeficient if its a variable. I'm not sure if this is actually possible, so if anybody has any good ideas i would be really apreciative. Thank you.

    Vector will absolutely work, as will ArrayList
    You just better make sure you know what kind of objects are at what slots in the vector.
    opType = ((MathPrimitive) myArray.elementAt(index)).getOperatorType();
    If you don't know what type of object is at a particular slot you can always use
    Object o = myArray.elementAt(index);
    if (o instanceof MathPrimitive)
    else
    ....

  • Creating array of objects of JLabel , JTextField type

    hello,
    I wanted to create an array of objects of JLabel class. I wrote and complied the following lines. it was successfully compiled but during execution it showed - 'start: applet not initialized' on the applet's window. What wrong have I done and how can I get rid of that?
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    /*<html>
    <applet code="test.class" width=200 height=300>
    </applet>
    </html> **/
    public class test extends JApplet
         Container c = getContentPane();
         JLabel lb[];
         public void init()
                   for( int i = 0; i < 10; i++ )
                   lb[i] = new JLabel( "Line" + i );
                   c.add( lb[i] );
    }

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    /*<html>
    <applet code="test.class" width=200 height=300>
    </applet>
    </html> **/
    public class test extends JApplet
         Container c = getContentPane();
         JLabel lb[] = new JLabel[10];
         public void init()
                   for( int x = 0; x < 10; x++ )
                   lb [x]= new JLabel( "Line" + x );
                   c.add( lb );
    // showing applet not initiliazed
    // generating nullPointerException
    // please helpLast post, thats a promise!!! :-)Still wrong. See corrections in 'for' loop. :)

  • Calling a Procedure which has Array of Objects as arguments (from BPEL)

    Hi,
    I wanted to pass multiple records as arguments to a stored procedure from BPEL.
    We created stored procedure which takes array of Objects as arguments. I invoked it from BPEL. It was successfully compiled and deployed.
    At runtime it is throwing following error.
    <bindingFault xmlns="http://schemas.oracle.com/bpel/extension">
    <part name="code">
    <code>17072</code>
    </part>
    <part name="summary">
    <summary>Error binding the value of a parameter. An error occurred when binding the value of parameter ARG in the SCOTT.TESTPACK.TESTPROC API. Cause: java.sql.SQLException: Inserted value too large for column: "sadfsafsad" Check to ensure that the parameter is a valid IN or IN/OUT parameter of the API. Contact oracle support if error is not fixable.</summary>
    </part>
    <part name="detail">
    <detail>Inserted value too large for column: "sadfsafsad"</detail>
    </part>
    </bindingFault>

    I think you from Sierra Atlantic and you using Beta 3. There was a bug in Beta 3 in using arrays, which got fixed in post Beta3. You got to wait till next release.

  • Inserting ARRAYs of Objects in Oracle 9i

    I am trying to insert ARRAYs of user-defined types into a table in Oracle. I have had success doing this once, so I wanted to do it again with other tables. Everything works perfectly for the first table I set up and it fails thereafter.
    I'm trying to figure out if there's some special code I need, or something on the Oracle side, in order to have multiple tables work this way.
    The Exception I'm getting is posted at the bottom. The following should give adequate context to my problem.
    The Oracle defined type is:
    CREATE OR REPLACE TYPE source_language_type AS OBJECT(
    csi INTEGER
    ,language_id VARCHAR2(10)
    ,source_name VARCHAR2(255)
    ,is_default INTEGER
    And the Oracle definition for the ARRAY of these types is:
    CREATE TYPE source_language_tabtype AS TABLE OF source_language_type
    My Java class that implements SQLData follows:
    public class DBSourceLangInput implements SQLData {
    public static final String SQL_NAME = "source_language_type";
    private int _csi;
    private String _langId;
    private String _name;
    private int _isDefault;
    public DBSourceLangInput(int csi, String langId, String name, int isDefault) {
    _csi = csi;
    _langId = langId;
    _name = name;
    _isDefault = isDefault;
    public String getSQLTypeName() throws SQLException {
    return SQL_NAME;
    public void readSQL(SQLInput stream, String typeName) throws SQLException {
    setCsi(stream.readInt());
    setLangId(stream.readString());
    setName(stream.readString());
    setIsDefault(stream.readInt());
    public void writeSQL(SQLOutput stream) throws SQLException {
    stream.writeInt(getCsi());
    stream.writeString(getLangId());
    stream.writeString(getName());
    stream.writeInt(getIsDefault());
    ...etc....
    And the code to insert the ARRAY of those objects follows:
    private void loadSourceLang(OracleConnection oraConn, DBSourceLangInput[] sourceLangs, OracleCallableStatement cs) throws SQLException {
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("source_language_tabtype", oraConn);
    ARRAY membersArray = new ARRAY(descriptor, oraConn, sourceLangs);
    cs.setARRAY(1, membersArray);
    cs.registerOutParameter(2, OracleTypes.INTEGER);
    cs.execute();
    The Exception is as follows:
    SQLException: invalid name pattern: SDS4.package_source_type
    SQLState: null
    Message: invalid name pattern: SDS4.package_source_type
    Vendor: 17074
    java.sql.SQLException: invalid name pattern: SDS4.package_source_type
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:169)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:211)
         at oracle.jdbc.oracore.OracleTypeADT.initMetadata(OracleTypeADT.java:425)
         at oracle.jdbc.oracore.OracleTypeADT.init(OracleTypeADT.java:344)
         at oracle.sql.StructDescriptor.initPickler(StructDescriptor.java:151)
         at oracle.sql.StructDescriptor.<init>(StructDescriptor.java:129)
         at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:97)
         at oracle.sql.STRUCT.toSTRUCT(STRUCT.java:322)
         at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:254)
         at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:297)
         at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:137)
         at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:750)
         at oracle.sql.ARRAY.<init>(ARRAY.java:116)
         at com.lxnx.metadatatools.sdsfeed.SDSFeed.loadPackageSource(SDSFeed.java:961)
    ....etc.....
    The code all seems right. It's identical to the code I'm successfully using to load another identical table.
    Again, is this a Java problem or an Oracle problem?
    Thanks again!

    I found my problem!
    I failed to post the one other snippet of code, where I actually create the CallableStatement object as follows:
    cs = (OracleCallableStatement) oraConn.prepareCall("CALL ABC.XYZ(?,?)");
    All my other sql statements are all lower case (select, insert, etc.), so I didn't think that should matter.
    However, as soon as I made these call statements all uppercase (as above), that fixed my problem!
    Very picky!!

  • Displaying the contents of an array of objects

    Hello All,
    My Java teacher gave us a challenge and I'm stumped. The teacher wants us to display the contents of the array in the main menthod. The original code is as follows:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
    }I understand that the elements of the array are objects, and each one has a value assigned to it. The following code was my first attempt at a solution:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
                                    for ( int i = 0; i < thingArray.length; i++)
                                       System.out.println( thingArray );                         
    }To which I'm given what amounts to garbage output. I learned from reading about that output that its basically displaying the memory location of the array, and the the contents of the array. There was mention of overriding or bypassing a method in System.out.println, but I don't believe that we're that far advanced yet. Any thoughts? I know I have to get at the data fields in the objects of the array, but i'm not having an easy time figuring it out. Thanks very much in advance!

    robrom78 wrote:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
    for ( int i = 0; i < thingArray.length; i++)
    System.out.println( thingArray );                         
    Note that you're trying to print the entire array at every loop iteration. That's probably not what you meant to do.
    You probably meant to do something more like
                                 System.out.println( thingArray[i] );Also, note that the java.util.Arrays class has a toString method that might be useful.
    To which I'm given what amounts to garbage output. It's not garbage. It's the default output to toString() for arrays, which is in fact the toString() defined for java.lang.Object (and inherited by arrays).
    I learned from reading about that output that its basically displaying the memory location of the array, and the the contents of the array.It displays a default result that is vaguely related to the memory, but probably shouldn't be thought of us such. Think of it as identifying the type of object, and a value that differentiates it from other objects of the same type.
    By the way I assume you mean "+not+ the contents of the array" above. If so, that is correct.
    There was mention of overriding or bypassing a method in System.out.println, but I don't believe that we're that far advanced yet. Any thoughts? No, you don't override a method in println; actually methods don't contain other methods directly. You probably do need to override toString in Thing.
    I know I have to get at the data fields in the objects of the array, but i'm not having an easy time figuring it out. You can get to the individual objects in the array just by dereferencing it, as I showed you above.
    But I suspect that won't be sufficient. Most likely, Thing doesn't have a toString method defined. This means that you'll end up with very similar output, but it will say "Thing" instead of "[Thing" and the numbers to the right of the "@" will be different.
    You'll need to override the toString() method in Thing to get the output you want.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • White screen - Laptop doesn't recognise own display as default

    Hi all, I've had a search on the forum for the same issue but there doesn't seem to be any issue exactly matching this, so posting. I bought an IdeaPad Flex 14 about 9 months ago. It was fine up til about 6 months ago. Then it started to boot to a wh

  • How Do I Open A .rar File??

    hey guys i just downloaded a .rar file that is suppossed to contain a bunch of .mp3 files but can't figure out what to do with the .rar file!? here is the file that i'm downloading if that helps.. http://www.mediafire.com/?7rvjidbnhmu thanks!

  • Output type Requirement triggering

    Hi, In my project I have a requirement to stop triggering of an output type if all the items in the sales order have reason for rejection set. I have done the condition check in a output requirement routine and if the condition fails then I set SY-SU

  • Lost the power adapter.

    Hi, I've lost my power adapter(ultracompact) that came with iphone 3G. However I have an old apple USB power adapter that I used for charging my ipods. When I checked the online apple store I saw that there are two different power adapters. The bigge

  • Attempting to sort recordset off our iseries

    I have a problem that I would appreciate assistance with.  I have successfuly created a recordset that pulls data off our iSeries.  I have created a table from the recordset, but upon the review of the content of the table by meeting attendees it was