Exemplo n.º 1
0
  public String getTableName(ENamedElement element) {
    String name = null;
    String typePrefix = null;

    if (element instanceof EClass) {
      typePrefix = TYPE_PREFIX_CLASS;
      name = DBAnnotation.TABLE_NAME.getValue(element);
      if (name == null) {
        name =
            isQualifiedNames()
                ? EMFUtil.getQualifiedName((EClass) element, NAME_SEPARATOR)
                : element.getName();
      }
    } else if (element instanceof EPackage) {
      typePrefix = TYPE_PREFIX_PACKAGE;
      name = DBAnnotation.TABLE_NAME.getValue(element);
      if (name == null) {
        name =
            isQualifiedNames()
                ? EMFUtil.getQualifiedName((EPackage) element, NAME_SEPARATOR)
                : element.getName();
      }
    } else {
      throw new ImplementationError("Unknown element: " + element); // $NON-NLS-1$
    }

    String prefix = getTableNamePrefix();
    if (prefix.length() != 0 && !prefix.endsWith(NAME_SEPARATOR)) {
      prefix += NAME_SEPARATOR;
    }

    return getName(prefix + name, typePrefix + getUniqueID(element), getMaxTableNameLength());
  }
Exemplo n.º 2
0
  @Override
  public void setUp() throws Exception {
    super.setUp();

    pkg = EMFUtil.createEPackage("customTest", "ct", "http://cdo.emf.eclipse.org/customTest.ecore");
    EDataType custom = EcoreFactory.eINSTANCE.createEDataType();
    custom.setInstanceClass(CustomType.class);
    custom.setName("CustomType");

    pkg.getEClassifiers().add(custom);

    cls = EMFUtil.createEClass(pkg, "Foobar", false, false);
    att = EMFUtil.createEAttribute(cls, "att", custom);

    CDOUtil.prepareDynamicEPackage(pkg);
  }
Exemplo n.º 3
0
 private void mapPackageInfos(
     InternalCDOPackageInfo[] packageInfos, Connection connection, boolean unmap) {
   boolean supportingEcore = getStore().getRepository().isSupportingEcore();
   for (InternalCDOPackageInfo packageInfo : packageInfos) {
     EPackage ePackage = packageInfo.getEPackage();
     if (!CDOModelUtil.isCorePackage(ePackage) || supportingEcore) {
       mapClasses(connection, unmap, EMFUtil.getPersistentClasses(ePackage));
     }
   }
 }
Exemplo n.º 4
0
  public String getTableName(EClass eClass, EStructuralFeature feature) {
    String name = DBAnnotation.TABLE_NAME.getValue(eClass);
    if (name == null) {
      name =
          isQualifiedNames() ? EMFUtil.getQualifiedName(eClass, NAME_SEPARATOR) : eClass.getName();
    }

    name += NAME_SEPARATOR;
    name += feature.getName();
    name += FEATURE_TABLE_SUFFIX;

    String prefix = getTableNamePrefix();
    if (prefix.length() != 0 && !prefix.endsWith(NAME_SEPARATOR)) {
      prefix += NAME_SEPARATOR;
    }

    return getName(
        prefix + name, TYPE_PREFIX_FEATURE + getUniqueID(feature), getMaxTableNameLength());
  }
Exemplo n.º 5
0
  /**
   * Constructs a test-specific EPackage of the format "pkg123_name". Using this instead of (just) a
   * hardcoded name for the test package, ensures that the test method is isolated from all others.
   *
   * @param name the test-local name of the package or <code>null</code> .
   * @return the created package.
   * @see #createUniquePackage()
   */
  public final EPackage createUniquePackage(String name) {
    if (dynamicPackageNumber == 0) {
      dynamicPackageNumber = ++dynamicPackageCounter;
    }

    StringBuilder builder = new StringBuilder();
    builder.append("pkg");
    builder.append(dynamicPackageNumber);

    if (name != null) {
      builder.append('_');
      builder.append(name);
    }

    final String uniqueName = builder.toString();

    EPackage ePackage = EMFUtil.createEPackage(uniqueName, uniqueName, "http://" + uniqueName);
    ePackage
        .eAdapters()
        .add(
            new AdapterImpl() {
              @Override
              public void notifyChanged(Notification msg) {
                if (msg.isTouch()) {
                  return;
                }

                Object feature = msg.getFeature();
                if (feature == EcorePackage.Literals.EPACKAGE__NS_PREFIX
                    || feature == EcorePackage.Literals.EPACKAGE__NS_URI
                    || feature == EcorePackage.Literals.ENAMED_ELEMENT__NAME) {
                  throw new ImplementationError("Don't change the unique package " + uniqueName);
                }
              }
            });

    return ePackage;
  }
Exemplo n.º 6
0
 public EPackage[] loadPackageUnit(InternalCDOPackageUnit packageUnit) {
   DB4OPackageUnit db4OPackageUnit =
       getPrimitivePackageUnitMap().get(packageUnit.getTopLevelPackageInfo().getPackageURI());
   return EMFUtil.getAllPackages(db4OPackageUnit.getEPackage());
 }