当前位置: 首页>>代码示例>>Java>>正文


Java PersistenceLibrarySupport类代码示例

本文整理汇总了Java中org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport的典型用法代码示例。如果您正苦于以下问题:Java PersistenceLibrarySupport类的具体用法?Java PersistenceLibrarySupport怎么用?Java PersistenceLibrarySupport使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PersistenceLibrarySupport类属于org.netbeans.modules.j2ee.persistence.wizard.library包,在下文中一共展示了PersistenceLibrarySupport类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSupportedProviders

import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport; //导入依赖的package包/类
@Override
public List<Provider> getSupportedProviders() {
    List<Provider> model = new ArrayList<Provider>();
    //get all, but remove duplicates
    for (Provider each : PersistenceLibrarySupport.getProvidersFromLibraries()) {
        boolean found = false;
        for (int i = 0; i < model.size(); i++) {
            Object elem = model.get(i);
            if (elem instanceof Provider && each.equals(elem)) {
                found = true;
                break;
            }
        }
        if (!found) {
            model.add(each);
        }
    }
    return model;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Util.java

示例2: getSupportedProviders

import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport; //导入依赖的package包/类
@Override
public List<Provider> getSupportedProviders() {
    ArrayList<Provider> providers = new ArrayList<Provider>();
    for (Provider each : PersistenceLibrarySupport.getProvidersFromLibraries()){
        boolean found = false;
        for (int i = 0; i < providers.size(); i++) {
            Object elem = providers.get(i);
            if (elem instanceof Provider && each.equals(elem)){
                found = true;
                break;
            }
        }
        if (!found){
           providers.add(each);
        }
    }
    return providers;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:PersistenceProviderComboboxHelper.java

示例3: findJPALibrary

import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport; //导入依赖的package包/类
private ClassPath findJPALibrary() {
    Library library = PersistenceLibrarySupport.getFirstProviderLibrary();
    if (library == null) {
        return null;
    }
    List<URL> urls = library.getContent("classpath"); // NOI18N
    return ClassPathSupport.createClassPath(urls.toArray(new URL[urls.size()]));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:JPAClassPathHelper.java

示例4: isValid

import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport; //导入依赖的package包/类
@Override
public boolean isValid() {
    SourceGroup sourceGroup = getComponent().getLocationValue();
    if (sourceGroup == null) {
        setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class, "ERR_JavaTargetChooser_SelectSourceGroup"));
        return false;
    }

    String packageName = getComponent().getPackageName();
    if (packageName.trim().equals("")) { // NOI18N
        setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class, "ERR_JavaTargetChooser_CantUseDefaultPackage"));
        return false;
    }

    if (!JavaIdentifiers.isValidPackageName(packageName)) {
        setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class,"ERR_JavaTargetChooser_InvalidPackage")); //NOI18N
        return false;
    }

    if (!SourceGroups.isFolderWritable(sourceGroup, packageName)) {
        setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class, "ERR_JavaTargetChooser_UnwritablePackage")); //NOI18N
        return false;
    }

    // issue 92192: need to check that we will have a persistence provider
    // available to add to the classpath while generating entity classes (unless
    // the classpath already contains one)
    ClassPath classPath = null;
    try {
        FileObject packageFO = SourceGroups.getFolderForPackage(sourceGroup, packageName, false);
        if (packageFO == null) {
            packageFO = sourceGroup.getRootFolder();
        }
        classPath = ClassPath.getClassPath(packageFO, ClassPath.COMPILE);
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, null, e);
    }
    if (classPath != null) {
        if (classPath.findResource("javax/persistence/EntityManager.class") == null) { // NOI18N
            // initialize the provider list lazily
            if (providers == null) {
                providers = PersistenceLibrarySupport.getProvidersFromLibraries();
            }
            if (providers.size() == 0) {
                setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class, "ERR_NoJavaPersistenceAPI")); // NOI18N
                return false;
            }
        }
    } else {
        LOGGER.warning("Cannot get a classpath for package " + packageName + " in " + sourceGroup); // NOI18N
    }

    SelectedTables selectedTables = getComponent().getSelectedTables();
    // check for null needed since isValid() can be called when
    // EntityClassesPanel.update() has not been called yet, e.g. from within
    // EntityClassesPanel.initialize()
    if (selectedTables != null) {
        String problem = selectedTables.getFirstProblemDisplayName();
        if (problem != null) {
            setErrorMessage(problem);
            return false;
        }
    }

    setErrorMessage(" "); // NOI18N
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:68,代码来源:EntityClassesPanel.java

