Examples of JDOOneToOneNature


Examples of org.exolab.castor.builder.info.nature.relation.JDOOneToOneNature

    public void testGetForeignKeyNothingAdded() {
        FieldInfoFactory factory = new FieldInfoFactory();
        FieldInfo address = factory.createFieldInfo(new XSClass(new JClass(
                "Employee")), "address");
        address.addNature(JDOOneToOneNature.class.getName());
        JDOOneToOneNature relation = new JDOOneToOneNature(address);
        assertNull(relation.getForeignKeys());
    }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.relation.JDOOneToOneNature

    public void testAddGetForeignKey() {
        FieldInfoFactory factory = new FieldInfoFactory();
        FieldInfo address = factory.createFieldInfo(new XSClass(new JClass(
                "Employee")), "address");
        address.addNature(JDOOneToOneNature.class.getName());
        JDOOneToOneNature relation = new JDOOneToOneNature(address);
        relation.addForeignKey("fk_address");
        assertEquals("fk_address", (String) relation.getForeignKeys().get(0));
    }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.relation.JDOOneToOneNature

    public void testAddGetForeignKeys() {
        FieldInfoFactory factory = new FieldInfoFactory();
        FieldInfo address = factory.createFieldInfo(new XSClass(new JClass(
                "Employee")), "token");
        address.addNature(JDOOneToOneNature.class.getName());
        JDOOneToOneNature relation = new JDOOneToOneNature(address);
        relation.addForeignKey("fk_sin");
        relation.addForeignKey("fk_dateofbirth");
       
        List keys = relation.getForeignKeys();
       
        if (keys.get(0).equals("fk_sin")) {
            // Check the second entry
            assertEquals("fk_dateofbirth", keys.get(1));
        } else if (keys.get(0).equals("fk_dateofbirth")) {
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.relation.JDOOneToOneNature

    public void testReadOnly() {
        FieldInfoFactory factory = new FieldInfoFactory();
        FieldInfo address = factory.createFieldInfo(
                new XSClass(new JClass("Employee")), "address");
        address.addNature(JDOOneToOneNature.class.getName());
        JDOOneToOneNature relation = new JDOOneToOneNature(address);
        relation.setReadOnly(true);
        assertEquals(true, relation.isReadOnly());
    }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.relation.JDOOneToOneNature

    public void testDirty() {
        FieldInfoFactory factory = new FieldInfoFactory();
        FieldInfo address = factory.createFieldInfo(
                new XSClass(new JClass("Employee")), "address");
        address.addNature(JDOOneToOneNature.class.getName());
        JDOOneToOneNature jdo = new JDOOneToOneNature(address);
        jdo.setDirty(true);
        assertEquals(true, jdo.isDirty());
    }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.relation.JDOOneToOneNature

                            fNature.setDirty(false);
                            fNature.setDirty(column.getDirty());
                        } else if (tmpObject instanceof OneToOne) {
                            OneToOne relation = (OneToOne) tmpObject;
                            fInfo.addNature(JDOOneToOneNature.class.getName());
                            JDOOneToOneNature oneNature = new JDOOneToOneNature(fInfo);
                            oneNature.addForeignKey(relation.getName());
                            oneNature.setDirty(relation.isDirty());
                            oneNature.setReadOnly(relation.isReadOnly());
                        } else if (tmpObject instanceof OneToMany) {
                            OneToMany relation = (OneToMany) tmpObject;
                            fInfo.addNature(JDOOneToManyNature.class.getName());
                            JDOOneToManyNature manyNature = new JDOOneToManyNature(fInfo);
                            manyNature.addForeignKey(relation.getName());
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.relation.JDOOneToOneNature

           }
           return true;
       }
      
       if (fInfo.hasNature(JDOOneToOneNature.class.getName())) {
           JDOOneToOneNature oneNature = new JDOOneToOneNature(fInfo);
           if (oneNature.getForeignKeys().size() != 1) {
               return false;
           }
           return true;
       }
      
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.relation.JDOOneToOneNature

    * @return JSourceCode created in this method
    */
   private JSourceCode createOneToOneFieldInfoPart(final FieldInfo fInfo, final JSourceCode jsc) {
//       JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
       JDOClassInfoNature cNature = new JDOClassInfoNature(fInfo.getDeclaringClassInfo());
       JDOOneToOneNature oneNature = new JDOOneToOneNature(fInfo);
       XMLInfoNature xmlNature = new XMLInfoNature(fInfo);
      
       //-- set name
       String name = xmlNature.getNodeName();
       jsc.add("");
       jsc.add("//" + name + " field");
       jsc.add("String " + name + "FieldName = \"" + name + "\";");
      
       String sqlName = oneNature.getForeignKeys().get(0).toString();
       jsc.add("String " + name + "SqlName = \"" + sqlName + "\";");
      
       //-- initialize objects
       jsc.add("FieldDescriptorImpl " + name + "FieldDescr;");
       jsc.add("FieldMapping " + name + "FM = new FieldMapping();");

       //-- set typeInfo
       String type = null;
       XSType schemaType;
      
       schemaType = xmlNature.getSchemaType();
       JType javaType = schemaType.getJType();
       type = javaType.toString();
      
       String wrapperType = null;
       if (javaType instanceof JPrimitiveType) {
        wrapperType = ((JPrimitiveType) javaType).getWrapperName();
       } else {
           wrapperType = type;
       }


       // TODO IS THERE A NEED TO CHECK THIS?!
       if ((type != null) && (type.length() > 0)) {
           jsc.add("TypeInfo " + name
                   + "Type = new TypeInfo(" + type + ".class);");
       }

       jsc.add("// Set columns required (= not null)");
       jsc.add(name + "Type.setRequired("
               + Boolean.toString(xmlNature.isRequired()) + ");");

       jsc.add("");

       jsc.add("FieldHandler " + name + "Handler;");
       jsc.add("try {");

       //-- get/set methods
       jsc.indent();
       // TODO HOW ABOUT GETTING THE NAME FROM NATURE?
       String className = fInfo.getDeclaringClassInfo().getJClass().getLocalName();
       // TODO IS THERE A NEED TO CHECK THIS?!
       if ((className != null) && (className.length() > 0)) {
           jsc.add("Method " + name + "GetMethod = "
                   + className + ".class.getMethod(\"get"
                   + toUpperCaseFirstLetter(name) + "\", null);");
           jsc.add("Method " + name + "SetMethod = "
                   + className + ".class.getMethod(\"set"
                   + toUpperCaseFirstLetter(name) + "\", new Class[]{");
       }

       // TODO IS THERE A NEED TO CHECK THIS?!
       if ((type != null) && (type.length() > 0)) {
           jsc.addIndented(type + ".class});");
       }

       jsc.add("");
       jsc.add(name + "Handler = new FieldHandlerImpl(" + name + "FieldName, ");
       jsc.append("null, null,");
       jsc.addIndented(name + "GetMethod, " + name + "SetMethod, " + name + "Type);");
       jsc.unindent();
       jsc.add("");

       //-- Catch of exceptions
       jsc.add("} catch (SecurityException e1) {");
       jsc.indent();
       jsc.add("throw new RuntimeException(e1.getMessage());");
       jsc.unindent();
       jsc.add("} catch (MappingException e1) {");
       jsc.indent();
       jsc.add("throw new RuntimeException(e1.getMessage());");
       jsc.unindent();
       jsc.add("} catch (NoSuchMethodException e1) {");
       jsc.indent();
       jsc.add("throw new RuntimeException(e1.getMessage());");
       jsc.unindent();
       jsc.add("}");


//       //-- JDOFieldDescriptorImpl constructor
//       jsc.add("// Instantiate " + name + " field descriptor");
//       jsc.add(name + "FieldDescr = new JDOFieldDescriptorImpl(");
//       jsc.append(name + "FieldName, " + name + "Type,");
//       jsc.indent();
//       jsc.add(name + "Handler, ");
//       jsc.append(Boolean.toString(fInfo.isTransient()) + ", ");
//       jsc.append("new String[] { " + name + "SqlName },");
//       jsc.add("new int[] {SQLTypeInfos");
//       jsc.indent();
//       jsc.add(".javaType2sqlTypeNum(");
//
//       // TODO IS THERE NEED TO CHECK THIS?!
//       if ((type != null) && (type.length() > 0)) {
//           jsc.append(wrapperType + ".class) },");
//       }
//
//       jsc.unindent();
//       jsc.add("null, new String[] { " + name + "SqlName }, ");
//       jsc.append(Boolean.toString(oneNature.isDirty()) + ", ");
//       jsc.append(Boolean.toString(oneNature.isReadOnly()) + ");");
//       jsc.unindent();

       //-- invoke FieldDescriptorImpl constructor
       jsc.add("// Instantiate " + name + " field descriptor");
       jsc.add(name + "FieldDescr = new FieldDescriptorImpl(");
       jsc.append(name + "FieldName, " + name + "Type,");
       jsc.append(name + "Handler, ");
       jsc.append(Boolean.toString(fInfo.isTransient()) + ");");

       jsc.add(name + "FieldDescr.addNature(FieldDescriptorJDONature.class.getName());");

       jsc.add("FieldDescriptorJDONature " + name + "FieldJdoNature = new FieldDescriptorJDONature("
               + name + "FieldDescr);");

       jsc.add(name + "FieldJdoNature.setSQLName(new String[] { " + name + "SqlName });");
       jsc.add(name + "FieldJdoNature.setSQLType(new int[] {SQLTypeInfos");
       jsc.append(".javaType2sqlTypeNum(");

       // TODO IS THERE NEED TO CHECK THIS?!
       if ((type != null) && (type.length() > 0)) {
           jsc.append(wrapperType + ".class) });");
       }

//       jsc.add(name + "FieldJdoNature.setManyTable(null);");
       jsc.add(name + "FieldJdoNature.setManyKey(new String[] { " + name + "SqlName });");
       jsc.add(name + "FieldJdoNature.setDirtyCheck(" + Boolean.toString(oneNature.isDirty()) + ");");
       jsc.add(name + "FieldJdoNature.setReadOnly(" + Boolean.toString(oneNature.isReadOnly()) + ");");

       jsc.add("");

       //-- parent class descriptor
       jsc.add(name + "FieldDescr.setContainingClassDescriptor(this);");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.