Examples of JDOFieldInfoNature


Examples of org.exolab.castor.builder.info.nature.JDOFieldInfoNature

        FieldInfo fInfo = cInfo.getElementField("ssnr");

        assertNotNull(fInfo);

        JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);

        assertEquals("ssnr", fNature.getColumnName());
        assertEquals("integer", fNature.getColumnType());

        fInfo = cInfo.getElementField("firstName");

        assertNotNull(fInfo);

        fNature = new JDOFieldInfoNature(fInfo);

        assertEquals("firstName", fNature.getColumnName());
        assertEquals("varchar", fNature.getColumnType());

        fInfo = cInfo.getElementField("lastName");

        assertNotNull(fInfo);

        fNature = new JDOFieldInfoNature(fInfo);

        assertEquals("lastName", fNature.getColumnName());
        assertEquals("varchar", fNature.getColumnType());
       
        try {
            assertNull(cInfos.get(1));
            fail("Unexpected ClassInfo Element encountered!");
        } catch (IndexOutOfBoundsException e) {
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.JDOFieldInfoNature

                FieldInfo fInfo = cInfo.getAttributeField("coverType");
               
                assertNotNull(fInfo);
               
                fInfo.addNature(JDOFieldInfoNature.class.getName());
                JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
               
                assertEquals("cover_type", fNature.getColumnName());
                assertEquals("varchar", fNature.getColumnType());
               
                // FieldInfo for isbn               
                fInfo = cInfo.getElementField("isbn");
               
                assertNotNull(fInfo);
               
                fNature = new JDOFieldInfoNature(fInfo);
               
                assertEquals("isbn", fNature.getColumnName());
                assertEquals("varchar", fNature.getColumnType());
               
                // FieldInfo for title
                fInfo = cInfo.getElementField("title");
               
                assertNotNull(fInfo);
               
                fNature = new JDOFieldInfoNature(fInfo);
               
                assertEquals("title", fNature.getColumnName());
                assertEquals("varchar", fNature.getColumnType());
            } else {
                fail("Unexpected ClassInfo Element encountered!");
            }
        }
    }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.JDOFieldInfoNature

                assertNotNull(fInfos);
               
                for (int j = 0; j < fInfos.length; ++j) {
                    FieldInfo fInfo = fInfos[j];
                    assertNotNull(fInfo);
                    JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
                    assertNotNull(fNature);
                   
                    String columnName = fNature.getColumnName();
                    String columnType = fNature.getColumnType();
                   
                    XMLInfoNature xmlFieldNature = new XMLInfoNature(fInfo);
                   
                    if (xmlFieldNature.getNodeName().equals("ssn")) {   
                        assertEquals("ssn", columnName);
                        assertEquals("bigint", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("firstName")) {
                        assertEquals("firstName", columnName);
                        assertEquals("varchar", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("lastName")) {
                        assertEquals("lastName", columnName);
                        assertEquals("varchar", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("birthdate")) {
                        assertEquals("birthdate", columnName);
                        assertEquals("date", columnType);
                    } else {
                        fail("Unexpected FieldInfo Element encountered!");
                    }
                }
            } else if (xmlNature.getNodeName().equals("insurant")) {
                String tableName = cNature.getTableName();
                assertEquals("insurant", tableName);
               
                List primaryKeys = cNature.getPrimaryKeys();
               
                assertEquals(2, primaryKeys.size());
                assertEquals("ssn", (String) primaryKeys.get(0));
                assertEquals("policyNumber", (String) primaryKeys.get(1));
               
                assertEquals(1, cInfo.getFieldCount());
               
                FieldInfo fInfo = cInfo.getElementField("policyNumber");
               
                assertNotNull(fInfo);
               
                JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
               
                assertNotNull(fNature);
               
                String columnName = fNature.getColumnName();
                assertEquals("policyNumber", columnName);
                String columnType = fNature.getColumnType();
                assertEquals("bigint", columnType);
            } else {
                fail("Unexpected ClassInfo Element encountered!");
            }
        }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.JDOFieldInfoNature

                if (it.hasNext()) {                
                    while (it.hasNext()) {
                        Object tmpObject = it.next();
                        if (tmpObject instanceof Column) {
                            fInfo.addNature(JDOFieldInfoNature.class.getName());
                            JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
                            Column column = (Column) tmpObject;
                            fNature.setColumnName(column.getName());
                            fNature.setColumnType(column.getType());
                            fNature.setReadOnly(column.isReadOnly());
                            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());
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.JDOFieldInfoNature

       if (!fInfo.hasNature(XMLInfoNature.class.getName())) {
           return false;
       }
      
       if (fInfo.hasNature(JDOFieldInfoNature.class.getName())) {
           JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
           if (fNature.getColumnName() == null
                   || fNature.getColumnName().length() == 0
                   || fNature.getColumnType() == null) {
               return false;
           }
           return true;
       }
      
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.JDOFieldInfoNature

    * @param fInfo FieldInfo object
    * @param jsc JSourceCode created till now
    * @return JSourceCode created in this method
    */
   private JSourceCode createEntityFieldInfoPart(final FieldInfo fInfo, final JSourceCode jsc) {
       JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
       JDOClassInfoNature cNature = new JDOClassInfoNature(fInfo.getDeclaringClassInfo());
       XMLInfoNature xmlNature = new XMLInfoNature(fInfo);
      
       //-- set name
       String name = xmlNature.getNodeName();
       jsc.add("");
       jsc.add("//" + name + " field");
       jsc.add("String " + name + "FieldName = \"" + name + "\";");

       //-- 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(" + wrapperType + ".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();
       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()) + ", ");
//       String sqlName = new JDOFieldInfoNature(fInfo).getColumnName();
//       jsc.append("new String[] { \"" + 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[] {}, ");
//       jsc.append(Boolean.toString(fNature.isDirty()) + ", ");
//       jsc.append(Boolean.toString(fNature.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);");

       String sqlName = new JDOFieldInfoNature(fInfo).getColumnName();
       jsc.add(name + "FieldJdoNature.setSQLName(new String[] { \"" + 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("null, new String[] {}, ");
       jsc.add(name + "FieldJdoNature.setManyTable(null);");
       jsc.add(name + "FieldJdoNature.setManyKey(new String[] {});");
       jsc.add(name + "FieldJdoNature.setDirtyCheck(" + Boolean.toString(fNature.isDirty()) + ");");
       jsc.add(name + "FieldJdoNature.setReadOnly(" + Boolean.toString(fNature.isReadOnly()) + ");");

       jsc.add("");

       //-- parent class descriptor
       jsc.add(name + "FieldDescr.setContainingClassDescriptor(this);");
      
       boolean isPrimaryKey = false;
       if (cNature.getPrimaryKeys() != null) {
           isPrimaryKey = (cNature.getPrimaryKeys().contains(xmlNature.getNodeName()));
       }
      
       jsc.add(name + "FieldDescr.setIdentity("
               + Boolean.toString(isPrimaryKey) + ");");

       //-- fieldmapping
       jsc.add(name + "FM.setIdentity(" + Boolean.toString(isPrimaryKey) + ");");
       jsc.add(name + "FM.setDirect(false);");
       jsc.add(name + "FM.setName(\"" + name + "\");");
       jsc.add(name + "FM.setRequired(" + xmlNature.isRequired() + ");");
       jsc.add(name + "FM.setSetMethod(\"set"
               + toUpperCaseFirstLetter(name) + "\");");
       jsc.add(name + "FM.setGetMethod(\"get"
               + toUpperCaseFirstLetter(name) + "\");");

       //-- sql part
       jsc.add("Sql " + name + "Sql = new Sql();");
       jsc.add(name + "Sql.addName(\"" + name + "\");");

       String sqlType = fNature.getColumnType();
       if ((sqlType != null) && (sqlType.length() > 0)) {
           jsc.add(name + "Sql.setType(\"" + sqlType + "\");");
       }

       jsc.add(name + "FM.setSql(" + name + "Sql);");
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.