示例5: 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
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:58,代码来源:Util.java

示例6: isValid

import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport; //导入依赖的package包/类
@Override
public boolean isValid() {
    SourceGroup sourceGroup = getComponent().getLocationValue();
    if (sourceGroup == null) {
        setErrorMessage(NbBundle.getMessage(DBScriptPanel.class, "ERR_JavaTargetChooser_SelectSourceGroup"));
        return false;
    }
    
    String packageName = getComponent().getPackageName();
    if (packageName.trim().equals("")) { // NOI18N
        setErrorMessage(NbBundle.getMessage(DBScriptPanel.class, "ERR_JavaTargetChooser_CantUseDefaultPackage"));
        return false;
    }
    
    if (!JavaIdentifiers.isValidPackageName(packageName)) {
        setErrorMessage(NbBundle.getMessage(DBScriptPanel.class, "ERR_JavaTargetChooser_InvalidPackage")); //NOI18N
        return false;
    }
    
    if (!SourceGroups.isFolderWritable(sourceGroup, packageName)) {
        setErrorMessage(NbBundle.getMessage(DBScriptPanel.class, "ERR_JavaTargetChooser_UnwritablePackage")); //NOI18N
        return false;
    }

    // issue 92192: need to check that we will have a persistence provider
    // available to add to the classpath while generating entity classes (unless
    // the classpath already contains one)
    ClassPath classPath = null;
    FileObject rPackageFO = null;
    try {
        FileObject packageFO = SourceGroups.getFolderForPackage(sourceGroup, packageName, false);
        rPackageFO = packageFO;
        if (packageFO == null) {
            packageFO = sourceGroup.getRootFolder();
        }
        classPath = ClassPath.getClassPath(packageFO, ClassPath.COMPILE);
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, null, e);
    }
    if (classPath != null) {
        if (classPath.findResource("javax/persistence/EntityManager.class") == null) { // NOI18N
            // initialize the provider list lazily
            if (providers == null) {
                providers = PersistenceLibrarySupport.getProvidersFromLibraries();
            }
            if (providers.isEmpty()) {
                setErrorMessage(NbBundle.getMessage(DBScriptPanel.class, "ERR_NoJavaPersistenceAPI")); // NOI18N
                return false;
            }
        }
    } else {
        LOGGER.log(Level.WARNING, "Cannot get a classpath for package {0} in {1}", new Object[]{packageName, sourceGroup}); // NOI18N
    }
    String name = getComponent().getScriptName().trim();
    if (name.length() == 0) {
        setErrorMessage(NbBundle.getMessage(DBScriptPanel.class, "ERR_JavaTargetChooser_InvalidNameLength0"));//NOI18N
        return false;
    }
    if (rPackageFO != null) {
        //check if file exist
        if (name.endsWith("." + EXTENSION)) {
            name = name.substring(0, name.length() - 4);
        }
        if (rPackageFO.getFileObject(name, EXTENSION) != null) {
            setErrorMessage(NbBundle.getMessage(DBScriptPanel.class, "ERR_JavaTargetChooser_InvalidNameExists", name));//NOI18N
            return false;
        }
    }
    if(deepVerify) {
        PersistenceEnvironment pe = project.getLookup().lookup(PersistenceEnvironment.class);
        List<String> problems = DBScriptWizard.run(project, null, pe, null, true);
        if(problems != null && !problems.isEmpty()){
            setErrorMessage(problems.get(0));
            return false;
        }
        deepVerify = false;
    }
    setErrorMessage(" "); // NOI18N
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:81,代码来源:DBScriptPanel.java

示例7: isValid

