Generate xml schema primary, foreign keys in java




  1. How i can make VIN column in auto table as primary key?

  2. How i can make ID column in repair table as primary key?

  3. How i can make VIN column in repair table as foreign key?

  4. Maybe is easy way to auto generate ID(make AUTO INCREMENT)? becouse i just using variable. Something like k=k+1 when record is added


I know that @XmlElement means that it will be element, but how to say that it will be primary key? I know that I need do something with:



<xs:keyref
and
xs.unique


But how do it in code.


So i need with class auto and repair tables generate xmlschema with primary, foreign keys.


Sorry for my bad english language :/


Here is first table(auto):



import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "Auto",propOrder = {
"VIN", "Make", "Model", "Year"
})
public class XmlSchemaTypeAuto {
@XmlElement(name="VIN")
String VIN;
@XmlElement(name="Make")
String Make;
@XmlElement(name="Model")
String Model;
@XmlElement(name="Year")
int Year;

public void setVIN(String vin) {
this.VIN = vin;
}

public String getVIN() {
return VIN;
}

public void setMake(String make) {
this.Make = make;
}

public String getMake() {
return Make;
}

public void setModel(String model) {
this.Model = model;
}

public String getModel() {
return Model;
}

public void setYear(int year) {
this.Year = year;
}

public int getYear() {
return Year;
}
}


Here is second table(repair):



import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "Repair", propOrder = {
"id", "VIN","Description", "Cost"
})

public class XmlSchemaTypeRepair {

@XmlElement(name="id")
int id;
@XmlElement(name="VIN")
String VIN;
String Description;
@XmlElement(name="Cost")
double Cost;

public void setVIN(String vin) {
this.VIN = vin;
}
public String getVIN() {
return VIN;
}
public void setDescription(String description) {
this.Description = description;
}

public String getDescription() {
return Description;
}
public void setID(int ID) {
this.id = ID;
}
public int getID() {
return id;
}
public void setCost(double cost) {
this.Cost = cost;
}

public double getCost() {
return Cost;
}
}


Here is two tables(XML schema):



import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlAccessType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "AutoRepairList")
public class XmlSchema {

@XmlElement(name = "AutoList")
public Autos auto =new Autos();
@XmlElement(name = "RepairList")
public Repair repair =new Repair();

public XmlSchema(){
repair.repairs = new ArrayList<XmlSchemaTypeRepair>();
auto.autos = new ArrayList<XmlSchemaTypeAuto>();
}
public void setRepair(List<XmlSchemaTypeRepair> RepairType){
this.repair.repairs=RepairType;
}

public void setAuto(List<XmlSchemaTypeAuto> AutoType){
this.auto.autos=AutoType;
}

public List<XmlSchemaTypeRepair> getRepair(){
return repair.repairs;
}

public List<XmlSchemaTypeAuto> getAuto(){
return auto.autos;
}

}
class Autos {
@XmlElement(name = "Auto")
public List<XmlSchemaTypeAuto> autos;
}
class Repair {
@XmlElement(name = "Repair")
public List<XmlSchemaTypeRepair> repairs;
}


From XmlSchema class I get :



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://ift.tt/tphNwY">

<xs:element name="AutoRepairList" type="xmlSchema"/>

<xs:complexType name="xmlSchema">
<xs:sequence>
<xs:element name="AutoList" type="autos" minOccurs="0"/>
<xs:element name="RepairList" type="repair" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="autos">
<xs:sequence>
<xs:element name="Auto" type="Auto" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="Auto">
<xs:sequence>
<xs:element name="VIN" type="xs:string" minOccurs="0"/>
<xs:element name="Make" type="xs:string" minOccurs="0"/>
<xs:element name="Model" type="xs:string" minOccurs="0"/>
<xs:element name="Year" type="xs:int"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="repair">
<xs:sequence>
<xs:element name="Repair" type="Repair" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="Repair">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element name="VIN" type="xs:string" minOccurs="0"/>
<xs:element name="Description" type="xs:string" minOccurs="0"/>
<xs:element name="Cost" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:schema>


Here is schema what I need:


enter image description here


No comments:

Post a Comment