public static DomainClass getDomainClassFor(final Class<? extends DomainObject> className) { final DomainModel domainModel = FenixFramework.getDomainModel(); for (DomainClass domainClass : domainModel.getDomainClasses()) { if (domainClass.getFullName().equals(className.getName())) { return domainClass; } } return null; }
public DomainEntity findClassOrExternal(String name) { DomainEntity domClass = findClass(name); if (domClass == null) { domClass = external.get(name); } return domClass; }
public FenixCodeGenerator(CompilerArgs compArgs, DomainModel domainModel) { super(compArgs, domainModel); jsonElementVt = domainModel.findValueType("JsonElement"); }
/** * @return a <code>Map</code> of <code>Classes</code> to {@link DomainClass} with all the existing classes of the * domain model, except those annotated with {@link NoDomainMetaObjects}. */ private Map<Class<? extends DomainObject>, DomainClass> getExistingDomainClasses(DomainModel domainModel) { Map<Class<? extends DomainObject>, DomainClass> existingDomainClasses = new HashMap<Class<? extends DomainObject>, DomainClass>(); Iterator<DomainClass> domainClassesIterator = domainModel.getClasses(); try { while (domainClassesIterator.hasNext()) { DomainClass dmlDomainClass = domainClassesIterator.next(); Class<? extends DomainObject> domainClass = (Class<? extends DomainObject>) Class.forName(dmlDomainClass.getFullName()); if (!domainClass.getSuperclass().getName().equals(domainClass.getName() + "_Base")) { throw new Error("The domain class: " + domainClass + " must extend its corresponding _Base class."); } if (domainClass.isAnnotationPresent(NoDomainMetaObjects.class)) { continue; } existingDomainClasses.put(domainClass, dmlDomainClass); } return existingDomainClasses; } catch (ClassNotFoundException e) { e.printStackTrace(); throw new Error(e); } }
DomainModel model = new DomainModel(); model.finalizeDomain(checkForMissingExternals); return model;
public void start() { for (Iterator iter = getModel().getClasses(); iter.hasNext();) { String className = ((DomainClass) iter.next()).getFullName(); try { loadClass(className); } catch (ClassNotFoundException cnfe) { System.err.println("Error: Couldn't load class " + className + ": " + cnfe); } } } }
/** Scans for domain classes annotated with @Indexed **/ private static Set<Class<?>> getIndexedDomainClasses() { Set<Class<?>> classList = new HashSet<Class<?>>(); for (DomainClass dc : FenixFramework.getDomainModel().getDomainClasses()) { try { Class<?> domainClass = Class.forName(dc.getFullName()); if (domainClass.getAnnotation(org.hibernate.search.annotations.Indexed.class) != null) { logger.trace("Indexing " + dc.getFullName()); classList.add(domainClass); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } return classList; } }
public boolean isDomainBaseClass(String name) { return (name.endsWith("_Base") && (getModel().findClass(name.substring(0, name.length() - 5)) != null)); }
@Override public void generateCode() { File file = new File(getBaseDirectoryFor("") + "/META-INF/orm.xml"); file.getParentFile().mkdirs(); FileWriter fileWriter = null; try { fileWriter = new FileWriter(file); this.ormWriter = new PrintWriter(fileWriter, true); ormBeginFile(); super.generateCode(); ormGenerateNonBaseClasses(getDomainModel().getClasses()); ormEndFile(); generatePersistenceXml(); } catch (IOException ioe) { throw new Error("Can't open file " + file); } finally { if (fileWriter != null) { try { fileWriter.close(); } catch (IOException e) { } } } }
public boolean isEnumType(String valueTypeName) { ValueType vt = findValueType(valueTypeName); return ((vt != null) && vt.isEnum()); }
private static void load() { startActivities = new HashMap<String, Activity<? extends Process>>(); final Collection<DomainClass> domainClasses = FenixFramework.getDomainModel().getDomainClasses(); for (final DomainClass domainClass : domainClasses) { try { final Class<?> clazz = Class.forName(domainClass.getFullName()); if (Process.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) { final Activity<? extends Process> activity = getStartActivity((Class<? extends Process>) clazz); if (activity != null) { startActivities.put(domainClass.getFullName(), activity); } } } catch (Exception e) { logger.error(e.getMessage(), e); } } }
public boolean isDomainNonBaseClass(String name) { return (getModel().findClass(name) != null); }
/** * Generate the backend-specific code for the domain model. */ public void generateCode() { // used by the value-type generator ValueTypeSerializationGenerator valueTypeGenerator = new ValueTypeSerializationGenerator(compArgs, domainModel); valueTypeGenerator.generateCode(); generateClasses(getDomainModel().getClasses()); generateBackEndId(); }
public static String getJdbcTypeFor(DomainModel model, String valueType) { ValueType vt = model.findValueType(valueType); String jdbcType = null; if (vt.isEnum()) { jdbcType = "VARCHAR"; } else if (vt.isBuiltin()) { jdbcType = BUILT_IN_JDBC_MAP.get(valueType); } else { List<ExternalizationElement> extElems = vt.getExternalizationElements(); if (extElems.size() != 1) { return BUILT_IN_JDBC_MAP.get("JsonElement"); } jdbcType = getJdbcTypeFor(model, extElems.get(0).getType().getDomainName()); } if (jdbcType == null) { throw new Error("Couldn't find a JDBC type for the value type " + valueType); } return jdbcType; } }
@SuppressWarnings("unchecked") public static List<Class<? extends DomainObject>> getDomainClassHierarchy(final Class<?> superClass, boolean shouldContainSuperClass, boolean shouldContainAbstractClass) { final DomainModel domainModel = FenixFramework.getDomainModel(); List<Class<? extends DomainObject>> classNames = new ArrayList<Class<? extends DomainObject>>(); for (DomainClass domainClass : domainModel.getDomainClasses()) { if (isClassInstance(domainClass, superClass, shouldContainSuperClass)) { try { final Class<? extends DomainObject> clazz = (Class<? extends DomainObject>) Class.forName(domainClass.getFullName()); if (shouldContainAbstractClass || !Modifier.isAbstract(clazz.getModifiers())) { classNames.add(clazz); } } catch (ClassNotFoundException e) { // ignore error e.printStackTrace(); } } } return classNames; }
private static long getMaxIdForClass(String className, long lowestId, long highestId) throws SQLException { Connection conn = TransactionSupport.getCurrentSQLConnection(); try (Statement stmt = conn.createStatement()) { StringBuilder sqlStmtText = new StringBuilder(); sqlStmtText.append("SELECT MAX(OID) FROM `"); DomainClass domainClass = FenixFramework.getDomainModel().findClass(className); sqlStmtText.append(OJBMetadataGenerator.getExpectedTableName(domainClass)); sqlStmtText.append("` WHERE OID > "); sqlStmtText.append(lowestId); sqlStmtText.append(" AND OID <= "); sqlStmtText.append(highestId); sqlStmtText.append(";"); ResultSet rs = stmt.executeQuery(sqlStmtText.toString()); rs.first(); return rs.getLong(1); // getLong() will return 0 in case there is no line matching the query } }
vt = new PlainValueType(baseTypeName); } else { vt = model.findValueType(baseTypeName); if (vt == null) { throw new SemanticException("Unknown value type: " + baseTypeName);
private static int createAnyMissingRecords(Map<Class<? extends AbstractDomainObject>, DomainClassInfo> map, ArrayList<DomainClassInfo> array, int maxId, DomainModel domainModel) throws ClassNotFoundException { ArrayList<DomainClassInfo> newClasses = new ArrayList<DomainClassInfo>(); for (DomainClass domClass : domainModel.getDomainClasses()) { Class<? extends AbstractDomainObject> javaClass = findClass(domClass.getFullName()); if (!map.containsKey(javaClass)) { // special case: record for DomainRoot must get class id = 0 int id = javaClass == DomainRoot.class ? 0 : ++maxId; DomainClassInfo classInfo = new DomainClassInfo(javaClass, id); addNewInfo(map, array, classInfo); newClasses.add(classInfo); if (logger.isInfoEnabled()) { logger.info("Registering new domain class '{}' with id '{}'", javaClass.getName(), Long.toHexString(classInfo.classId)); } } } if (!newClasses.isEmpty()) { JVSTMBackEnd.getInstance().getRepository() .storeDomainClassInfos(newClasses.toArray(new DomainClassInfo[newClasses.size()])); } return maxId; }
static void initializeClassInfos(DomainModel model, int serverId) { serverOidBase = (long) serverId << 48; // the server id provides de 16 most significant bits of the OID int maxId = 0; Map<Class, DomainClassInfo> map = new IdentityHashMap<Class, DomainClassInfo>(); ArrayList<DomainClassInfo> array = new ArrayList<DomainClassInfo>(); // special case: create record for DomainRoot (must get class id = 0) addNewInfo(map, array, new DomainClassInfo(DomainRoot.class, 0)); // create all other records, skipping DomainRoot of course for (DomainClass domClass : model.getDomainClasses()) { Class javaClass; try { javaClass = Class.forName(domClass.getFullName()); } catch (ClassNotFoundException e) { throw new ExceptionInInitializerError(e); } if (javaClass != DomainRoot.class && !map.containsKey(javaClass)) { DomainClassInfo classInfo = new DomainClassInfo(javaClass, ++maxId); addNewInfo(map, array, classInfo); } } // finish the initialization by assigning to the static variables classInfoMap = Collections.unmodifiableMap(map); classInfoById = new DomainClassInfo[maxId + 1]; array.toArray(classInfoById); }
static void initializeClassInfos(DomainModel model, int serverId) { serverOidBase = (long) serverId << 48; // the server id provides de 16 most significant bits of the OID int maxId = 0; Map<Class, DomainClassInfo> map = new IdentityHashMap<Class, DomainClassInfo>(); ArrayList<DomainClassInfo> array = new ArrayList<DomainClassInfo>(); // special case: create record for DomainRoot (must get class id = 0) addNewInfo(map, array, new DomainClassInfo(DomainRoot.class, 0)); // create all other records, skipping DomainRoot of course for (DomainClass domClass : model.getDomainClasses()) { Class javaClass; try { javaClass = Class.forName(domClass.getFullName()); } catch (ClassNotFoundException e) { throw new ExceptionInInitializerError(e); } if (javaClass != DomainRoot.class && !map.containsKey(javaClass)) { DomainClassInfo classInfo = new DomainClassInfo(javaClass, ++maxId); addNewInfo(map, array, classInfo); } } // finish the initialization by assigning to the static variables classInfoMap = Collections.unmodifiableMap(map); classInfoById = new DomainClassInfo[maxId + 1]; array.toArray(classInfoById); }