import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport; //导入依赖的package包/类
@Override
public boolean isValid() {
    SourceGroup sourceGroup = getComponent().getLocationValue();
    if (sourceGroup == null) {
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_SelectSourceGroup"));
        return false;
    }

    String packageName = getComponent().getPackageName();
    if (packageName.trim().equals("")) { // NOI18N
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_CantUseDefaultPackage"));
        return false;
    }

    if (!JavaIdentifiers.isValidPackageName(packageName)) {
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_InvalidPackage")); //NOI18N
        return false;
    }

    if (!SourceGroupSupport.isFolderWritable(sourceGroup, packageName)) {
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_UnwritablePackage")); //NOI18N
        return false;
    }

    if (getComponent().getFileName().trim().equals("")) { // NOI18N
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_CantUseDefaultFileName"));
        return false;
    }

    // issue 92192: need to check that we will have a persistence provider
    // available to add to the classpath while generating entity classes (unless
    // the classpath already contains one)
    FileObject packageFO = SourceGroupSupport.getFolderForPackage(sourceGroup, packageName, false);
    if (packageFO == null) {
        packageFO = sourceGroup.getRootFolder();
    }
    ClassPath classPath = ClassPath.getClassPath(packageFO, ClassPath.COMPILE);

    if (classPath != null) {
        if (classPath.findResource("javax/persistence/EntityManager.class") == null) { // NOI18N
            // initialize the provider list lazily
            if (providers == null) {
                providers = PersistenceLibrarySupport.getProvidersFromLibraries();
            }
            if (providers.size() == 0) {
                setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_NoJavaPersistenceAPI")); // NOI18N
                return false;
            }
        }
    } else {
        LOGGER.warning("Cannot get a classpath for package " + packageName + " in " + sourceGroup); // NOI18N
    }

    SelectedTables selectedTables = getComponent().getSelectedTables();
    // check for null needed since isValid() can be called when
    // EntityClassesPanel.update() has not been called yet, e.g. from within
    // EntityClassesPanel.initialize()
    if (selectedTables != null) {
        String problem = selectedTables.getFirstProblemDisplayName();
        if (problem != null) {
            setErrorMessage(problem);
            return false;
        }
    }

    setErrorMessage(" "); // NOI18N
    return true;
}
 
开发者ID:jeddict,项目名称:jeddict,代码行数:69,代码来源:EntityClassesConfigurationPanel.java

示例8: isValid

import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport; //导入依赖的package包/类
@Override
public boolean isValid() {
    SourceGroup sourceGroup = getComponent().getLocationValue();
    if (sourceGroup == null) {
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_SelectSourceGroup"));
        return false;
    }

    String packageName = getComponent().getPackageName();
    if (packageName.trim().equals("")) { // NOI18N
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_CantUseDefaultPackage"));
        return false;
    }

    if (!JavaIdentifiers.isValidPackageName(packageName)) {
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_InvalidPackage")); //NOI18N
        return false;
    }

    if (!SourceGroups.isFolderWritable(sourceGroup, packageName)) {
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_UnwritablePackage")); //NOI18N
        return false;
    }

    if (getComponent().getFileName().trim().equals("")) { // NOI18N
        setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_JavaTargetChooser_CantUseDefaultFileName"));
        return false;
    }

    // issue 92192: need to check that we will have a persistence provider
    // available to add to the classpath while generating entity classes (unless
    // the classpath already contains one)
    ClassPath classPath = null;
    try {
        FileObject packageFO = SourceGroups.getFolderForPackage(sourceGroup, packageName, false);
        if (packageFO == null) {
            packageFO = sourceGroup.getRootFolder();
        }
        classPath = ClassPath.getClassPath(packageFO, ClassPath.COMPILE);
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, null, e);
    }
    if (classPath != null) {
        if (classPath.findResource("javax/persistence/EntityManager.class") == null) { // NOI18N
            // initialize the provider list lazily
            if (providers == null) {
                providers = PersistenceLibrarySupport.getProvidersFromLibraries();
            }
            if (providers.size() == 0) {
                setErrorMessage(NbBundle.getMessage(EntityClassesConfigurationPanel.class, "ERR_NoJavaPersistenceAPI")); // NOI18N
                return false;
            }
        }
    } else {
        LOGGER.warning("Cannot get a classpath for package " + packageName + " in " + sourceGroup); // NOI18N
    }

    SelectedTables selectedTables = getComponent().getSelectedTables();
    // check for null needed since isValid() can be called when
    // EntityClassesPanel.update() has not been called yet, e.g. from within
    // EntityClassesPanel.initialize()
    if (selectedTables != null) {
        String problem = selectedTables.getFirstProblemDisplayName();
        if (problem != null) {
            setErrorMessage(problem);
            return false;
        }
    }

    setErrorMessage(" "); // NOI18N
    return true;
}
 
开发者ID:foxerfly,项目名称:Netbeans-JPA-Modeler,代码行数:73,代码来源:EntityClassesConfigurationPanel.java


注:本文中的org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。