本文整理汇总了Java中org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport.getLibrary方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceLibrarySupport.getLibrary方法的具体用法?Java PersistenceLibrarySupport.getLibrary怎么用?Java PersistenceLibrarySupport.getLibrary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport
的用法示例。
在下文中一共展示了PersistenceLibrarySupport.getLibrary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addPersistenceUnitToProjectRoot
import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport; //导入方法依赖的package包/类
/**
* add pu to the project's root, add persistence libraries if appropriate and known
* add db libraries for connection if it's not conteiner managed project
* @param project
* @param root
* @param pu
* @since 1.55
*/
public static void addPersistenceUnitToProjectRoot(Project project, FileObject root, PersistenceUnit persistenceUnit) {
String providerClass = persistenceUnit.getProvider();
boolean libAdded = false;
Library lib = null;
if (providerClass != null) {
Provider selectedProvider = ProviderUtil.getProvider(providerClass, project);
lib = PersistenceLibrarySupport.getLibrary(selectedProvider);
if (lib != null) {
if (!Util.isDefaultProvider(project, selectedProvider)) {
Util.addLibraryToProject(project, lib);
libAdded = true;
} else if (selectedProvider.getAnnotationProcessor() != null) {
Util.addLibraryToProject(project, lib, JavaClassPathConstants.PROCESSOR_PATH);
libAdded = true;
}
}
if (!isContainerManaged(project)) {
DatabaseConnection connection = ProviderUtil.getConnection(persistenceUnit);
if (connection != null) {
JDBCDriver[] driver = JDBCDriverManager.getDefault().getDrivers(connection.getDriverClass());
PersistenceLibrarySupport.addDriver(project, driver[0]);
} else {
Logger.getLogger("global").log(Level.INFO, "Can't find connection for persistence unit"); //NOI18N
}
}
}
try {
ProviderUtil.addPersistenceUnit(persistenceUnit, project, root);
} catch (InvalidPersistenceXmlException ipx) {
// just log for debugging purposes, at this point the user has
// already been warned about an invalid persistence.xml
Logger.getLogger(RelatedCMPWizard.class.getName()).log(Level.FINE, "Invalid persistence.xml: " + ipx.getPath(), ipx); //NOI18N
}
//need to add ap registration lib if exist
if (libAdded && lib != null) {
String projVersion = PersistenceUtils.getJPAVersion(project);
if( projVersion == null ) {
projVersion = "1.0";
}//NOI18N minimum version, will not affect
double version = Math.max(Double.parseDouble(PersistenceUtils.getJPAVersion(lib)), Double.parseDouble(projVersion));
if (version > 1.0 && Util.isJPAVersionSupported(project, Double.toString(version))) {
Library mLib = LibraryManager.getDefault().getLibrary(lib.getName()+"modelgen");//NOI18N
if(mLib!=null) {
Util.addLibraryToProject(project, mLib, JavaClassPathConstants.PROCESSOR_PATH);
}//no real need to add modelgen to compile classpath
}
}
}