The more realistic extractor would be:
import
java.io.BufferedReader;
import
java.io.BufferedWriter;
import
java.io.File;
import
java.io.FileOutputStream;
import
java.io.IOException;
import
java.io.OutputStreamWriter;
import
java.sql.Clob;
import
java.sql.SQLException;
import
java.text.DateFormat;
import
java.text.SimpleDateFormat;
import
java.util.Calendar;
import
java.util.List;
import
javax.persistence.EntityManager;
import
javax.persistence.EntityManagerFactory;
import
javax.persistence.Persistence;
public
class DDLExtractor
{
{
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
ENV);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.createNativeQuery(
NO_SCHEMA).executeUpdate();
em.createNativeQuery(
PRETTY).executeUpdate();
em.createNativeQuery(
NO_PHYSICAL_PROP).executeUpdate();
em.createNativeQuery(
NO_SEGMENT_PROP).executeUpdate();
em.createNativeQuery(
SQL_TERMINATOR).executeUpdate();
createDDL(em,type);
}
em.getTransaction().commit();
em.close();
System.
out.printf("Done. Spent %d secs.", (end - start) / 1000);
}
String sql =
"select object_name from user_objects where object_type = '"+type.toUpperCase()+"' order by 1";
List<String> objectNameList = (List<String>)em.createNativeQuery(sql).getResultList();
sql =
"select DBMS_METADATA.GET_DDL('PACKAGE_SPEC','"+objectName+"') from DUAL";
export(em,
"PACKAGE_SPEC",objectName);
export(em,
"PACKAGE_BODY",objectName);
}
export(em,type,objectName);
}
}
}
String sql =
"select DBMS_METADATA.GET_DDL('"+type.toUpperCase()+"','"+objectName+"') from DUAL";
Clob clob = (Clob)em.createNativeQuery(sql).getSingleResult();
String ddl = clobToString(clob);
File file = getFile(type,objectName);
write(file,ddl);
}
String folder =
"";
String fileName =
"";
folder =
"package";
fileName =
"pks."+objectName.toLowerCase()+".sql";
}
folder =
"package";
fileName =
"pkb."+objectName.toLowerCase()+".sql";
}
folder =
"table";
fileName = objectName.toLowerCase()+
".ddl";
}
folder =
"view";
fileName = objectName.toLowerCase()+
".ddl";
}
File parent =
new File(ENV+"_"+SDF.format(Calendar.getInstance().getTime()),folder);
parent.mkdirs();
}
}
BufferedWriter writer =
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
writer.append(content);
writer.newLine();
writer.close();
}
StringBuffer sb =
new StringBuffer();
}
String line;
BufferedReader br =
new BufferedReader(clob.getCharacterStream());
sb.append(line).append(
"\r\n");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment