cancel
Showing results for 
Search instead for 
Did you mean: 

CRUD Methods in SAPUI5 vs CRUD Methods in JavaEE

Former Member
0 Kudos
Hi,
I would like to can compare the code of two applications, one in JavaEE and another in SAPUI5.
Here is the code in Java, for the JavaEE application's connection :
public static Connection getConnection()
{
Connection cnx = null;
try
{
cnx = DriveManager.getConnection("jdbc:sqlserver://XXX.X.X.X;databasename=Z_MY_MATRL_UI5_APP;user=User;password=Password");
}
catch (SQLException e)
{
e.printStackTrace();
}
return cnx;
There is the code in Javascript, for the SAPUI5 application's connection :
MyMaterial.app.util.DataServices = 
{
callDataService : function(service, name) 
{
var url = "http://xxxxxXXXX.xxxxxxxxx.xxxx:XXXX/sap/opu/odata/sap/Z_MY_MATRL_UI5_APP_SRV";
var oModel = new sap.ui.model.odata.ODataModel(url, true, "User", "Password");
},
};
Here is the code in Java, for the JavaEE application's CRUD method :
public class MaterialDal 
{
public static final String REQUETE_INSERT = "INSERT INTO Material(MaterialDescription) VALUES (?)";

public static final String REQUETE_SELECT = "SELECT * FROM Material";

public static final String REQUETE_UPDATE = "UPDATE Material SET MaterialDescription=? WHERE MaterialNumber = ?";

public static final String REQUETE_DELETE = "DELETE Material WHERE MaterialNumber = ?";
public static boolean insertMaterial(Material material)
{
try(Connection cnx = BddConnexion.getConnection())
{
PreparedStatement requete = cnx.prepareStatement(REQUETE_INSERT);
requete.setString(1, material.getMaterialDescription());
int nbLigneAffectee = requete.executeUpdate();
return nbLigneAffectee != 0;
} 
catch (SQLException e) 
{
return false;
}
}

public static List<Material> getMaterial()
{
try(Connection cnx = BddConnexion.getConnection())
{
List<Material> listMaterial = new ArrayList<Material>();

Statement requete = cnx.createStatement();
ResultSet rs = requete.executeQuery(REQUETE_SELECT);

while (rs.next()) 
{
Material material = new Material();
material.setMaterialNumber(rs.getInt("MaterialNumber"));
material.setMaterialDescription(rs.getString("MaterialDescription"));
listMaterial.add(material);
}
return listMaterial;
} 
catch (Exception e) 
{
return null;
}
}

public static boolean updateMaterial(Material material)
{
try (Connection cnx = BddConnexion.getConnection())
{
PreparedStatement requete = cnx.prepareStatement(REQUETE_UPDATE);
requete.setString(1, material.getMaterialDescription());
requete.setInt(2,material.getMaterialNumber());
int nbLigneAffectee = requete.executeUpdate();
return nbLigneAffectee != 0;
} 
catch (SQLException e) 
{
return false;
}
}

public static boolean deleteMaterial(int number)
{
try(Connection cnx = BddConnexion.getConnection())
{
PreparedStatement requete = cnx.prepareStatement(REQUETE_DELETE);
requete.setInt(1, number);
int nbLigneAffectee = requete.executeUpdate();
return nbLigneAffectee != 0;
} 
catch (SQLException e) 
{
return false;
}
}
}
There is the code in Javascript, for the SAPUI5 application's CRUD method :
MyMaterial.app.util.DataServices = 
{

sendDataService : function(service, name)
{
var url = "http://xxxxxXXXX.xxxxxxxxx.xxxx:XXXX/sap/opu/odata/sap/Z_MY_MATRL_UI5_APP_SRV";
var oModel = new sap.ui.model.odata.ODataModel(url, true, "User", "Password");

    oModel.create(service, null, null, false, 
function(oData, oResponse)
{ 
    sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(oData), name);
    }, 
    function(oResponse)
{ 
    context.setModel(null, name);
    }
    );

oModel.update(service, null, null, false,  
    function(oData, oResponse)
{ 
    sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(oData), name);
    }, 
    function(oResponse)
{ 
    context.setModel(null, name);
    }
    );
oModel.delete(service, null, null, false,  
    function(oData, oResponse)
{ 
    sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(oData), name);
    }, 
    function(oResponse)
{ 
    context.setModel(null, name);
    }
    );
},

callDataService : function(service, name)
{
var url = "http://xxxxxXXXX.xxxxxxxxx.xxxx:XXXX/sap/opu/odata/sap/Z_MY_MATRL_UI5_APP_SRV";
var oModel = new sap.ui.model.odata.ODataModel(url, true, "User", "Password");

    oModel.read(service, null, null, false, 
    function(oData, oResponse)
{ 
    sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(oData), name); 
    }, 
    function(oResponse)
{ 
    sap.ui.getCore().setModel(null, name);
    }
    );
},

};
sap.ui.controller("MyMaterial.controller.AddMaterial", 
{

handleCreate : function (evt) 
{
// show confirmation dialog
var bundle = this.getView().getModel("i18n").getResourceBundle();
sap.m.MessageBox.confirm(
bundle.getText("CreateDialogMsg"),
function (oAction) 
{
if (sap.m.MessageBox.Action.OK === oAction) 
{
// notify user
var successMsg = bundle.getText("CreateDialogSuccessMsg");
sap.m.MessageToast.show(successMsg);
// TODO call proper service method and update model

// value tracking 
oTrack.date = MyMaterial.app.util.Formatter.date(); 
oTrack.time = MyMateriali.app.util.Formatter.time(); 
oTrack.action = "C"; 
console.log(oTrack); 
}
},

bundle.getText("CreateDialogTitle")
);
}
});
sap.ui.controller("MyMaterial.controller.ChangeMaterial", 
{

handleChange : function (evt) 
{
// show confirmation dialog
var bundle = this.getView().getModel("i18n").getResourceBundle();
sap.m.MessageBox.confirm(
bundle.getText("ChangeDialogMsg"),
function (oAction) 
{
if (sap.m.MessageBox.Action.OK === oAction) 
{
// notify user
var successMsg = bundle.getText("ChangeDialogSuccessMsg");
sap.m.MessageToast.show(successMsg);
// TODO call proper service method and update model

// value tracking 
oTrack.date = MyMaterial.app.util.Formatter.date(); 
oTrack.time = MyMaterial.app.util.Formatter.time(); 
oTrack.action = "M"; 
console.log(oTrack); 
}
},
bundle.getText("ChangeDialogTitle")
);
}
});
sap.ui.controller("MyMaterial.controller.DeleteMaterial", 
{

handleChange : function (evt) 
{
// show confirmation dialog
var bundle = this.getView().getModel("i18n").getResourceBundle();
sap.m.MessageBox.confirm(
bundle.getText("DeleteDialogMsg"),
function (oAction) 
{
if (sap.m.MessageBox.Action.OK === oAction) 
{
// notify user
var successMsg = bundle.getText("DeleteDialogSuccessMsg");
sap.m.MessageToast.show(successMsg);
// TODO call proper service method and delete model

// value tracking 
oTrack.date = MyMaterial.app.util.Formatter.date(); 
oTrack.time = MyMaterial.app.util.Formatter.time(); 
oTrack.action = "D"; 
console.log(oTrack); 
}
},
bundle.getText("DeleteDialogTitle")
);
}
});
In the AddMaterial, ChangeMaterial and DeleteMaterial controllers I don't know how call a service methods to create, update or delete material (like in the Java code).
Someone can help me, please?
Thanks in advance.
Best Regards.

Accepted Solutions (0)

Answers (0)