use of org.obeonetwork.dsl.typeslibrary.NativeType in project InformationSystem by ObeoNetwork.
the class ColumnServicesTest method testColumnLengthSIMPLE.
@Test
public void testColumnLengthSIMPLE() {
Column col = (Column) EcoreUtil.create(DatabasePackage.Literals.COLUMN);
TypeInstance type = (TypeInstance) EcoreUtil.create(TypesLibraryPackage.Literals.TYPE_INSTANCE);
NativeType nType = (NativeType) EcoreUtil.create(TypesLibraryPackage.Literals.NATIVE_TYPE);
col.setType(type);
type.setNativeType(nType);
nType.setSpec(NativeTypeKind.SIMPLE);
assertEquals("", new ColumnServices().typeLength(col));
}
use of org.obeonetwork.dsl.typeslibrary.NativeType in project InformationSystem by ObeoNetwork.
the class ColumnServicesTest method testColumnLengthLENGTHANDPRECISION.
@Test
public void testColumnLengthLENGTHANDPRECISION() {
Column col = (Column) EcoreUtil.create(DatabasePackage.Literals.COLUMN);
TypeInstance type = (TypeInstance) EcoreUtil.create(TypesLibraryPackage.Literals.TYPE_INSTANCE);
NativeType nType = (NativeType) EcoreUtil.create(TypesLibraryPackage.Literals.NATIVE_TYPE);
col.setType(type);
type.setNativeType(nType);
nType.setSpec(NativeTypeKind.LENGTH_AND_PRECISION);
type.setLength(255);
type.setPrecision(8);
assertEquals("255,8", new ColumnServices().typeLength(col));
}
use of org.obeonetwork.dsl.typeslibrary.NativeType in project InformationSystem by ObeoNetwork.
the class EntityToMLD method loadTypesLibrary.
private Map<String, NativeType> loadTypesLibrary() {
Map<String, NativeType> types = new HashMap<String, NativeType>();
TypesLibrary typesLibrary = TypesLibraryUtil.getLogicalTypesLibrary(getResourceSet());
for (Iterator<EObject> it = typesLibrary.eAllContents(); it.hasNext(); ) {
EObject object = it.next();
if (object instanceof NativeType) {
NativeType type = (NativeType) object;
types.put(type.getName(), type);
}
}
return types;
}
use of org.obeonetwork.dsl.typeslibrary.NativeType in project InformationSystem by ObeoNetwork.
the class EntityToMLD method resolveType.
private TypeInstance resolveType(DataType type, String physicalSize) {
TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
if (type != null && type.getName() != null) {
if (getTypeProperties().containsKey(type.getName())) {
String logicalTypeName = getTypeProperties().getProperty(type.getName());
NativeType logicalType = nativeTypesMap.get(logicalTypeName);
if (logicalType != null) {
typeInstance.setNativeType(logicalType);
if (physicalSize != null && physicalSize.length() > 0) {
if (physicalSize.contains(",")) {
int length = Integer.parseInt(physicalSize.substring(0, physicalSize.indexOf(",")));
int precision = Integer.parseInt(physicalSize.substring(physicalSize.indexOf(",") + 1));
typeInstance.setLength(length);
typeInstance.setPrecision(precision);
} else {
typeInstance.setLength(Integer.parseInt(physicalSize));
}
}
}
}
}
return typeInstance;
}
use of org.obeonetwork.dsl.typeslibrary.NativeType in project InformationSystem by ObeoNetwork.
the class DatabaseEditLabelServices method setType.
private void setType(Column column, String typeName, Collection<NativeTypesLibrary> typesLibraries) {
for (NativeTypesLibrary nativeTypesLibrary : typesLibraries) {
for (NativeType nativeType : nativeTypesLibrary.getNativeTypes()) {
String typePattern = getNativeTypePattern(nativeType);
String typeRegexPattern = null;
if (nativeType.getSpec() == NativeTypeKind.ENUM) {
typeRegexPattern = typePattern;
} else {
typeRegexPattern = typePattern.replace("%n", "(.*)");
typeRegexPattern = typeRegexPattern.replace("%p", "(.*)");
}
if (typeRegexPattern != null) {
Pattern ptn = null;
try {
ptn = Pattern.compile(typeRegexPattern, Pattern.CASE_INSENSITIVE);
} catch (Exception e) {
// Do nothing, the loop will try the other types
}
if (ptn != null) {
Matcher matcher = ptn.matcher(typeName);
if (matcher.matches()) {
// Ensure there is a type instance
if (column.getType() == null || (column.getType() instanceof TypeInstance == false)) {
TypeInstance type = TypesLibraryFactory.eINSTANCE.createTypeInstance();
type.setNativeType(nativeType);
column.setType(type);
}
TypeInstance columnType = ((TypeInstance) column.getType());
columnType.setNativeType(nativeType);
switch(nativeType.getSpec()) {
case SIMPLE:
// Nothing special to do
return;
case LENGTH:
// Retrieve length
String lengthString = matcher.group(1).trim();
// Ensure its a string representing an int
int length = getIntValue(lengthString);
columnType.setLength(length);
return;
case LENGTH_AND_PRECISION:
int nPos = typePattern.indexOf("%n");
int pPos = typePattern.indexOf("%p");
String nString = null;
String pString = null;
if (nPos < pPos) {
nString = matcher.group(1).trim();
nString = matcher.group(2).trim();
} else {
nString = matcher.group(2).trim();
pString = matcher.group(1).trim();
}
int nValue = getIntValue(nString);
int pValue = getIntValue(pString);
columnType.setLength(nValue);
columnType.setPrecision(pValue);
break;
case ENUM:
// Retrieves values
columnType.getLiterals().clear();
String valuesString = matcher.group(1).trim();
for (String value : valuesString.split(",")) {
columnType.getLiterals().add(value.trim());
}
return;
}
}
}
}
}
}
}
Aggregations