1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| public void makeCreate() {
String tableName = "";
String fileName = "";
String domaine = "";
FileWriter sqlFile = null;
try {
if (connection != null) {
Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery(properties.getProperty("GETTABLES"));
while (res.next()) {
// nom du domaine
domaine = res.getString("OWNER").replace("DEV_", "");
// creation du nom de la table
tableName = res.getString("OWNER") + "." + res.getString("TABLE_NAME");
// création du nom de fichier
fileName = String.format("BCCRE%1sU_%2s", domaine, res.getString("TABLE_NAME"));
// création de l'arborescence
new File(String.format("ECHO_%1s", domaine)).mkdir();
new File(String.format("ECHO_%1s\\bin", domaine)).mkdir();
new File(String.format("ECHO_%1s\\oracle", domaine)).mkdir();
new File(String.format("ECHO_%1s\\oracle\\sql", domaine)).mkdir();
// si on est toujours sur le meme nom de table
if (!tables.contains(tableName)) {
// ajout dans la liste des tables
tables.add(tableName);
/* Creation des ksh */
new File(String.format("ECHO_%1s\\bin\\%2s.ksh",domaine, fileName)).delete();
// création sdu ksh
FileWriter kshFile = new FileWriter(String.format("ECHO_%1s\\bin\\%2s.ksh", domaine, fileName),true);
// création du début du fichier
kshFile.write(String.format(Constants.CARTOUCHE_KSH,domaine, fileName,"création",fileName));
//fermeture du fichier
kshFile.close();
/* création des sql */
// si non null on ferme le fichier
if (sqlFile != null) {
sqlFile.write(")\ntablespace &1\n/");
sqlFile.close();
}
// efface le fichier si il existe
new File(String.format("ECHO_%1s\\oracle\\sql\\%2s.sql", domaine,fileName)).delete();
// créer le fichier
sqlFile = new FileWriter(String.format("ECHO_%1s\\oracle\\sql\\%2s.sql", domaine,fileName), true);
// création du début du fichier
sqlFile.write(String.format(Constants.CARTOUCHE_SQL,domaine, fileName,"Création",fileName));
sqlFile.write(String.format("DROP TABLE %1s\n/\n\n",tableName));
sqlFile.write(String.format("CREATE TABLE %1s(",tableName));
sqlFile.write(String.format("\n\t%1s %2s(%3d)", res.getString("COLUMN_NAME"), res.getString("DATA_TYPE"), res.getInt("DATA_LENGTH")));
if (res.getString("NULLABLE").equals("Y"))
sqlFile.write(" not null");
if (res.getObject("DATA_DEFAULT") != null)
sqlFile.write(String.format(" DEFAULT '%1s'",String.valueOf(res.getObject(("DATA_DEFAULT")))));
} else {
if(res.getString("DATA_TYPE").equals("DATE")){
sqlFile.write(String.format(",\n\t%1s %2s", res.getString("COLUMN_NAME"), res.getString("DATA_TYPE")));
}else{
sqlFile.write(String.format(",\n\t%1s %2s(%3d)", res.getString("COLUMN_NAME"), res.getString("DATA_TYPE"), res.getInt("DATA_LENGTH")));
}
if (res.getString("NULLABLE").equals("Y"))
sqlFile.write(" not null");
}// while ResultSet
if (sqlFile != null) sqlFile.close();
}// if connection
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
} |
Partager