protected EODataSource _localDataSource() { if (null == dataSource()) { setDataSource( (EODatabaseDataSource) _WOJExtensionsUtil.valueForBindingOrNull("dataSource", this)); if (null == dataSource()) { String anEntityName = _localSourceEntityName(); EOModelGroup aModelGroup = EOModelGroup.defaultGroup(); EOEntity anEntity = aModelGroup.entityNamed(anEntityName); if (anEntity == null) { throw new IllegalStateException( "<" + getClass().getName() + " could not find entity named " + anEntityName + ">"); } EOEntity destinationEntity = entityWithEntityAndKeyPath(anEntity, _localRelationshipKey()); Object _source = _localSourceObject(); EOEditingContext anEditingContext = null; if (_source instanceof EOEnterpriseObject) { anEditingContext = ((EOEnterpriseObject) _source).editingContext(); } if (anEditingContext == null) { anEditingContext = session().defaultEditingContext(); } EODatabaseDataSource aDatabaseDataSource = new EODatabaseDataSource(anEditingContext, destinationEntity.name()); setDataSource(aDatabaseDataSource); } } return dataSource(); }
@After public void tearDown() { EOModelGroup modelGroup = EOModelGroup.defaultGroup(); EOModel model = modelGroup.modelNamed(TEST_MODEL_NAME); if (model != null) { modelGroup.removeModel(model); } }
private EOEntity entityForTableName(String tableName) { EOModelGroup modelGroup = EOModelGroup.globalModelGroup(); for (EOModel model : modelGroup.models()) { for (EOEntity entity : model.entities()) { if (entity.externalName() != null && entity.externalName().equalsIgnoreCase(tableName)) { return entity; } } } return null; }
@Test public void loadMoreThanOneModel() throws Exception { createEditingContext(TEST_MODEL_NAME, "AnotherTest"); EOModel result = EOModelGroup.defaultGroup().modelNamed(TEST_MODEL_NAME); assertThat(result, notNullValue()); result = EOModelGroup.defaultGroup().modelNamed("AnotherTest"); assertThat(result, notNullValue()); }
@Test public void doNotRemoveModelsNotLoadedByTheEditingContextRule() throws Throwable { URL url = getClass().getResource("/" + TEST_MODEL_NAME + ".eomodeld"); EOModelGroup.defaultGroup().addModelWithPathURL(url); AbstractEditingContextRule editingContext = createEditingContext(); editingContext.before(mockTarget); editingContext.after(mockTarget); assertThat(EOModelGroup.defaultGroup().modelNamed(TEST_MODEL_NAME), notNullValue()); }
public SEEntityStats entityStatsForEntityNamed(String entityName) { EOEntity entity = _modelGroup.entityNamed(entityName); EOModel model = entity.model(); SEModelStats modelStats = modelStatsForModelNamed(model.name()); SEEntityStats entityStats = modelStats.entityStatsForEntityNamed(entityName); return entityStats; }
@Override public D2WContext subContext() { if (_context == null) { String s = hasBinding("_dynamicPage") ? (String) valueForBinding("_dynamicPage") : null; if (s != null) { _context = makeSubContextForDynamicPageNamed(s, session()); } else { _context = makeSubContextForTaskAndEntity( task(), EOModelGroup.defaultGroup().entityNamed(entityName()), session()); } String s1 = lookFromSettings(); if (s1 != null) { _context.takeValueForInferrableKey(lookFromSettings(), D2WModel.LookKey); } _context.takeValueForKey( _context.task() + "CurrentObject", D2WComponent.keyForGenerationReplacementForVariableNamed("currentObject")); } NSDictionary nsdictionary = settings(); if (nsdictionary != null) { String s2; for (Enumeration enumeration = nsdictionary.keyEnumerator(); enumeration.hasMoreElements(); _context.takeValueForInferrableKey(nsdictionary.valueForKey(s2), s2)) { s2 = (String) enumeration.nextElement(); } } if (log.isDebugEnabled()) log.debug(hashCode() + ": context: " + _context); return _context; }
public EOQualifier qualifierForRelationshipWithKey(String aKey) { willRead(); if (aKey != null) { String anEntityName = entityName(); EOEntity anEntity = EOModelGroup.defaultGroup().entityNamed(anEntityName); EORelationship aRelationship = anEntity.relationshipNamed(aKey); if (aRelationship != null) { EOEditingContext anEditingContext = editingContext(); EOGlobalID aGlobalID = anEditingContext.globalIDForObject(this); String aModelName = anEntity.model().name(); EODatabaseContext aDatabaseContext = EOUtilities.databaseContextForModelNamed(anEditingContext, aModelName); aDatabaseContext.lock(); NSDictionary aRow = aDatabaseContext.snapshotForGlobalID(aGlobalID); aDatabaseContext.unlock(); EOQualifier aQualifier = aRelationship.qualifierWithSourceRow(aRow); return aQualifier; } } return null; }
private void createTables(boolean dropTables) { for (Enumeration e = EOModelGroup.defaultGroup().models().objectEnumerator(); e.hasMoreElements(); ) { final EOModel eomodel = (EOModel) e.nextElement(); EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, eomodel.name()); dbc.lock(); try { EOAdaptorChannel channel = dbc.availableChannel().adaptorChannel(); if (eomodel.adaptorName().contains("JDBC")) { EOSynchronizationFactory syncFactory = (EOSynchronizationFactory) channel.adaptorContext().adaptor().synchronizationFactory(); ERXSQLHelper helper = ERXSQLHelper.newSQLHelper(channel); NSDictionary options = helper.defaultOptionDictionary(true, dropTables); // Primary key support creation throws an unwanted exception // if // EO_PK_TABLE already // exists (e.g. in case of MySQL), so we add pk support in a // stand-alone step options = optionsWithPrimaryKeySupportDisabled(options); createPrimaryKeySupportForModel(eomodel, channel, syncFactory); String sqlScript = syncFactory.schemaCreationScriptForEntities(eomodel.entities(), options); log.info("Creating tables: {}", eomodel.name()); ERXJDBCUtilities.executeUpdateScript(channel, sqlScript, true); } } catch (SQLException ex) { log.error("Can't update", ex); } finally { dbc.unlock(); } } }
@Test public void loadOneModelInsideResourcesFolder() throws Exception { createEditingContext("AnotherTest"); EOModel result = EOModelGroup.defaultGroup().modelNamed("AnotherTest"); assertThat(result, notNullValue()); }
@Test public void removeModelsLoadedByTheTemporaryEditingContextAfterTestExecution() throws Throwable { AbstractEditingContextRule editingContext = createEditingContext(TEST_MODEL_NAME); editingContext.before(mockTarget); editingContext.after(mockTarget); assertThat(EOModelGroup.defaultGroup().modelNamed(TEST_MODEL_NAME), nullValue()); }
@SuppressWarnings({"unchecked"}) protected void ensureModelsLoaded() { if (_modelStats == null) { _modelStats = new NSMutableDictionary<String, SEModelStats>(); for (EOModel model : (NSArray<EOModel>) _modelGroup.models()) { SEModelStats modelStats = new SEModelStats(model); _modelStats.setObjectForKey(modelStats, model.name()); } } }
/** * This method encodes the entity name of the enterprise object by searching in the default model * group whether it can find the key EncodedEntityNameKey in the user info dictionary. * * @param eo the enterprise object * @return the encoded entity name defaulting to the given eo's entityName */ public static String entityNameEncode(EOEnterpriseObject eo) { // Get the EncodedEntityName of the object // Default to eo's entityName String encodedEntityName = eo.entityName(); EOEntity entity = EOModelGroup.defaultGroup().entityNamed(eo.entityName()); NSDictionary userInfo = entity.userInfo(); if (userInfo != null && userInfo.objectForKey(EncodedEntityNameKey) != null) encodedEntityName = (String) userInfo.objectForKey(EncodedEntityNameKey); return encodedEntityName; }
public WOComponent executeUpdate() { EOModel m = EOModelGroup.defaultGroup().models().objectAtIndex(0); con = ERXJDBCConnectionBroker.connectionBrokerForModel(m).getConnection(); try { Statement s = con.createStatement(); int r = s.executeUpdate(sql); response = "result: " + r; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { ERXJDBCConnectionBroker.connectionBrokerForModel(m).freeConnection(con); } return context().page(); }
public WOComponent executeQuery() { EOModel m = EOModelGroup.defaultGroup().models().objectAtIndex(0); con = ERXJDBCConnectionBroker.connectionBrokerForModel(m).getConnection(); try { con.setAutoCommit(false); Statement s = con.createStatement(); ResultSet rs = s.executeQuery(sql); con.commit(); StringBuffer buf = new StringBuffer(); // append header buf.append("<table border=\"1\"><tr>"); ResultSetMetaData rsmd = rs.getMetaData(); int colcount = rsmd.getColumnCount(); for (int i = 1; i <= colcount; i++) { buf.append("<td>"); buf.append(rsmd.getColumnName(i)); buf.append("</td>"); } buf.append("</tr>"); while (rs.next()) { buf.append("<tr>"); for (int i = 1; i <= colcount; i++) { buf.append("<td>"); Object o = rs.getObject(i); buf.append(o == null ? "" : o.toString()); buf.append("</td>"); } buf.append("</tr>"); } buf.append("</table>"); response = buf.toString(); } catch (SQLException e) { response = ERXUtilities.stackTrace(e); } finally { ERXJDBCConnectionBroker.connectionBrokerForModel(m).freeConnection(con); } return context().page(); }
// FIXME: (tuscland) Should we listen to model group notifications ? // If this method is called too early, we might not have all the entities in the model group, // but this case is rare. protected static final NSDictionary encodedEntityNames() { if (_encodedEntityNames == null) { synchronized (ERXEOEncodingUtilities.class) { if (_encodedEntityNames == null) { _encodedEntityNames = new NSMutableDictionary(); NSArray models = (NSArray) EOModelGroup.defaultGroup().models(); for (Enumeration en = models.objectEnumerator(); en.hasMoreElements(); ) { NSArray entities = ((EOModel) en.nextElement()).entities(); for (Enumeration entEn = entities.objectEnumerator(); entEn.hasMoreElements(); ) { EOEntity entity = (EOEntity) entEn.nextElement(); NSDictionary userInfo = entity.userInfo(); if (userInfo != null) { String encodedEntityName = (String) userInfo.objectForKey(EncodedEntityNameKey); if (encodedEntityName != null) _encodedEntityNames.setObjectForKey(entity.name(), encodedEntityName); } } } } } } return _encodedEntityNames; }