You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(11) |
Oct
(10) |
Nov
(3) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(44) |
Feb
(30) |
Mar
(11) |
Apr
(43) |
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(9) |
Oct
|
Nov
(1) |
Dec
(1) |
2008 |
Jan
(1) |
Feb
|
Mar
|
Apr
(17) |
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: <rfl...@us...> - 2007-02-24 10:21:14
|
Revision: 253 http://svn.sourceforge.net/salto-db/?rev=253&view=rev Author: rflament Date: 2007-02-24 02:21:11 -0800 (Sat, 24 Feb 2007) Log Message: ----------- Added Paths: ----------- salto-db-generator-eclipse/trunk/icons/stock-insert-view.png Added: salto-db-generator-eclipse/trunk/icons/stock-insert-view.png =================================================================== (Binary files differ) Property changes on: salto-db-generator-eclipse/trunk/icons/stock-insert-view.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-21 15:13:41
|
Revision: 252 http://svn.sourceforge.net/salto-db/?rev=252&view=rev Author: rflament Date: 2007-02-21 07:13:36 -0800 (Wed, 21 Feb 2007) Log Message: ----------- refresh project list when a new project is created or when an existing project is opened or removed Modified Paths: -------------- salto-db-generator-eclipse/trunk/plugin.xml salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/Activator.java salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/EclipseIdeInterface.java salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/SaltoDbPerspective.java salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/ApplyTemplateControl.java salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/GeneratorView.java salto-db-generator-eclipse/trunk/src/saltodb.properties salto-db-generator-eclipse/trunk/src/saltodb_fr.properties Modified: salto-db-generator-eclipse/trunk/plugin.xml =================================================================== --- salto-db-generator-eclipse/trunk/plugin.xml 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/plugin.xml 2007-02-21 15:13:36 UTC (rev 252) @@ -16,7 +16,7 @@ id="com.salto.db.generator.eclipse.view.GeneratorView"> </view> <view - name="Salto-db Apply Templates" + name="Salto-db Execute Plugin" icon="icons/stock_database.png" category="com.salto.db.generator.eclipse" class="com.salto.db.generator.eclipse.view.TableViewPart" @@ -44,11 +44,12 @@ </extension> <extension point="org.eclipse.ui.perspectives"> - <perspective - class="com.salto.db.generator.eclipse.SaltoDbPerspective" - icon="icons/stock_database.png" - id="com.salto.db.generator.eclipse.SaltoDbPerspective" - name="Salto-db"/> + <perspective + class="com.salto.db.generator.eclipse.SaltoDbPerspective" + fixed="false" + icon="icons/stock_database.png" + id="com.salto.db.generator.eclipse.SaltoDbPerspective" + name="Salto-db Generator"/> </extension> </plugin> Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/Activator.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/Activator.java 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/Activator.java 2007-02-21 15:13:36 UTC (rev 252) @@ -4,11 +4,14 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import com.salto.db.generator.eclipse.view.CoolChangeListener; + /** * The activator class controls the plug-in life cycle */ @@ -26,6 +29,8 @@ private static HashMap images = new HashMap(); + private static CoolChangeListener listener = new CoolChangeListener(); + /** * The constructor */ @@ -41,6 +46,7 @@ public void start(BundleContext context) throws Exception { super.start(context); resourceBundle = ResourceBundle.getBundle("saltodb"); + ResourcesPlugin.getWorkspace().addResourceChangeListener(listener); } /* @@ -51,6 +57,7 @@ public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); + ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener); } /** @@ -107,4 +114,8 @@ return resourceBundle; } + public static CoolChangeListener getListener() { + return listener; + } + } Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/EclipseIdeInterface.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/EclipseIdeInterface.java 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/EclipseIdeInterface.java 2007-02-21 15:13:36 UTC (rev 252) @@ -24,7 +24,8 @@ /** * retourne les dossiers contenant les sources java. * - * @param projName nom du projet + * @param projName + * nom du projet * @return liste des répertoires contenant les sources * @throws IdeException */ @@ -36,11 +37,12 @@ ArrayList list = new ArrayList(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { - IPath path = entries[i].getPath(); + IPath path = entries[i].getPath(); String[] str = path.segments(); String realPath = ""; for (int j = 1; j < str.length; j++) { - if (j != 1) realPath += "/"; + if (j != 1) + realPath += "/"; realPath += str[j]; } list.add(realPath); @@ -51,18 +53,19 @@ throw new IdeException(e); } } - + /* * @see IdeInterface#getPackage(String) */ public String[] getPackage(String projName) throws IdeException { + IProject projet = ResourcesPlugin.getWorkspace().getRoot().getProject(projName); IJavaProject javaProjet = JavaCore.create(projet); try { IPackageFragment[] fragments = javaProjet.getPackageFragments(); ArrayList list = new ArrayList(); for (int i = 0; i < fragments.length; i++) { - if (fragments[i].getKind() == IPackageFragmentRoot.K_SOURCE && ! list.contains(fragments[i].getElementName())) { + if (fragments[i].getKind() == IPackageFragmentRoot.K_SOURCE && !list.contains(fragments[i].getElementName())) { list.add(fragments[i].getElementName()); } } @@ -110,45 +113,34 @@ /* * @see IdeInterface#importSource(String, String, String) */ - public void importSource(String projet, String sourcePath,String pckName,String compName, String source) - throws IdeException { - /* FileOutputStream out = null; - try { - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projet); - File dir = new File(project.getLocation().toOSString()+"/" - + sourcePath+"/" - + pckName.replace('.','/')+"/"); - try {dir.mkdirs();} catch (Exception e) {} - out = new FileOutputStream(dir.getPath()+"/"+compName+".java"); - out.write(source.getBytes()); - out.close(); - - //importation de la classe dans le projet Eclipse - IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - IProject javaProject = myWorkspaceRoot.getProject(projet); - if (javaProject.exists() && !javaProject.isOpen()) - javaProject.open(null); - - //cr�ation des folders si n�cessaires - Path filePath = new Path(sourcePath + "/"+pckName.replace('.','/')); - IFolder javaFolder = null; - String relativePath = ""; - for (int i = 0; i< filePath.segments().length;i++) { - relativePath += '/' +filePath.segments()[i]; - javaFolder = javaProject.getFolder(new Path(relativePath)); - if (! javaFolder.exists()) { - javaFolder.create(true,true,null); - } - } - - // cr�ation du fichier java - IFile javaFile = javaFolder.getFile(compName+".java"); - javaFile.refreshLocal(1, null); - } - catch (Exception e) { - throw new IdeException(e); - }*/ + public void importSource(String projet, String sourcePath, String pckName, String compName, String source) throws IdeException { + /* + * FileOutputStream out = null; try { + * + * IProject project = + * ResourcesPlugin.getWorkspace().getRoot().getProject(projet); File dir = + * new File(project.getLocation().toOSString()+"/" + sourcePath+"/" + + * pckName.replace('.','/')+"/"); try {dir.mkdirs();} catch (Exception + * e) {} out = new FileOutputStream(dir.getPath()+"/"+compName+".java"); + * out.write(source.getBytes()); out.close(); + * + * //importation de la classe dans le projet Eclipse IWorkspaceRoot + * myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject + * javaProject = myWorkspaceRoot.getProject(projet); if + * (javaProject.exists() && !javaProject.isOpen()) + * javaProject.open(null); + * + * //cr�ation des folders si n�cessaires Path filePath = new + * Path(sourcePath + "/"+pckName.replace('.','/')); IFolder javaFolder = + * null; String relativePath = ""; for (int i = 0; i< + * filePath.segments().length;i++) { relativePath += '/' + * +filePath.segments()[i]; javaFolder = javaProject.getFolder(new + * Path(relativePath)); if (! javaFolder.exists()) { + * javaFolder.create(true,true,null); } } + * // cr�ation du fichier java IFile javaFile = + * javaFolder.getFile(compName+".java"); javaFile.refreshLocal(1, null); } + * catch (Exception e) { throw new IdeException(e); } + */ } /* Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/SaltoDbPerspective.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/SaltoDbPerspective.java 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/SaltoDbPerspective.java 2007-02-21 15:13:36 UTC (rev 252) @@ -1,12 +1,9 @@ package com.salto.db.generator.eclipse; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; -import com.salto.db.generator.eclipse.view.CoolChangeListener; - public class SaltoDbPerspective implements IPerspectiveFactory { public void createInitialLayout(IPageLayout layout) { @@ -24,8 +21,7 @@ folder = layout.createFolder("right", IPageLayout.RIGHT, (float) 0.75, editorArea); //$NON-NLS-1$ folder.addView("com.salto.db.generator.eclipse.view.TableViewPart"); - ResourcesPlugin.getWorkspace().addResourceChangeListener(new CoolChangeListener()); - System.out.println("added listeners"); + } } Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/ApplyTemplateControl.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/ApplyTemplateControl.java 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/ApplyTemplateControl.java 2007-02-21 15:13:36 UTC (rev 252) @@ -29,6 +29,7 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TabFolder; @@ -45,6 +46,7 @@ import salto.tool.sql.data.TableInfo; import com.salto.db.generator.Constants; +import com.salto.db.generator.eclipse.Activator; import com.salto.db.generator.eclipse.EclipseIdeInterface; import com.salto.db.generator.plugin.IGeneratorPlugin; import com.salto.db.generator.plugin.Plugins; @@ -80,6 +82,8 @@ public ApplyTemplateControl(Composite parent, int style) { super(parent, style); + Activator.getListener().setApplyTemplateControl(this); + GridLayout gridLayout = new GridLayout(); this.setLayout(gridLayout); gridLayout.numColumns = 2; @@ -121,6 +125,10 @@ public void modifyText(ModifyEvent e) { try { + if (projects.getText() == null || "".equals(projects.getText())) { + return; + } + String[] pcks = new EclipseIdeInterface().getPackage(projects.getText()); pck.setItems(pcks); @@ -134,6 +142,7 @@ if (srcs.length > 0) src.select(0); } catch (Exception ex) { + ex.printStackTrace(); } } }); @@ -167,7 +176,7 @@ gridData.horizontalSpan = 2; tabFolder.setLayoutData(gridData); - execute = addButton(this, Msg.getString("apply.templates"), 0, true); + execute = addButton(this, Msg.getString("apply.the.templates"), 0, true); gridData = new GridData(GridData.CENTER); gridData.horizontalSpan = 2; execute.setLayoutData(gridData); @@ -175,6 +184,27 @@ } + public void refreshProjects() { + + Display display = this.getDisplay(); + if (!display.isDisposed()) { + + display.asyncExec(new Runnable() { + + public void run() { + + String[] projets = new EclipseIdeInterface().getProjets(); + projects.removeAll(); + projects.setItems(projets); + projects.update(); + + } + + }); + } + + } + private void showMessage(String message) { MessageDialog.openInformation(tableViewer.getControl().getShell(), "Salto-DB Generator", message); } @@ -211,8 +241,7 @@ return; } } - new DataObjectCreate().creerDoSimple(GENERATOR, prefix.getText(), nameOffset, path, pck.getText(), jdoInfos, this.comboPlugins.getSelectedPlugin() - .getName()); + new DataObjectCreate().creerDoSimple(GENERATOR, prefix.getText(), nameOffset, path, pck.getText(), jdoInfos, this.comboPlugins.getSelectedPlugin().getName()); IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject javaProject = myWorkspaceRoot.getProject(projects.getText()); Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java 2007-02-21 15:13:36 UTC (rev 252) @@ -1,8 +1,9 @@ package com.salto.db.generator.eclipse.view; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IResourceDelta; /** * @author remi @@ -10,37 +11,42 @@ */ public class CoolChangeListener implements IResourceChangeListener { + private ApplyTemplateControl applyTemplateControl; + public void resourceChanged(IResourceChangeEvent event) { - /* - * if (event.getType() != IResourceChangeEvent.POST_CHANGE) return; - */ - System.out.println("Something changed !"); - System.out.println(event.getSource()); - System.out.println(event.getDelta().getFullPath()); - /*if (event.getSource() instanceof IWorkspace) { - IWorkspace workspace = (IWorkspace) event.getSource();*/ - System.out.println("Something changed (new project ?)!"); - switch (event.getType()) { - case IResourceChangeEvent.POST_CHANGE: - System.out.println("IResourceChangeEvent.POST_CHANGE"); + if (event.getType() != IResourceChangeEvent.POST_CHANGE) + return; + + process(event.getDelta().getAffectedChildren()); + + } + + private void process(IResourceDelta[] deltas) { + + for (int i = 0; i < deltas.length; i++) { + IResourceDelta delta = deltas[i]; + + switch (delta.getResource().getType()) { + case IResource.PROJECT: + if (applyTemplateControl != null) { + applyTemplateControl.refreshProjects(); + } break; - case IResourceChangeEvent.POST_BUILD: - System.out.println("IResourceChangeEvent.POST_BUILD"); - break; - case IResourceChangeEvent.PRE_DELETE: - System.out.println("IResourceChangeEvent.PRE_DELETE"); - break; - case IResourceChangeEvent.PRE_CLOSE: - System.out.println("IResourceChangeEvent.PRE_CLOSE"); - break; - case IResourceChangeEvent.PRE_BUILD: - System.out.println("IResourceChangeEvent.PRE_BUILD"); - break; + default: break; } - //} + + } } + public ApplyTemplateControl getApplyTemplateControl() { + return applyTemplateControl; + } + + public void setApplyTemplateControl(ApplyTemplateControl applyTemplateControl) { + this.applyTemplateControl = applyTemplateControl; + } + } Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/GeneratorView.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/GeneratorView.java 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/GeneratorView.java 2007-02-21 15:13:36 UTC (rev 252) @@ -1,5 +1,6 @@ package com.salto.db.generator.eclipse.view; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -79,7 +80,7 @@ public static int SCHEMA = 2; public static int TABLE = 3; - + public static int VIEW = 4; class TreeObject implements IAdaptable { @@ -223,27 +224,30 @@ IPath path = Activator.getDefault().getStateLocation(); String filename = path.append("saltodb.txt").toOSString(); - IDialogSettings settings = new DialogSettings("Salto-DB"); - settings.load(filename); - // settings. + IDialogSettings settings = new DialogSettings("Salto-DB Generator"); - settings = settings.getSection("Connections"); + if (new File(filename).exists()) { + settings.load(filename); + // settings. - IDialogSettings[] s = settings.getSections(); + settings = settings.getSection("Connections"); - if (s != null) { - // viewer.setExpandedState(root, true); + IDialogSettings[] s = settings.getSections(); - for (int i = 0; i < s.length; i++) { - ConnectionInfo connectionInfo = new ConnectionInfo(s[i].get("driver"), s[i].get("url"), s[i].get("user"), s[i].get("pwd"), s[i].get("name"), s[i].get("driverJarFile")); - TreeParent connection = new TreeParent(connectionInfo.getName()); - connection.setParent(root); - connection.setType(DISCONNECTED_CONNECTION); - root.addChild(connection); - // viewer.setExpandedState(connection, true); - initConnectionInfo.put(connectionInfo.getName(), connectionInfo); + if (s != null) { + // viewer.setExpandedState(root, true); + + for (int i = 0; i < s.length; i++) { + ConnectionInfo connectionInfo = new ConnectionInfo(s[i].get("driver"), s[i].get("url"), s[i].get("user"), s[i].get("pwd"), s[i].get("name"), s[i].get("driverJarFile")); + TreeParent connection = new TreeParent(connectionInfo.getName()); + connection.setParent(root); + connection.setType(DISCONNECTED_CONNECTION); + root.addChild(connection); + // viewer.setExpandedState(connection, true); + initConnectionInfo.put(connectionInfo.getName(), connectionInfo); + } + } - } } catch (Throwable t) { t.printStackTrace(); @@ -284,7 +288,7 @@ if (object.getType() == TABLE) { return Activator.getImage("stock-insert-table.png"); } - + if (object.getType() == VIEW) { return Activator.getImage("stock-insert-view.png"); } @@ -410,7 +414,7 @@ disconnectAction.setImageDescriptor(Activator.getImageDescriptor("stock-disconnect.png")); //$NON-NLS-1$ applyTemplateAction = new ApplyTemplateAction(); - applyTemplateAction.setText(Msg.getString("apply.templates")); //$NON-NLS-1$ + applyTemplateAction.setText(Msg.getString("apply.a.templates")); //$NON-NLS-1$ applyTemplateAction.setImageDescriptor(Activator.getImageDescriptor("stock-apply.png")); //$NON-NLS-1$ } Modified: salto-db-generator-eclipse/trunk/src/saltodb.properties =================================================================== --- salto-db-generator-eclipse/trunk/src/saltodb.properties 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/src/saltodb.properties 2007-02-21 15:13:36 UTC (rev 252) @@ -7,7 +7,8 @@ drop.url=Remove connect=Connect disconnect=Disconnect -apply.templates=Apply Templates +apply.a.templates=Execute plugin +apply.the.templates=Execute plugin default.schema=Default Schema templates=Templates @@ -23,9 +24,9 @@ connect.user=Database User connect.pwd=Database Password -title.applytemplates=Apply Templates on Table {0} +title.applytemplates=Execute plugin on Table {0} title.addconnection=Add a JDBC connection -success.applytemplates=Templates have successfully been applied ! +success.applytemplates=Plugin has successfully been executed ! column.type=Type column.name=Name Modified: salto-db-generator-eclipse/trunk/src/saltodb_fr.properties =================================================================== --- salto-db-generator-eclipse/trunk/src/saltodb_fr.properties 2007-02-20 10:06:27 UTC (rev 251) +++ salto-db-generator-eclipse/trunk/src/saltodb_fr.properties 2007-02-21 15:13:36 UTC (rev 252) @@ -7,7 +7,8 @@ drop.url=Supprimer connect=Connexion disconnect=D\xE9connexion -apply.templates=Appliquer les templates +apply.a.templates=Ex\xE9cuter un plugin +apply.the.templates=Ex\xE9cuter le plugin default.schema=Default Schema templates=Templates @@ -23,9 +24,9 @@ connect.user=Utilisateur base de donn\xE9es connect.pwd=Mot de passe base de donn\xE9es -title.applytemplates=Appliquer les templates sur la table {0} +title.applytemplates=Ex\xE9cuter un plugin sur la table {0} title.addconnection=Ajout d'une connexion JDBC -success.applytemplates=Les templates ont \xE9t\xE9 appliqu\xE9es avec succ\xE8s ! +success.applytemplates=Le plugin a \xE9t\xE9 ex\xE9cut\xE9 avec succ\xE8s ! column.type=Type column.name=Nom This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-20 10:06:30
|
Revision: 251 http://svn.sourceforge.net/salto-db/?rev=251&view=rev Author: rflament Date: 2007-02-20 02:06:27 -0800 (Tue, 20 Feb 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java 2007-02-16 21:56:26 UTC (rev 250) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java 2007-02-20 10:06:27 UTC (rev 251) @@ -2,6 +2,7 @@ import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IWorkspace; /** * @author remi @@ -11,11 +12,35 @@ public void resourceChanged(IResourceChangeEvent event) { - /*if (event.getType() != IResourceChangeEvent.POST_CHANGE) - return;*/ + /* + * if (event.getType() != IResourceChangeEvent.POST_CHANGE) return; + */ System.out.println("Something changed !"); System.out.println(event.getSource()); System.out.println(event.getDelta().getFullPath()); + /*if (event.getSource() instanceof IWorkspace) { + IWorkspace workspace = (IWorkspace) event.getSource();*/ + System.out.println("Something changed (new project ?)!"); + switch (event.getType()) { + case IResourceChangeEvent.POST_CHANGE: + System.out.println("IResourceChangeEvent.POST_CHANGE"); + break; + case IResourceChangeEvent.POST_BUILD: + System.out.println("IResourceChangeEvent.POST_BUILD"); + break; + case IResourceChangeEvent.PRE_DELETE: + System.out.println("IResourceChangeEvent.PRE_DELETE"); + break; + case IResourceChangeEvent.PRE_CLOSE: + System.out.println("IResourceChangeEvent.PRE_CLOSE"); + break; + case IResourceChangeEvent.PRE_BUILD: + System.out.println("IResourceChangeEvent.PRE_BUILD"); + break; + default: + break; + } + //} } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-16 21:56:29
|
Revision: 250 http://svn.sourceforge.net/salto-db/?rev=250&view=rev Author: rflament Date: 2007-02-16 13:56:26 -0800 (Fri, 16 Feb 2007) Log Message: ----------- Property Changed: ---------------- salto-db-generator-eclipse/trunk/lib/salto-db-generator.jar Property changes on: salto-db-generator-eclipse/trunk/lib/salto-db-generator.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-16 21:55:31
|
Revision: 249 http://svn.sourceforge.net/salto-db/?rev=249&view=rev Author: rflament Date: 2007-02-16 13:55:27 -0800 (Fri, 16 Feb 2007) Log Message: ----------- Added Paths: ----------- salto-db-generator-eclipse/trunk/lib/salto-db-generator.jar Removed Paths: ------------- salto-db-generator-eclipse/trunk/lib/salto-db-generator.jar Deleted: salto-db-generator-eclipse/trunk/lib/salto-db-generator.jar =================================================================== (Binary files differ) Added: salto-db-generator-eclipse/trunk/lib/salto-db-generator.jar =================================================================== --- salto-db-generator-eclipse/trunk/lib/salto-db-generator.jar (rev 0) +++ salto-db-generator-eclipse/trunk/lib/salto-db-generator.jar 2007-02-16 21:55:27 UTC (rev 249) @@ -0,0 +1,873 @@ +PK + |
From: <rfl...@us...> - 2007-02-16 21:53:00
|
Revision: 248 http://svn.sourceforge.net/salto-db/?rev=248&view=rev Author: rflament Date: 2007-02-16 13:52:58 -0800 (Fri, 16 Feb 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/SaltoDbPerspective.java salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/ApplyTemplateControl.java salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/GeneratorView.java salto-db-generator-eclipse/trunk/src/saltodb.properties salto-db-generator-eclipse/trunk/src/saltodb_fr.properties Added Paths: ----------- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/SaltoDbPerspective.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/SaltoDbPerspective.java 2007-02-15 16:13:47 UTC (rev 247) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/SaltoDbPerspective.java 2007-02-16 21:52:58 UTC (rev 248) @@ -1,9 +1,12 @@ package com.salto.db.generator.eclipse; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; +import com.salto.db.generator.eclipse.view.CoolChangeListener; + public class SaltoDbPerspective implements IPerspectiveFactory { public void createInitialLayout(IPageLayout layout) { @@ -21,7 +24,8 @@ folder = layout.createFolder("right", IPageLayout.RIGHT, (float) 0.75, editorArea); //$NON-NLS-1$ folder.addView("com.salto.db.generator.eclipse.view.TableViewPart"); - + ResourcesPlugin.getWorkspace().addResourceChangeListener(new CoolChangeListener()); + System.out.println("added listeners"); } } Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/ApplyTemplateControl.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/ApplyTemplateControl.java 2007-02-15 16:13:47 UTC (rev 247) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/ApplyTemplateControl.java 2007-02-16 21:52:58 UTC (rev 248) @@ -63,6 +63,8 @@ private Text prefix; + private Text nameOffsetText; + private Text longDescription; private TableViewer tableViewer; @@ -154,6 +156,12 @@ gridData = new GridData(GridData.FILL_HORIZONTAL); prefix.setLayoutData(gridData); + label = new Label(this, SWT.NONE); + label.setText(Msg.getString("nameOffset")); + nameOffsetText = new Text(this, SWT.BORDER); + gridData = new GridData(GridData.FILL_HORIZONTAL); + nameOffsetText.setLayoutData(gridData); + tabFolder = new TabFolder(this, SWT.NONE); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.horizontalSpan = 2; @@ -193,8 +201,19 @@ } } - new DataObjectCreate().creerDoSimple(GENERATOR, prefix.getText(), path, pck.getText(), jdoInfos, this.comboPlugins.getSelectedPlugin().getName()); + int nameOffset = 0; + if (this.nameOffsetText.getText() != null && !"".equals(this.nameOffsetText.getText())) { + try { + nameOffset = Integer.parseInt(this.nameOffsetText.getText()); + } catch (NumberFormatException e) { + showMessage(Msg.getString("error.nameOffset.format", new String[] { this.nameOffsetText.getText() })); + return; + } + } + new DataObjectCreate().creerDoSimple(GENERATOR, prefix.getText(), nameOffset, path, pck.getText(), jdoInfos, this.comboPlugins.getSelectedPlugin() + .getName()); + IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject javaProject = myWorkspaceRoot.getProject(projects.getText()); if (javaProject.exists() && !javaProject.isOpen()) Added: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java (rev 0) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/CoolChangeListener.java 2007-02-16 21:52:58 UTC (rev 248) @@ -0,0 +1,21 @@ +package com.salto.db.generator.eclipse.view; + +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; + +/** + * @author remi + * + */ +public class CoolChangeListener implements IResourceChangeListener { + + public void resourceChanged(IResourceChangeEvent event) { + + /*if (event.getType() != IResourceChangeEvent.POST_CHANGE) + return;*/ + System.out.println("Something changed !"); + System.out.println(event.getSource()); + System.out.println(event.getDelta().getFullPath()); + } + +} Modified: salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/GeneratorView.java =================================================================== --- salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/GeneratorView.java 2007-02-15 16:13:47 UTC (rev 247) +++ salto-db-generator-eclipse/trunk/src/com/salto/db/generator/eclipse/view/GeneratorView.java 2007-02-16 21:52:58 UTC (rev 248) @@ -79,6 +79,8 @@ public static int SCHEMA = 2; public static int TABLE = 3; + + public static int VIEW = 4; class TreeObject implements IAdaptable { private String name; @@ -282,6 +284,10 @@ if (object.getType() == TABLE) { return Activator.getImage("stock-insert-table.png"); } + + if (object.getType() == VIEW) { + return Activator.getImage("stock-insert-view.png"); + } if (object.getType() == DISCONNECTED_CONNECTION) { return Activator.getImage("stock-disconnect.png"); @@ -502,7 +508,7 @@ for (int i = 0; i < paths.length; i++) { TreeObject object = (TreeObject) paths[i].getLastSegment(); - if (object.getType() == TABLE) { + if (object.getType() == TABLE || object.getType() == VIEW) { list.add(object.getData()); } @@ -621,7 +627,10 @@ item.setParent(schemaItem); item.setData(tableInfo[i]); schemaItem.addChild(item); - item.setType(TABLE); + if (tableInfo[i].getTableType().equals("VIEW")) + item.setType(VIEW); + else + item.setType(TABLE); viewer.setExpandedState(item, true); } Modified: salto-db-generator-eclipse/trunk/src/saltodb.properties =================================================================== --- salto-db-generator-eclipse/trunk/src/saltodb.properties 2007-02-15 16:13:47 UTC (rev 247) +++ salto-db-generator-eclipse/trunk/src/saltodb.properties 2007-02-16 21:52:58 UTC (rev 248) @@ -36,4 +36,6 @@ plugin=Plugin plugin.description=Plugin Description -prefix=Classes prefix \ No newline at end of file +prefix=Classes prefix +nameOffset=Table name offset +error.nameOffset.format={0} cannot be converted to a number ! \ No newline at end of file Modified: salto-db-generator-eclipse/trunk/src/saltodb_fr.properties =================================================================== --- salto-db-generator-eclipse/trunk/src/saltodb_fr.properties 2007-02-15 16:13:47 UTC (rev 247) +++ salto-db-generator-eclipse/trunk/src/saltodb_fr.properties 2007-02-16 21:52:58 UTC (rev 248) @@ -37,4 +37,6 @@ plugin=Plugin plugin.description=Description du plugin -prefix=Prefixe des classes \ No newline at end of file +prefix=Prefixe des classes +nameOffset=Offset du nom des tables +error.nameOffset.format={0} n'est pas un nombre valide ! \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-15 16:14:42
|
Revision: 247 http://svn.sourceforge.net/salto-db/?rev=247&view=rev Author: rflament Date: 2007-02-15 08:13:47 -0800 (Thu, 15 Feb 2007) Log Message: ----------- doc Modified Paths: -------------- salto-db-generator/trunk/src/com/salto/db/generator/plugin/EJB3AndHibernateDAOPlugin.java salto-db-generator/trunk/src/com/salto/db/generator/plugin/HibernatePlugin.java salto-db-generator/trunk/src/com/salto/db/generator/plugin/PojoHibernateDAOPlugin.java salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt salto-db-generator/trunk/src/site/apt/plugins/pojohibernatedao.apt salto-db-generator/trunk/src/site/apt/roadmap.apt Added Paths: ----------- salto-db-generator/trunk/src/site/resources/images/screenshot2.png Modified: salto-db-generator/trunk/src/com/salto/db/generator/plugin/EJB3AndHibernateDAOPlugin.java =================================================================== --- salto-db-generator/trunk/src/com/salto/db/generator/plugin/EJB3AndHibernateDAOPlugin.java 2007-02-15 14:34:31 UTC (rev 246) +++ salto-db-generator/trunk/src/com/salto/db/generator/plugin/EJB3AndHibernateDAOPlugin.java 2007-02-15 16:13:47 UTC (rev 247) @@ -77,7 +77,7 @@ context.put("date", new Date()); context.put("dialect", this.ejb3Plugin); context.put("pckName", pckName); - context.put("annotations", String.valueOf(true)); + context.put("annotations", String.valueOf(ejb3Plugin.isGenerateAnnotations())); runVelocity(TEMPLATE_PATH, "hibernatedaofactory.vm", srcPath + "/" + (pckName + ".hibernate").replace('.', '/') + "/", Modified: salto-db-generator/trunk/src/com/salto/db/generator/plugin/HibernatePlugin.java =================================================================== --- salto-db-generator/trunk/src/com/salto/db/generator/plugin/HibernatePlugin.java 2007-02-15 14:34:31 UTC (rev 246) +++ salto-db-generator/trunk/src/com/salto/db/generator/plugin/HibernatePlugin.java 2007-02-15 16:13:47 UTC (rev 247) @@ -51,8 +51,8 @@ return ""; } - public void init(String generator, String doPrefix, String srcPath, - String pckName) throws Exception { + public void init(String generator, String doPrefix, int defaultNameOffset, + String srcPath, String pckName) throws Exception { super.init(generator, doPrefix, defaultNameOffset, srcPath, pckName); this.setGenerateAnnotations(false); } Modified: salto-db-generator/trunk/src/com/salto/db/generator/plugin/PojoHibernateDAOPlugin.java =================================================================== --- salto-db-generator/trunk/src/com/salto/db/generator/plugin/PojoHibernateDAOPlugin.java 2007-02-15 14:34:31 UTC (rev 246) +++ salto-db-generator/trunk/src/com/salto/db/generator/plugin/PojoHibernateDAOPlugin.java 2007-02-15 16:13:47 UTC (rev 247) @@ -21,11 +21,11 @@ return "Pojos + Hibernate mapping + Generic DAO"; } - public void init(String generator, String doPrefix, String srcPath, - String pckName) throws Exception { + public void init(String generator, String doPrefix, int defaultNameOffset, + String srcPath, String pckName) throws Exception { super.init(generator, doPrefix, defaultNameOffset, srcPath, pckName); HibernatePlugin hibernatePlugin = new HibernatePlugin(); - hibernatePlugin.init(generator, doPrefix, srcPath, pckName + ".pojo"); + hibernatePlugin.init(generator, doPrefix, defaultNameOffset, srcPath, pckName + ".pojo"); this.setEjb3Plugin(hibernatePlugin); } } Modified: salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt 2007-02-15 14:34:31 UTC (rev 246) +++ salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt 2007-02-15 16:13:47 UTC (rev 247) @@ -5,7 +5,7 @@ EJB3 And Hibernate DAOs plugin This plugin generates EJB3 entities (like the EJB3 plugin), a abstract persistence layer and an hibernate - annotation implementation. + annotation implementation of this layer. The generated code is actually a implementation of the pattern of described at {{http://www.hibernate.org/328.html}}. This pattern suits well with the open-session in view pattern (i.e. web applications). @@ -14,7 +14,7 @@ In each dao there is a getById() method, a save() method, an update() method, a delete() method and a finder for each different column. - If you want something equivalebt but without ejb3 annotations, have a look at the {{{pojohibernatedao.html}"Pojos and Hibernate DAOs" plugin}}. + If you want something equivalent but without ejb3 annotations, have a look at the {{{pojohibernatedao.html}"Pojos and Hibernate DAOs" plugin}}. * Example Modified: salto-db-generator/trunk/src/site/apt/plugins/pojohibernatedao.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/pojohibernatedao.apt 2007-02-15 14:34:31 UTC (rev 246) +++ salto-db-generator/trunk/src/site/apt/plugins/pojohibernatedao.apt 2007-02-15 16:13:47 UTC (rev 247) @@ -2,4 +2,1071 @@ Pojos and Hibernate DAOs plugin --- -Pojos and Hibernate DAOs plugin \ No newline at end of file +Pojos and Hibernate DAOs plugin + + This plugin generates pojos (like the Hibernate plugin), a abstract persistence layer and an hibernate implementation of this layer. + + The generated code is actually a implementation of the pattern of described at {{http://www.hibernate.org/328.html}}. This pattern + suits well with the open-session in view pattern (i.e. web applications). + + For each table the plugin generates the pojo, an abstract DAO class and a concrete hibernate dao. + + In each dao there is a getById() method, a save() method, an update() method, a delete() method and a finder for each different column. + + It generates hibernate mappping files as well (hbm files). + + If you want something equivalent but with ejb3 annotations, have a look at the {{{ejb3hibernatedao.html}"EJB3 And Hibernate DAOs" plugin}}. + + +* Example + + Suppose we have two tables in a database : + + * Table CITY + + * Table PERSON + + [] + + Here is the corresponding MySQL DDL : + ++---------------------------------------------------+ +CREATE TABLE city ( + id_city int(11) NOT NULL auto_increment, + name varchar(50) NOT NULL, + PRIMARY KEY (id_city) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE person ( + id_person int(11) NOT NULL auto_increment, + name varchar(50) NOT NULL, + first_name varchar(50) NOT NULL, + age int(11) NOT NULL, + id_city int(11) NOT NULL, + PRIMARY KEY (id_person), + KEY fk_person_city (id_city), + CONSTRAINT fk_person_city FOREIGN KEY (id_city) REFERENCES city (id_city) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; ++---------------------------------------------------+ + + A person lives in a city, and for each city there are many persons living in it. So we have a many-to-one relationship. + + Once everything is generated, you can write one line of code to retrieve every persons in the database to print their name and the name + of the city they live in : + ++--------------------------------------------------------------+ +List<Person> persons = DAOFactory.DEFAULT.buildPersonDAO().findAll(); +for (Person person : persons) + { + System.out.println(person.getFirstName()+" "+person.getName()+" lives in "+person.getCity().getName()); + } + ++--------------------------------------------------------------+ + + Here are the different generated files : + +[../images/screenshot2.png] + +** Interfaces + + * com.salto.pojodao.CityDAO : an interface for city daos + ++--------------------------------------------------------+ +package com.salto.pojodao; + +import java.util.Map; +import java.util.List; +import java.sql.Timestamp; + +import com.salto.pojodao.pojo.City; +/** + * <p>Hibernate DAO layer for Citys</p> + * <p>Generated at Thu Feb 15 16:29:39 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ +public interface CityDAO extends GenericDAO<City,Integer> { + + /* + * TODO : Add specific businesses daos here. + * These methods will be overwrited if you re-generate this interface. + * You might want to extend this interface and to change the dao factory to return + * an instance of the new implemenation in buildCityDAO() + */ + + /** + * Find City by criteria. + * If a parameter is null it is not used in the query. + */ + public List<City> findByCriteria(String name); + + /** + * Find City by criteria. + */ + public List<City> findByCriteria(Map criterias); + + + /** + * Find City by name + */ + public List<City> findByName(String name); + +} ++--------------------------------------------------------+ + + * com.salto.pojodao.DAOFactory : a factory for daos. When you develop you use this class to build daos instance, this way you don't have any references to an implementation in your methods and it makes it easy to change of implementation. + ++----------------------------------------------------------+ +package com.salto.pojodao; + +import com.salto.pojodao.hibernate.HibernateDAOFactory; + +/** + * Generated at Thu Feb 15 16:29:39 CET 2007 + * + * @see http://www.hibernate.org/328.html + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ + +public abstract class DAOFactory { + + private static final DAOFactory HIBERNATE = new HibernateDAOFactory(); + + public static final DAOFactory DEFAULT = HIBERNATE; + + public abstract CityDAO buildCityDAO(); + + public abstract PersonDAO buildPersonDAO(); + +} ++----------------------------------------------------------+ + + * com.salto.pojodao.GenericDAO : an interface describing a generic dao. Other daos extend it. + ++----------------------------------------------------------+ +package com.salto.pojodao; + +import java.io.Serializable; +import java.util.List; + +/** + * Generated at Thu Feb 15 16:29:39 CET 2007 + * + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ +public interface GenericDAO<T, ID extends Serializable> { + + T getById(ID id, boolean lock); + + T getById(ID id); + + List<T> findAll(); + + void save(T entity); + + void update(T entity); + + void saveOrUpdate(T entity); + + void delete(T entity); + + void delete(T entity, Boolean doItNow); + + int deleteById(ID id); + +} ++----------------------------------------------------------+ + + * com.salto.pojodao.PersonDAO : an interface for person daos + ++----------------------------------------------------------+ +package com.salto.pojodao; + +import java.util.Map; +import java.util.List; +import java.sql.Timestamp; + +import com.salto.pojodao.pojo.Person; +/** + * <p>Hibernate DAO layer for Persons</p> + * <p>Generated at Thu Feb 15 16:29:39 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ +public interface PersonDAO extends GenericDAO<Person,Integer> { + + /* + * TODO : Add specific businesses daos here. + * These methods will be overwrited if you re-generate this interface. + * You might want to extend this interface and to change the dao factory to return + * an instance of the new implemenation in buildPersonDAO() + */ + + /** + * Find Person by criteria. + * If a parameter is null it is not used in the query. + */ + public List<Person> findByCriteria(String name, String firstName, Integer age, Integer idCity); + + /** + * Find Person by criteria. + */ + public List<Person> findByCriteria(Map criterias); + + + /** + * Find Person by name + */ + public List<Person> findByName(String name); + + /** + * Find Person by firstName + */ + public List<Person> findByFirstName(String firstName); + + /** + * Find Person by age + */ + public List<Person> findByAge(Integer age); + + /** + * Find Person by idCity + */ + public List<Person> findByIdCity(Integer idCity); + +} ++----------------------------------------------------------+ + +** Hibernate implementation + + * com.salto.pojodao.hibernate.AbstractHibernateDAO : an abstract hibernate implementation of GenericDAO + ++----------------------------------------------------------+ +package com.salto.pojodao.hibernate; + +import com.salto.pojodao.GenericDAO; +import java.io.Serializable; + +import org.hibernate.FlushMode; +import org.hibernate.Query; +import org.hibernate.LockMode; +import org.hibernate.Session; + +/** + * Generated at Thu Feb 15 16:29:39 CET 2007 + * + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ +public abstract class AbstractHibernateDAO<T, ID extends Serializable> implements GenericDAO<T, ID> { + + private Session session; + + public AbstractHibernateDAO(Session s) { + session = s; + } + + public Session getSession() { + return session; + } + + public void setSession(Session session) { + this.session = session; + } + + public void save(T entity) { + getSession().save(entity); + } + + public void update(T entity) { + getSession().update(entity); + } + + public void saveOrUpdate(T entity) { + getSession().saveOrUpdate(entity); + } + + public void delete(T entity) { + getSession().delete(entity); + } + + public void delete(T entity, Boolean doItNow) { + if (doItNow) { + getSession().setFlushMode(FlushMode.ALWAYS); + } + delete(entity); + } + + /** + * This method will execute an HQL query and return the number of affected entities. + */ + protected int executeQuery(String query, String namedParams[], Object params[]) { + Query q = getSession().createQuery(query); + + if (namedParams != null) { + for (int i = 0; i < namedParams.length; i++) { + q.setParameter(namedParams[i], params[i]); + } + } + + return q.executeUpdate(); + } + + protected int executeQuery(String query) { + return executeQuery(query, null, null); + } + + /** + * This method will execute a Named HQL query and return the number of affected entities. + */ + protected int executeNamedQuery(String namedQuery, String namedParams[], Object params[]) { + Query q = getSession().getNamedQuery(namedQuery); + + if (namedParams != null) { + for (int i = 0; i < namedParams.length; i++) { + q.setParameter(namedParams[i], params[i]); + } + } + + return q.executeUpdate(); + } + + protected int executeNamedQuery(String namedQuery) { + return executeNamedQuery(namedQuery, null, null); + } + +} ++----------------------------------------------------------+ + + * com.salto.pojodao.hibernate.CityHibernateDAO : the Hibernate implementation of CityDAO + ++----------------------------------------------------------+ +package com.salto.pojodao.hibernate; + +import java.util.Map; +import java.util.List; +import java.sql.Timestamp; + +import com.salto.pojodao.pojo.City; +import com.salto.pojodao.CityDAO; + +import org.hibernate.Criteria; +import org.hibernate.LockMode; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; + +/** + * <p>Hibernate DAO layer for Citys</p> + * <p>Generated at Thu Feb 15 16:29:39 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ +public class CityHibernateDAO extends + AbstractHibernateDAO<City, Integer> implements + CityDAO { + + public CityHibernateDAO(Session s) { + super(s); + } + + public City getById(Integer id) { + return (City) getSession().get(City.class, id); + } + + public City getById(Integer id, boolean lock) { + if (lock) { + return (City) getSession().get(City.class, id, + LockMode.UPGRADE); + } else + return getById(id); + } + + /** + * Find City by criteria. + * If a parameter is null it is not used in the query. + * //FIXME: there's certainly an issue with foreign keys... + */ + @SuppressWarnings("unchecked") + public List<City> findByCriteria(String name) { + + Criteria criteria = getSession().createCriteria(City.class); + + if (name != null) { + criteria.add(Restrictions.eq("name", name)); + } + + return criteria.list(); + } + + /** + * Find City by criteria. + */ + @SuppressWarnings("unchecked") + public List<City> findByCriteria(Map criterias) { + + Criteria criteria = getSession().createCriteria(City.class); + criteria.add(Restrictions.allEq(criterias)); + return criteria.list(); + } + + public int deleteById(Integer id) { + Query q = getSession().createQuery("delete from City where id = :id"); + q.setParameter("id",id); + return q.executeUpdate(); + } + + @SuppressWarnings("unchecked") + public List<City> findAll() { + Query q = getSession().createQuery("from City"); + q.setCacheable(true); + return q.list(); + } + + /** + * Find City by name + */ + @SuppressWarnings("unchecked") + public List<City> findByName(String name) { + Query q = getSession().createQuery("from City where name = :name"); + q.setParameter("name",name); + q.setCacheable(true); + return q.list(); + } + + +} ++----------------------------------------------------------+ + + * com.salto.pojodao.hibernate.HibernateDAOFactory : the Hibernate implementation of DAOFactory + ++----------------------------------------------------------+ +package com.salto.pojodao.hibernate; + +import com.salto.pojodao.DAOFactory; +import com.salto.pojodao.CityDAO; +import com.salto.pojodao.PersonDAO; + +/** + * Generated at Thu Feb 15 16:29:39 CET 2007 + * + * @see http://www.hibernate.org/43.html + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ +public class HibernateDAOFactory extends DAOFactory { + + /* (non-Javadoc) + * @see com.salto.pojodao.DAOFactory#buildCityDAO() + */ + @Override + public CityDAO buildCityDAO() { + return new CityHibernateDAO(HibernateUtil.getSession()); + } + + /* (non-Javadoc) + * @see com.salto.pojodao.DAOFactory#buildPersonDAO() + */ + @Override + public PersonDAO buildPersonDAO() { + return new PersonHibernateDAO(HibernateUtil.getSession()); + } + +} ++----------------------------------------------------------+ + + * com.salto.pojodao.hibernate.HibernateUtil : utility methods for Hibernate + ++----------------------------------------------------------+ +package com.salto.pojodao.hibernate; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.cfg.Configuration; + +/** + * Generated at Thu Feb 15 16:29:39 CET 2007 + * + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ +public final class HibernateUtil { + + private static SessionFactory sessionFactory; + + private static final ThreadLocal threadSession = new ThreadLocal(); + + private static final ThreadLocal threadTransaction = new ThreadLocal(); + + static { + try { + sessionFactory = new Configuration().configure().buildSessionFactory(); + } catch (Throwable ex) { + + throw new ExceptionInInitializerError(ex); + } + } + + private HibernateUtil() { + + } + + /** + * Returns the SessionFactory used for this static class. + * + * @return SessionFactory + */ + public static SessionFactory getSessionFactory() { + return sessionFactory; + } + + /** + * Retrieves the current Session local to the thread. <p/> If no Session is + * open, opens a new Session for the running thread. + * + * @return Session + */ + @SuppressWarnings("unchecked") + public static Session getSession() { + Session s = (Session) threadSession.get(); + + if (s == null) { + + s = getSessionFactory().openSession(); + + threadSession.set(s); + beginTransaction(); + } + + return s; + } + + /** + * Closes the Session local to the thread. + */ + @SuppressWarnings("unchecked") + public static void closeSession() { + + Session s = (Session) threadSession.get(); + threadSession.set(null); + if (s != null && s.isOpen()) { + + s.close(); + } + + } + + /** + * Start a new database transaction. + */ + @SuppressWarnings("unchecked") + public static void beginTransaction() { + Transaction tx = (Transaction) threadTransaction.get(); + + if (tx == null) { + + tx = getSession().beginTransaction(); + threadTransaction.set(tx); + } + + } + + /** + * Commit the database transaction. + */ + @SuppressWarnings("unchecked") + public static void commitTransaction() { + Transaction tx = (Transaction) threadTransaction.get(); + + if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) { + + tx.commit(); + } + threadTransaction.set(null); + + } + + /** + * Rollback the database transaction. + */ + @SuppressWarnings("unchecked") + public static void rollbackTransaction() { + Transaction tx = (Transaction) threadTransaction.get(); + try { + threadTransaction.set(null); + if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) { + + tx.rollback(); + } + + } finally { + closeSession(); + } + } + +} ++----------------------------------------------------------+ + + * com.salto.pojodao.hibernate.PersonHibernateDAO : the Hibernate implementation of PersonDAO + ++----------------------------------------------------------+ +package com.salto.pojodao.hibernate; + +import java.util.List; +import java.util.Map; + +import org.hibernate.Criteria; +import org.hibernate.LockMode; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; + +import com.salto.pojodao.PersonDAO; +import com.salto.pojodao.pojo.Person; + +/** + * <p>Hibernate DAO layer for Persons</p> + * <p>Generated at Thu Feb 15 16:29:39 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / Pojos + Hibernate mapping + Generic DAO + */ +public class PersonHibernateDAO extends + AbstractHibernateDAO<Person, Integer> implements + PersonDAO { + + public PersonHibernateDAO(Session s) { + super(s); + } + + + public Person getById(Integer id) { + return (Person) getSession().get(Person.class, id); + } + + public Person getById(Integer id, boolean lock) { + if (lock) { + return (Person) getSession().get(Person.class, id, + LockMode.UPGRADE); + } else + return getById(id); + } + + /** + * Find Person by criteria. + * If a parameter is null it is not used in the query. + * //FIXME: there's certainly an issue with foreign keys... + */ + @SuppressWarnings("unchecked") + public List<Person> findByCriteria(String name, String firstName, Integer age, Integer idCity) { + + Criteria criteria = getSession().createCriteria(Person.class); + + if (name != null) { + criteria.add(Restrictions.eq("name", name)); + } + + if (firstName != null) { + criteria.add(Restrictions.eq("firstName", firstName)); + } + + if (age != null) { + criteria.add(Restrictions.eq("age", age)); + } + + if (idCity != null) { + criteria.add(Restrictions.eq("idCity", idCity)); + } + + return criteria.list(); + } + + /** + * Find Person by criteria. + */ + @SuppressWarnings("unchecked") + public List<Person> findByCriteria(Map criterias) { + + Criteria criteria = getSession().createCriteria(Person.class); + criteria.add(Restrictions.allEq(criterias)); + return criteria.list(); + } + + public int deleteById(Integer id) { + Query q = getSession().createQuery("delete from Person where id = :id"); + q.setParameter("id",id); + return q.executeUpdate(); + } + + @SuppressWarnings("unchecked") + public List<Person> findAll() { + Query q = getSession().createQuery("from Person"); + q.setCacheable(true); + return q.list(); + } + + /** + * Find Person by name + */ + @SuppressWarnings("unchecked") + public List<Person> findByName(String name) { + Query q = getSession().createQuery("from Person where name = :name"); + q.setParameter("name",name); + q.setCacheable(true); + return q.list(); + } + + /** + * Find Person by firstName + */ + @SuppressWarnings("unchecked") + public List<Person> findByFirstName(String firstName) { + Query q = getSession().createQuery("from Person where firstName = :firstName"); + q.setParameter("firstName",firstName); + q.setCacheable(true); + return q.list(); + } + + /** + * Find Person by age + */ + @SuppressWarnings("unchecked") + public List<Person> findByAge(Integer age) { + Query q = getSession().createQuery("from Person where age = :age"); + q.setParameter("age",age); + q.setCacheable(true); + return q.list(); + } + + /** + * Find Person by idCity + */ + @SuppressWarnings("unchecked") + public List<Person> findByIdCity(Integer idCity) { + Query q = getSession().createQuery("from Person where city.idCity = :idCity"); + q.setParameter("idCity",idCity); + q.setCacheable(true); + return q.list(); + } + + +} ++----------------------------------------------------------+ + +** Pojos + + * com.salto.pojodao.pojo.City : Pojo mapping city table + ++----------------------------------------------------------+ +package com.salto.pojodao.pojo; + +import java.util.List; +import java.io.Serializable; +import java.sql.Timestamp; + + +/** + * <p>Pojo mapping table city</p> + * <p></p> + * + * <p>Generated at Thu Feb 15 16:29:39 CET 2007</p> + * @author Salto-db Generator Ant v1.0.15 / Hibernate pojos and xml mapping files. + * + */ +public class City implements Serializable { + + /** + * Attribute idCity. + */ + private Integer idCity; + + /** + * Attribute name. + */ + private String name; + + /** + * List of Person + */ + private List<Person> persons = null; + + + /** + * @return idCity + */ + public Integer getIdCity() { + return idCity; + } + + /** + * @param idCity new value for idCity + */ + public void setIdCity(Integer idCity) { + this.idCity = idCity; + } + + /** + * @return name + */ + public String getName() { + return name; + } + + /** + * @param name new value for name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the list of Person + */ + public List<Person> getPersons() { + return this.persons; + } + + /** + * Set the list of Person + */ + public void setPersons(List<Person> persons) { + this.persons = persons; + } + +} ++----------------------------------------------------------+ + + * com.salto.pohodao.pojo.Person : Entity mapping person table + ++----------------------------------------------------------+ +package com.salto.pojodao.pojo; + +import java.util.List; +import java.io.Serializable; +import java.sql.Timestamp; + + +/** + * <p>Pojo mapping table person</p> + * <p></p> + * + * <p>Generated at Thu Feb 15 16:29:39 CET 2007</p> + * @author Salto-db Generator Ant v1.0.15 / Hibernate pojos and xml mapping files. + * + */ +public class Person implements Serializable { + + /** + * Attribute idPerson. + */ + private Integer idPerson; + + /** + * Attribute name. + */ + private String name; + + /** + * Attribute firstName. + */ + private String firstName; + + /** + * Attribute age. + */ + private Integer age; + + /** + * Attribute city + */ + private City city; + + + /** + * @return idPerson + */ + public Integer getIdPerson() { + return idPerson; + } + + /** + * @param idPerson new value for idPerson + */ + public void setIdPerson(Integer idPerson) { + this.idPerson = idPerson; + } + + /** + * @return name + */ + public String getName() { + return name; + } + + /** + * @param name new value for name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return firstName + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName new value for firstName + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return age + */ + public Integer getAge() { + return age; + } + + /** + * @param age new value for age + */ + public void setAge(Integer age) { + this.age = age; + } + + /** + * get city + */ + public City getCity() { + return this.city; + } + + /** + * set city + */ + public void setCity(City city) { + this.city = city; + } + + + +} ++----------------------------------------------------------+ + +** Configuration files + + * hibernate.cfg.xml + ++----------------------------------------------------------+ +<!DOCTYPE hibernate-configuration PUBLIC + "-//Hibernate/Hibernate Configuration DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> + +<!-- This file has been generated by Salto-db Generator Ant v1.0.15 at Thu Feb 15 16:29:39 CET 2007 --> +<hibernate-configuration> + <session-factory> + + <!-- You need to complete the configuration here. This is just a sample, you should + use a connection pool --> + <property name="connection.url">jdbc:mysql://localhost/sdb</property> + <property name="connection.username">root</property> + <property name="connection.driver_class">com.mysql.jdbc.Driver</property> + <!-- Your database is MySQL--> + <property name="dialect">org.hibernate.dialect.MySQLDialect</property> + <property name="connection.password">XXXXXXXX</property> + <property name="show_sql">true</property> + + <mapping resource="City.hbm.xml" /> + <mapping resource="Person.hbm.xml" /> + + </session-factory> +</hibernate-configuration> ++----------------------------------------------------------+ + + * City.hbm.xml + ++----------------------------------------------------------+ +<!DOCTYPE hibernate-mapping PUBLIC + "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> + +<!-- This file has been generated by Salto-db Generator Ant v1.0.15 / Hibernate pojos + and xml mapping files. at Thu Feb 15 16:29:39 CET 2007 --> +<hibernate-mapping> + <class name="com.salto.pojodao.pojo.City" table="city"> + + <id name="idCity"> + <generator class="native"/> + </id> + + <property name="name" column="name"/> + + <bag name="persons" inverse="true"> + <key column="id_city"/> + <one-to-many class="com.salto.pojodao.pojo.Person"/> + </bag> + + </class> +</hibernate-mapping> ++----------------------------------------------------------+ + + * Person.hbm.xml + ++----------------------------------------------------------+ +<!DOCTYPE hibernate-mapping PUBLIC + "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> + +<!-- This file has been generated by Salto-db Generator Ant v1.0.15 / Hibernate pojos + and xml mapping files. at Thu Feb 15 16:29:39 CET 2007 --> +<hibernate-mapping> + <class name="com.salto.pojodao.pojo.Person" table="person"> + + <id name="idPerson"> + <generator class="native"/> + </id> + + <property name="name" column="name"/> + + <property name="firstName" column="first_name"/> + + <property name="age" column="age"/> + + <many-to-one name="city" column="id_city"/> + + </class> +</hibernate-mapping> ++----------------------------------------------------------+ + +* Usage + + Retrieve every persons in database : + ++--------------------------------------------------------------+ +List<Person> persons = DAOFactory.DEFAULT.buildPersonDAO().findAll(); ++--------------------------------------------------------------+ + + Retrieve every persons that lives in a "Paris" : + ++--------------------------------------------------------------+ +City paris = DAOFactory.DEFAULT.buildCityDAO().findByName("Paris"); +List<Person> parisCitizen = paris.getPersons(); + +// if you know what Paris's id is, you can use this code : +// List<Person> parisCitizen = DAOFactory.DEFAULT.buildPersonDAO().findByIdCity(parisId); ++--------------------------------------------------------------+ + + Save a new Person in database : + ++--------------------------------------------------------------+ +Person person = new Person(); +person.setName("doe"); +person.setFirstName("john"); +person.setAge(20); + +DAOFactory.DEFAULT.buildPersonDAO().save(person); ++--------------------------------------------------------------+ + + As you can see, there is absolutely no reference to hibernate or even to database management in the code you have to write. You can + focus on business logic instead of loosing time managing connections, transactions and so on. \ No newline at end of file Modified: salto-db-generator/trunk/src/site/apt/roadmap.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/roadmap.apt 2007-02-15 14:34:31 UTC (rev 246) +++ salto-db-generator/trunk/src/site/apt/roadmap.apt 2007-02-15 16:13:47 UTC (rev 247) @@ -12,4 +12,4 @@ * Possibility to use custom plugins within the Eclipse plugin - * Complete webapp generation with crud operations. \ No newline at end of file + * Complete webapp generation with crud operations \ No newline at end of file Added: salto-db-generator/trunk/src/site/resources/images/screenshot2.png =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/screenshot2.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-15 14:34:33
|
Revision: 246 http://svn.sourceforge.net/salto-db/?rev=246&view=rev Author: rflament Date: 2007-02-15 06:34:31 -0800 (Thu, 15 Feb 2007) Log Message: ----------- doc Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt salto-db-generator/trunk/src/site/apt/tutorials/customplugin.apt salto-db-generator/trunk/src/site/site.xml Added Paths: ----------- salto-db-generator/trunk/src/site/apt/roadmap.apt Modified: salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt 2007-02-12 17:07:35 UTC (rev 245) +++ salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt 2007-02-15 14:34:31 UTC (rev 246) @@ -14,7 +14,7 @@ In each dao there is a getById() method, a save() method, an update() method, a delete() method and a finder for each different column. - If you want something equivalebt but without ejb3 annotation, have a look at the {{{pojohibernatedao.html}"Pojos and Hibernate DAOs" plugin}}. + If you want something equivalebt but without ejb3 annotations, have a look at the {{{pojohibernatedao.html}"Pojos and Hibernate DAOs" plugin}}. * Example Added: salto-db-generator/trunk/src/site/apt/roadmap.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/roadmap.apt (rev 0) +++ salto-db-generator/trunk/src/site/apt/roadmap.apt 2007-02-15 14:34:31 UTC (rev 246) @@ -0,0 +1,15 @@ + --- + Roadmap + --- + +Roadmap + + The next version will be version 1.2. Here are plans for v1.2 : + + * Core Api rewrite so plugins will be easier to write + + * Spring/Hibernate plugin + + * Possibility to use custom plugins within the Eclipse plugin + + * Complete webapp generation with crud operations. \ No newline at end of file Modified: salto-db-generator/trunk/src/site/apt/tutorials/customplugin.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/tutorials/customplugin.apt 2007-02-12 17:07:35 UTC (rev 245) +++ salto-db-generator/trunk/src/site/apt/tutorials/customplugin.apt 2007-02-15 14:34:31 UTC (rev 246) @@ -8,7 +8,7 @@ How to write a custom plugin for Salto-db Generator It is possible to write your own plugins and to use them from the Ant task. It is not yet possible to use custom - plugins from the Eclipse plugin. + plugins within the Eclipse plugin. To write a plugin you need to create class that implements the {{{../apidocs/com/salto/db/generator/plugin/IGeneratorPlugin.html}IGeneratorPlugin}} interface. Modified: salto-db-generator/trunk/src/site/site.xml =================================================================== --- salto-db-generator/trunk/src/site/site.xml 2007-02-12 17:07:35 UTC (rev 245) +++ salto-db-generator/trunk/src/site/site.xml 2007-02-15 14:34:31 UTC (rev 246) @@ -17,7 +17,9 @@ <item name="Eclipse plugin" href="eclipseplugin.html"/> <item name="Download" href="download.html"/><!-- <item name="FAQ" href="faq.html"/> - --></menu> + --> + <item name="Roadmap" href="roadmap.html"/> + </menu> <menu name="Plugins"> <item name="Salto-db" href="plugins/saltodb.html"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From:
<ji...@is...> - 2007-02-12 18:42:13
|
[ http://issues.salto-consulting.com/jira/browse/SALTODB-8?page=3Dall = ] R=C3=A9mi Flament closed SALTODB-8. ------------------------------ Resolution: Fixed done, will be included in 1.0.15 > Generated DAO should have a findByCriteria method > ------------------------------------------------- > > Key: SALTODB-8 > URL: http://issues.salto-consulting.com/jira/browse/SALTO= DB-8 > Project: Salto-db > Issue Type: New Feature > Components: Salto-db Generator > Reporter: R=C3=A9mi Flament > Assigned To: R=C3=A9mi Flament > > In each dao there should be a findByCriteria method which takes every col= umns as parameters or a pre-filled object.=20 > If a column is not null, then it should be used in the find method (we ca= n use hibernate criteria api to do that). > Example : > If a person has two attributes, name and firstName, this method (or equiv= alent) should be generated in the PersonDAO : > public List<Person> findByCriteria(String name, String firstName) > { > Criteria criteria =3D session.createCriteria(Person.class); > if (name!=3D null) { > =09criteria.add(Restrictions.eq("name", name)); > } > if (firstName!=3D null) { > =09criteria.add(Restrictions.eq("firstName", firstName)); > } > return criteria.list(); > } > Once you have a method like this one, it becomes very easy to develop sea= rch methods with a lot of criterias . --=20 This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: htt= p://issues.salto-consulting.com/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From:
<ji...@is...> - 2007-02-12 18:40:53
|
[ http://issues.salto-consulting.com/jira/browse/SALTODB-9?page=3Dall = ] R=C3=A9mi Flament closed SALTODB-9. ------------------------------ Resolution: Fixed done, will be include in 1.0.15 > Column length > ------------- > > Key: SALTODB-9 > URL: http://issues.salto-consulting.com/jira/browse/SALTO= DB-9 > Project: Salto-db > Issue Type: Improvement > Components: Salto-db Generator > Reporter: R=C3=A9mi Flament > Assigned To: R=C3=A9mi Flament > > When an hibernate pojo is generated, the mapping should contain the "leng= th" keyword if there is a length in the corresponding db-column. > Example : > @Column(name =3D "column_name", length=3D50) --=20 This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: htt= p://issues.salto-consulting.com/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
From: <rfl...@us...> - 2007-02-12 17:08:50
|
Revision: 245 http://svn.sourceforge.net/salto-db/?rev=245&view=rev Author: rflament Date: 2007-02-12 09:07:35 -0800 (Mon, 12 Feb 2007) Log Message: ----------- SALTODB-9 Modified Paths: -------------- salto-db-generator/trunk/templates/ejb3/setter.vm Modified: salto-db-generator/trunk/templates/ejb3/setter.vm =================================================================== --- salto-db-generator/trunk/templates/ejb3/setter.vm 2007-02-07 17:39:29 UTC (rev 244) +++ salto-db-generator/trunk/templates/ejb3/setter.vm 2007-02-12 17:07:35 UTC (rev 245) @@ -101,7 +101,11 @@ #if (${col.isAutoIncrement()}) @GeneratedValue #end +#if ($col.getNonPrimitifClass()=="String") + @Column(name = "$col.colName", length = $col.colSize) + #else @Column(name = "$col.colName") + #end #end public $col.getNonPrimitifClass() ${col.getterMethod()}() { return ${col.javaAttName}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-07 17:39:38
|
Revision: 244 http://svn.sourceforge.net/salto-db/?rev=244&view=rev Author: rflament Date: 2007-02-07 09:39:29 -0800 (Wed, 07 Feb 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedaotests.apt salto-db-generator/trunk/src/site/apt/tutorials/tuto-doc.apt salto-db-generator/trunk/src/site/site.xml Added Paths: ----------- salto-db-generator/trunk/src/com/salto/db/ant/RegisterPluginTask.java salto-db-generator/trunk/src/site/apt/tutorials/customplugin.apt Added: salto-db-generator/trunk/src/com/salto/db/ant/RegisterPluginTask.java =================================================================== --- salto-db-generator/trunk/src/com/salto/db/ant/RegisterPluginTask.java (rev 0) +++ salto-db-generator/trunk/src/com/salto/db/ant/RegisterPluginTask.java 2007-02-07 17:39:29 UTC (rev 244) @@ -0,0 +1,45 @@ +package com.salto.db.ant; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +import com.salto.db.generator.plugin.IGeneratorPlugin; +import com.salto.db.generator.plugin.Plugins; + +/** + * Register a plugin + * + * @author rfl...@sa... + * + */ +public class RegisterPluginTask extends Task { + + private String className; + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public void execute() throws BuildException { + log("registering plugin from classname '" + className + "'"); + + try { + Class c = Class.forName(className); + IGeneratorPlugin plugin = (IGeneratorPlugin) c.newInstance(); + Plugins.getInstance().addPlugin(plugin); + + } catch (ClassNotFoundException e) { + throw new BuildException("cannot find class '" + className + + "' in classpath", e); + + } catch (Exception e) { + throw new BuildException(e); + } + + } + +} Modified: salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt 2007-02-06 16:11:01 UTC (rev 243) +++ salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt 2007-02-07 17:39:29 UTC (rev 244) @@ -14,6 +14,8 @@ In each dao there is a getById() method, a save() method, an update() method, a delete() method and a finder for each different column. + If you want something equivalebt but without ejb3 annotation, have a look at the {{{pojohibernatedao.html}"Pojos and Hibernate DAOs" plugin}}. + * Example Suppose we have two tables in a database : Modified: salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedaotests.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedaotests.apt 2007-02-06 16:11:01 UTC (rev 243) +++ salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedaotests.apt 2007-02-07 17:39:29 UTC (rev 244) @@ -1,8 +1,163 @@ --- - EJB3, Hibernate DAOs and unit tests plugin + EJB3, Hibernate DAOs and Junit tests plugin --- -EJB3, Hibernate DAOs and unit tests plugin +EJB3, Hibernate DAOs and JUnit tests plugin - This plugin generated the same files as the "EJB3 And Hibernate Daos" plugin, plus JUnit testcases for every generated daos. + This plugin generates the same files as the {{{ejb3hibernatedao.html}"EJB3 And Hibernate Daos" plugin}}, plus JUnit testcases for every generated daos. + + Thanks to this plugin, you can directly test generated daos and have an example of how to use them. + + Here is a sample generated testcase : + ++----------------------------------------------------------+ +package com.salto.ejb3dao.test; + +import junit.framework.TestCase; +import java.util.List; +import java.sql.Timestamp; + +import com.salto.ejb3dao.DAOFactory; +import com.salto.ejb3dao.pojo.Person; +import com.salto.ejb3dao.PersonDAO; + +/** + * <p>Unit test for com.salto.ejb3dao.PersonDAO</p> + * <p>Generated at Wed Feb 07 16:08:05 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + TestCases + */ +public class PersonDAOTest extends TestCase { + + private PersonDAO dao; + + private Integer existingId; + + private Person testEntityPerson; + + private String testName; + + private String testFirstName; + + private int testAge; + + private int testIdCity; + + + public void setUp() throws Exception { + setPersonDAO(DAOFactory.DEFAULT.buildPersonDAO()); + //TODO: call setExistingId() with an id that exists in database + //TODO: call setTestPerson() with an Person instance + } + + public void tearDown() { + existingId = null; + dao = null; + testEntityPerson = null; + } + + public void setPersonDAO(PersonDAO dao) { + this.dao = dao; + } + + public PersonDAO getPersonDAO() { + return this.dao; + } + + public void setExistingId(Integer id) { + this.existingId = id; + } + + public Integer getExistingId() { + return this.existingId; + } + + public Person getTestEntityPerson() { + return testEntityPerson; + } + + public void setTestEntityPerson(Person testEntityPerson) { + this.testEntityPerson = testEntityPerson; + } + + public void testGetById() { + Person test = dao.getById(existingId); + assertNotNull(test); + } + + public void testFindAll() { + List<Person> all = dao.findAll(); + assertNotNull(all); + assertFalse(all.isEmpty()); + } + + public void testSaveAndRemove() { + dao.save(testEntityPerson); + Person test = dao.getById(testEntityPerson.getIdPerson()); + assertNotNull(testEntityPerson.getIdPerson()); + assertNotNull(test); + dao.delete(testEntityPerson); + test = dao.getById(testEntityPerson.getIdPerson()); + assertNull(test); + } + + public String getTestName() { + return testName; + } + + public void setTestName(String testName) { + this.testName = testName; + } + + public void testFindByName() { + List<Person> list = dao.findByName(testName); + assertNotNull(list); + assertFalse(list.isEmpty()); + } + + public String getTestFirstName() { + return testFirstName; + } + + public void setTestFirstName(String testFirstName) { + this.testFirstName = testFirstName; + } + + public void testFindByFirstName() { + List<Person> list = dao.findByFirstName(testFirstName); + assertNotNull(list); + assertFalse(list.isEmpty()); + } + + public int getTestAge() { + return testAge; + } + + public void setTestAge(int testAge) { + this.testAge = testAge; + } + + public void testFindByAge() { + List<Person> list = dao.findByAge(testAge); + assertNotNull(list); + assertFalse(list.isEmpty()); + } + + public int getTestIdCity() { + return testIdCity; + } + + public void setTestIdCity(int testIdCity) { + this.testIdCity = testIdCity; + } + + public void testFindByIdCity() { + List<Person> list = dao.findByIdCity(testIdCity); + assertNotNull(list); + assertFalse(list.isEmpty()); + } + + +} ++----------------------------------------------------------+ \ No newline at end of file Added: salto-db-generator/trunk/src/site/apt/tutorials/customplugin.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/tutorials/customplugin.apt (rev 0) +++ salto-db-generator/trunk/src/site/apt/tutorials/customplugin.apt 2007-02-07 17:39:29 UTC (rev 244) @@ -0,0 +1,148 @@ + --- + How to write a custom plugin for Salto-db Generator + --- + R\xE9mi Flament + --- + --- + +How to write a custom plugin for Salto-db Generator + + It is possible to write your own plugins and to use them from the Ant task. It is not yet possible to use custom + plugins from the Eclipse plugin. + + To write a plugin you need to create class that implements the {{{../apidocs/com/salto/db/generator/plugin/IGeneratorPlugin.html}IGeneratorPlugin}} interface. + + I advise you to extend the abstract class {{{../apidocs/com/salto/db/generator/plugin/DefaultAbstractGeneratorPlugin.html}DefaultAbstractGeneratorPlugin}}. + + We're going to create a plugin called "myPlugin" which create a text file for each table. In each of those file we will write the name of the table, the name of the columns and their types. + + Here is the code of our custom plugin : + ++------------------------------------------------------------------------+ +package com.test; + +import java.io.FileOutputStream; +import java.io.PrintWriter; + +import salto.tool.jdo.data.JdoInfo; +import salto.tool.sql.data.TableColInfo; + +import com.salto.db.generator.plugin.DefaultAbstractGeneratorPlugin; + +public class MyPlugin extends DefaultAbstractGeneratorPlugin { + + /** + * Create a file for each table that contains column names and types + * + * @see com.salto.db.generator.plugin.IGeneratorPlugin#execute(java.lang.String, + * salto.tool.jdo.data.JdoInfo) + */ + public void execute(String fileName, JdoInfo jdoInfo) throws Exception { + + FileOutputStream fos = null; + PrintWriter printWriter = null; + + try { + fos = new FileOutputStream(fileName + ".txt"); + printWriter = new PrintWriter(fos); + printWriter.println("----------------------------------------"); + printWriter.println("Table " + jdoInfo.getTableName()); + printWriter.println("----------------------------------------"); + for (int i = 0; i < jdoInfo.getColInfos().length; i++) { + TableColInfo info = jdoInfo.getColInfos()[i]; + printWriter.println(info.getColName() + " " + + info.getColTypName()); + } + } + + catch (Exception e) { + e.printStackTrace(); + + } finally { + try { + printWriter.close(); + } catch (Exception e) { + + } + + try { + fos.close(); + } catch (Exception e) { + + } + } + } + + /** + * This prefix will be added to the name that we are passed as a parameter + * in the execute() method. + * + * @see com.salto.db.generator.plugin.IGeneratorPlugin#getDefaultPrefix() + */ + public String getDefaultPrefix() { + return "MyCustomPrefix"; + } + + /** + * Long description show in the eclipse plugin. + * + * @see com.salto.db.generator.plugin.IGeneratorPlugin#getLongDescription() + */ + public String getLongDescription() { + return "This plugin has been written to show how to develop a custom plugin and how to register it." + + " It will generate a simple text for each table containing column names and types."; + } + + /** + * Plugin identifier + * + * @see com.salto.db.generator.plugin.IGeneratorPlugin#getName() + */ + public String getName() { + return "myplugin"; + } + + /** + * short description show in the eclipse plugin. + * + * @see com.salto.db.generator.plugin.IGeneratorPlugin#getShortDescription() + */ + public String getShortDescription() { + return "tutorial custom plugin"; + } + +} ++------------------------------------------------------------------------+ + + Next we need to compile our plugin. Once this is done we can use the salto-db-register task to use it from the + salto-db-generate task : + ++------------------------------------------------------------------+ +<salto-db-register className="com.test.MyPlugin"/> + +<salto-db-generate nameOffset="0" generateView="${generateView}" plugin="myPlugin" schema="${schema}" + tableName="${tableName}" login="${login}" password="${password}" jdbcUrl="${jdbcUrl}" + driverClassName="${driverClassName}" outputDir="${outputDir}" packageName="${packageName}"/> ++------------------------------------------------------------------+ + + After running the Ant build, we end up with as many MyCustomPrefix*.txt files as there are tables + in the database. + + Each generated file looks like that : + ++------------------------------------------------------------------+ +---------------------------------------- +Table person +---------------------------------------- +id_person INTEGER +name VARCHAR +first_name VARCHAR +age INTEGER +id_city INTEGER + ++------------------------------------------------------------------+ + + For people familiar with the Velocity template engine, it might be easier to extend the {{{../apidocs/com/salto/db/generator/plugin/VelocityAbstractPlugin.html}VelocityAbstractPlugin}} when you write a plugin. + + If you write a custom plugin and if you think it could be useful to other people, don't hesitate to send it to us, we'll include it + on next releases. \ No newline at end of file Modified: salto-db-generator/trunk/src/site/apt/tutorials/tuto-doc.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/tutorials/tuto-doc.apt 2007-02-06 16:11:01 UTC (rev 243) +++ salto-db-generator/trunk/src/site/apt/tutorials/tuto-doc.apt 2007-02-07 17:39:29 UTC (rev 244) @@ -4,6 +4,8 @@ Manuel Verriez --- --- + +Salto-db generator: installation & use Salto-db generator is an Eclipse plug-in that allows you to generate JAVA classes in order to interact between your application and a datasource. @@ -13,7 +15,7 @@ * hibernate: Plain Old Java Objects (POJO) generation + xml mapping files or EJB3 annotations (since Hibernate 3.2) -Installation +* Installation Installation is straight forward, once you have Eclipse. You need to add a new update site (Eclipse -> Help -> Software Updates -> Find and install -> Search for new features to install -> New remote site) @@ -23,7 +25,7 @@ [../images/tutorials/doc/eclipse.jpg] Salto-db perspective -Use +* Use Here is an example to illustrate functionalities provided by this plug-in. Modified: salto-db-generator/trunk/src/site/site.xml =================================================================== --- salto-db-generator/trunk/src/site/site.xml 2007-02-06 16:11:01 UTC (rev 243) +++ salto-db-generator/trunk/src/site/site.xml 2007-02-07 17:39:29 UTC (rev 244) @@ -30,6 +30,7 @@ <menu name="Tutorials"> <item name="Eclipse plugin tutorial" href="tutorials/tuto-doc.html"/> + <item name="How to write a custom plugin" href="tutorials/customplugin.html"/> </menu> ${reports} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-06 16:12:17
|
Revision: 243 http://svn.sourceforge.net/salto-db/?rev=243&view=rev Author: rflament Date: 2007-02-06 08:11:01 -0800 (Tue, 06 Feb 2007) Log Message: ----------- documentation Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/plugins/ejb3.apt salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedaotests.apt salto-db-generator/trunk/src/site/apt/plugins/hibernate.apt Added Paths: ----------- salto-db-generator/trunk/src/site/resources/images/screenshot1.png Modified: salto-db-generator/trunk/src/site/apt/plugins/ejb3.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/ejb3.apt 2007-02-05 14:50:31 UTC (rev 242) +++ salto-db-generator/trunk/src/site/apt/plugins/ejb3.apt 2007-02-06 16:11:01 UTC (rev 243) @@ -2,4 +2,297 @@ EJB3 plugin --- -EJB3 plugin \ No newline at end of file +EJB3 plugin + + This plugins generates EJB3 entities. + +* Example + + Suppose we have two tables in a database : + + * Table CITY + + * Table PERSON + + [] + + Here is the corresponding MySQL DDL : + ++---------------------------------------------------+ +CREATE TABLE city ( + id_city int(11) NOT NULL auto_increment, + name varchar(50) NOT NULL, + PRIMARY KEY (id_city) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE person ( + id_person int(11) NOT NULL auto_increment, + name varchar(50) NOT NULL, + first_name varchar(50) NOT NULL, + age int(11) NOT NULL, + id_city int(11) NOT NULL, + PRIMARY KEY (id_person), + KEY fk_person_city (id_city), + CONSTRAINT fk_person_city FOREIGN KEY (id_city) REFERENCES city (id_city) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; ++---------------------------------------------------+ + + A person lives in a city, and for each city there are many persons living in it. So we have a many-to-one relationship. + + EJB3 plugin generate two entities, City and Person : + +** City.java + ++----------------------------------------------------------------- +package com.salto.ejb3; + +import java.util.List; +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Column; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Transient; +import javax.persistence.Embeddable; + +/** + * <p>Pojo mapping table city</p> + * <p></p> + * + * <p>Generated at Tue Feb 06 10:43:30 CET 2007</p> + * @author Salto-db Generator Ant v1.0.15 / EJB3 + * + */ +@Entity +@Table(name = "city", catalog = "sdb") +@SuppressWarnings("serial") +public class City implements Serializable { + + /** + * Attribute idCity. + */ + private Integer idCity; + + /** + * Attribute name. + */ + private String name; + + /** + * List of Person + */ + private List<Person> persons = null; + + + /** + * @return idCity + */ + @Basic + @Id + @GeneratedValue + @Column(name = "id_city") + public Integer getIdCity() { + return idCity; + } + + /** + * @param idCity new value for idCity + */ + public void setIdCity(Integer idCity) { + this.idCity = idCity; + } + + /** + * @return name + */ + @Basic + @Column(name = "name") + public String getName() { + return name; + } + + /** + * @param name new value for name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the list of Person + */ + @OneToMany(mappedBy="city") + public List<Person> getPersons() { + return this.persons; + } + + /** + * Set the list of Person + */ + public void setPersons(List<Person> persons) { + this.persons = persons; + } + + +} ++----------------------------------------------------------------- + +** Person.java + ++----------------------------------------------------------------- +package com.salto.ejb3; + +import java.util.List; +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Column; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Transient; +import javax.persistence.Embeddable; + +/** + * <p>Pojo mapping table person</p> + * <p></p> + * + * <p>Generated at Tue Feb 06 10:43:30 CET 2007</p> + * @author Salto-db Generator Ant v1.0.15 / EJB3 + * + */ +@Entity +@Table(name = "person", catalog = "sdb") +@SuppressWarnings("serial") +public class Person implements Serializable { + + /** + * Attribute idPerson. + */ + private Integer idPerson; + + /** + * Attribute name. + */ + private String name; + + /** + * Attribute firstName. + */ + private String firstName; + + /** + * Attribute age. + */ + private Integer age; + + /** + * Attribute city + */ + private City city; + + + /** + * @return idPerson + */ + @Basic + @Id + @GeneratedValue + @Column(name = "id_person") + public Integer getIdPerson() { + return idPerson; + } + + /** + * @param idPerson new value for idPerson + */ + public void setIdPerson(Integer idPerson) { + this.idPerson = idPerson; + } + + /** + * @return name + */ + @Basic + @Column(name = "name") + public String getName() { + return name; + } + + /** + * @param name new value for name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return firstName + */ + @Basic + @Column(name = "first_name") + public String getFirstName() { + return firstName; + } + + /** + * @param firstName new value for firstName + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return age + */ + @Basic + @Column(name = "age") + public Integer getAge() { + return age; + } + + /** + * @param age new value for age + */ + public void setAge(Integer age) { + this.age = age; + } + + /** + * get city + */ + @ManyToOne + @JoinColumn(name = "id_city") + public City getCity() { + return this.city; + } + + /** + * set city + */ + public void setCity(City city) { + this.city = city; + } + + + +} ++----------------------------------------------------------------- + + Once entities are generated you can use them with any EJB3 persistence manager, such as Hibernate annotations, toplink, and so on. \ No newline at end of file Modified: salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt 2007-02-05 14:50:31 UTC (rev 242) +++ salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedao.apt 2007-02-06 16:11:01 UTC (rev 243) @@ -2,4 +2,1061 @@ EJB3 And Hibernate DAOs plugin --- -EJB3 And Hibernate DAOs plugin \ No newline at end of file +EJB3 And Hibernate DAOs plugin + + This plugin generates EJB3 entities (like the EJB3 plugin), a abstract persistence layer and an hibernate + annotation implementation. + + The generated code is actually a implementation of the pattern of described at {{http://www.hibernate.org/328.html}}. This pattern + suits well with the open-session in view pattern (i.e. web applications). + + For each table the plugin generates the entity class, an abstract DAO class and a concrete hibernate dao. + + In each dao there is a getById() method, a save() method, an update() method, a delete() method and a finder for each different column. + +* Example + + Suppose we have two tables in a database : + + * Table CITY + + * Table PERSON + + [] + + Here is the corresponding MySQL DDL : + ++---------------------------------------------------+ +CREATE TABLE city ( + id_city int(11) NOT NULL auto_increment, + name varchar(50) NOT NULL, + PRIMARY KEY (id_city) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE person ( + id_person int(11) NOT NULL auto_increment, + name varchar(50) NOT NULL, + first_name varchar(50) NOT NULL, + age int(11) NOT NULL, + id_city int(11) NOT NULL, + PRIMARY KEY (id_person), + KEY fk_person_city (id_city), + CONSTRAINT fk_person_city FOREIGN KEY (id_city) REFERENCES city (id_city) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; ++---------------------------------------------------+ + + A person lives in a city, and for each city there are many persons living in it. So we have a many-to-one relationship. + + Once everything is generated, you can write one line of code to retrieve every persons in the database to print their name and the name + of the city they live in : + ++--------------------------------------------------------------+ +List<Person> persons = DAOFactory.DEFAULT.buildPersonDAO().findAll(); +for (Person person : persons) + { + System.out.println(person.getFirstName()+" "+person.getName()+" lives in "+person.getCity().getName()); + } + ++--------------------------------------------------------------+ + + + Here are the different generated files : + +[../images/screenshot1.png] + +** Interfaces + + * com.salto.ejb3dao.CityDAO : an interface for city daos + ++--------------------------------------------------------+ +package com.salto.ejb3dao; + +import java.util.Map; +import java.util.List; +import java.sql.Timestamp; + +import com.salto.ejb3dao.pojo.City; +/** + * <p>Hibernate DAO layer for Citys</p> + * <p>Generated at Tue Feb 06 11:15:11 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ +public interface CityDAO extends GenericDAO<City,Integer> { + + /* + * TODO : Add specific businesses daos here. + * These methods will be overwrited if you re-generate this interface. + * You might want to extend this interface and to change the dao factory to return + * an instance of the new implemenation in buildCityDAO() + */ + + /** + * Find City by criteria. + * If a parameter is null it is not used in the query. + */ + public List<City> findByCriteria(String name); + + /** + * Find City by criteria. + */ + public List<City> findByCriteria(Map criterias); + + + /** + * Find City by name + */ + public List<City> findByName(String name); + +} ++--------------------------------------------------------+ + + * com.salto.ejb3dao.DAOFactory : a factory for daos. When you develop you use this class to build daos instance, this way you don't have any references to an implementation in your methods and it makes it easy to change of implementation. + ++----------------------------------------------------------+ +package com.salto.ejb3dao; + +import com.salto.ejb3dao.hibernate.HibernateDAOFactory; + +/** + * Generated at Tue Feb 06 11:15:11 CET 2007 + * + * @see http://www.hibernate.org/328.html + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ + +public abstract class DAOFactory { + + private static final DAOFactory HIBERNATE = new HibernateDAOFactory(); + + public static final DAOFactory DEFAULT = HIBERNATE; + + public abstract CityDAO buildCityDAO(); + + public abstract PersonDAO buildPersonDAO(); + +} ++----------------------------------------------------------+ + + * com.salto.ejb3dao.GenericDAO : an interface describing a generic dao. Other daos extend it. + ++----------------------------------------------------------+ +package com.salto.ejb3dao; + +import java.io.Serializable; +import java.util.List; + +/** + * Generated at Tue Feb 06 11:15:11 CET 2007 + * + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ +public interface GenericDAO<T, ID extends Serializable> { + + T getById(ID id, boolean lock); + + T getById(ID id); + + List<T> findAll(); + + void save(T entity); + + void update(T entity); + + void saveOrUpdate(T entity); + + void delete(T entity); + + void delete(T entity, Boolean doItNow); + + int deleteById(ID id); + +} ++----------------------------------------------------------+ + + * com.salto.ejb3dao.PersonDAO : an interface for person daos + ++----------------------------------------------------------+ +package com.salto.ejb3dao; + +import java.util.Map; +import java.util.List; +import java.sql.Timestamp; + +import com.salto.ejb3dao.pojo.Person; +/** + * <p>Hibernate DAO layer for Persons</p> + * <p>Generated at Tue Feb 06 11:15:11 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ +public interface PersonDAO extends GenericDAO<Person,Integer> { + + /* + * TODO : Add specific businesses daos here. + * These methods will be overwrited if you re-generate this interface. + * You might want to extend this interface and to change the dao factory to return + * an instance of the new implemenation in buildPersonDAO() + */ + + /** + * Find Person by criteria. + * If a parameter is null it is not used in the query. + */ + public List<Person> findByCriteria(String name, String firstName, Integer age, Integer idCity); + + /** + * Find Person by criteria. + */ + public List<Person> findByCriteria(Map criterias); + + + /** + * Find Person by name + */ + public List<Person> findByName(String name); + + /** + * Find Person by firstName + */ + public List<Person> findByFirstName(String firstName); + + /** + * Find Person by age + */ + public List<Person> findByAge(Integer age); + + /** + * Find Person by idCity + */ + public List<Person> findByIdCity(Integer idCity); + +} ++----------------------------------------------------------+ + +** Hibernate Annotations implementation + + * com.salto.ejb3dao.hibernate.AbstractHibernateDAO : an abstract hibernate implementation of GenericDAO + ++----------------------------------------------------------+ +package com.salto.ejb3dao.hibernate; + +import com.salto.ejb3dao.GenericDAO; +import java.io.Serializable; + +import org.hibernate.FlushMode; +import org.hibernate.Query; +import org.hibernate.LockMode; +import org.hibernate.Session; + +/** + * Generated at Tue Feb 06 11:15:11 CET 2007 + * + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ +public abstract class AbstractHibernateDAO<T, ID extends Serializable> implements GenericDAO<T, ID> { + + private Session session; + + public AbstractHibernateDAO(Session s) { + session = s; + } + + public Session getSession() { + return session; + } + + public void setSession(Session session) { + this.session = session; + } + + public void save(T entity) { + getSession().save(entity); + } + + public void update(T entity) { + getSession().update(entity); + } + + public void saveOrUpdate(T entity) { + getSession().saveOrUpdate(entity); + } + + public void delete(T entity) { + getSession().delete(entity); + } + + public void delete(T entity, Boolean doItNow) { + if (doItNow) { + getSession().setFlushMode(FlushMode.ALWAYS); + } + delete(entity); + } + + /** + * This method will execute an HQL query and return the number of affected entities. + */ + protected int executeQuery(String query, String namedParams[], Object params[]) { + Query q = getSession().createQuery(query); + + if (namedParams != null) { + for (int i = 0; i < namedParams.length; i++) { + q.setParameter(namedParams[i], params[i]); + } + } + + return q.executeUpdate(); + } + + protected int executeQuery(String query) { + return executeQuery(query, null, null); + } + + /** + * This method will execute a Named HQL query and return the number of affected entities. + */ + protected int executeNamedQuery(String namedQuery, String namedParams[], Object params[]) { + Query q = getSession().getNamedQuery(namedQuery); + + if (namedParams != null) { + for (int i = 0; i < namedParams.length; i++) { + q.setParameter(namedParams[i], params[i]); + } + } + + return q.executeUpdate(); + } + + protected int executeNamedQuery(String namedQuery) { + return executeNamedQuery(namedQuery, null, null); + } + +} ++----------------------------------------------------------+ + + * com.salto.ejb3dao.hibernate.CityHibernateDAO : the Hibernate implementation of CityDAO + ++----------------------------------------------------------+ +package com.salto.ejb3dao.hibernate; + +import java.util.Map; +import java.util.List; +import java.sql.Timestamp; + +import com.salto.ejb3dao.pojo.City; +import com.salto.ejb3dao.CityDAO; + +import org.hibernate.Criteria; +import org.hibernate.LockMode; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; + +/** + * <p>Hibernate DAO layer for Citys</p> + * <p>Generated at Tue Feb 06 11:15:11 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ +public class CityHibernateDAO extends + AbstractHibernateDAO<City, Integer> implements + CityDAO { + + public CityHibernateDAO(Session s) { + super(s); + } + + public City getById(Integer id) { + return (City) getSession().get(City.class, id); + } + + public City getById(Integer id, boolean lock) { + if (lock) { + return (City) getSession().get(City.class, id, + LockMode.UPGRADE); + } else + return getById(id); + } + + /** + * Find City by criteria. + * If a parameter is null it is not used in the query. + */ + @SuppressWarnings("unchecked") + public List<City> findByCriteria(String name) { + + Criteria criteria = getSession().createCriteria(City.class); + + if (name != null) { + criteria.add(Restrictions.eq("name", name)); + } + + return criteria.list(); + } + + /** + * Find City by criteria. + */ + @SuppressWarnings("unchecked") + public List<City> findByCriteria(Map criterias) { + + Criteria criteria = getSession().createCriteria(City.class); + criteria.add(Restrictions.allEq(criterias)); + return criteria.list(); + } + + public int deleteById(Integer id) { + Query q = getSession().createQuery("delete from City where id = :id"); + q.setParameter("id",id); + return q.executeUpdate(); + } + + @SuppressWarnings("unchecked") + public List<City> findAll() { + Query q = getSession().createQuery("from City"); + q.setCacheable(true); + return q.list(); + } + + /** + * Find City by name + */ + @SuppressWarnings("unchecked") + public List<City> findByName(String name) { + Query q = getSession().createQuery("from City where name = :name"); + q.setParameter("name",name); + q.setCacheable(true); + return q.list(); + } + + +} ++----------------------------------------------------------+ + + * com.salto.ejb3dao.hibernate.HibernateDAOFactory : the Hibernate implementation of DAOFactory + ++----------------------------------------------------------+ +package com.salto.ejb3dao.hibernate; + +import com.salto.ejb3dao.DAOFactory; +import com.salto.ejb3dao.CityDAO; +import com.salto.ejb3dao.PersonDAO; + +/** + * Generated at Tue Feb 06 11:15:11 CET 2007 + * + * @see http://www.hibernate.org/43.html + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ +public class HibernateDAOFactory extends DAOFactory { + + /* (non-Javadoc) + * @see com.salto.ejb3dao.DAOFactory#buildCityDAO() + */ + @Override + public CityDAO buildCityDAO() { + return new CityHibernateDAO(HibernateUtil.getSession()); + } + + /* (non-Javadoc) + * @see com.salto.ejb3dao.DAOFactory#buildPersonDAO() + */ + @Override + public PersonDAO buildPersonDAO() { + return new PersonHibernateDAO(HibernateUtil.getSession()); + } + +} ++----------------------------------------------------------+ + + * com.salto.ejb3dao.hibernate.HibernateUtil : utility methods for Hibernate + ++----------------------------------------------------------+ +package com.salto.ejb3dao.hibernate; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.cfg.AnnotationConfiguration; + +/** + * Generated at Tue Feb 06 11:15:11 CET 2007 + * + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ +public final class HibernateUtil { + + private static SessionFactory sessionFactory; + + private static final ThreadLocal threadSession = new ThreadLocal(); + + private static final ThreadLocal threadTransaction = new ThreadLocal(); + + static { + try { + sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); + } catch (Throwable ex) { + + throw new ExceptionInInitializerError(ex); + } + } + + private HibernateUtil() { + + } + + /** + * Returns the SessionFactory used for this static class. + * + * @return SessionFactory + */ + public static SessionFactory getSessionFactory() { + return sessionFactory; + } + + /** + * Retrieves the current Session local to the thread. <p/> If no Session is + * open, opens a new Session for the running thread. + * + * @return Session + */ + @SuppressWarnings("unchecked") + public static Session getSession() { + Session s = (Session) threadSession.get(); + + if (s == null) { + + s = getSessionFactory().openSession(); + + threadSession.set(s); + beginTransaction(); + } + + return s; + } + + /** + * Closes the Session local to the thread. + */ + @SuppressWarnings("unchecked") + public static void closeSession() { + + Session s = (Session) threadSession.get(); + threadSession.set(null); + if (s != null && s.isOpen()) { + + s.close(); + } + + } + + /** + * Start a new database transaction. + */ + @SuppressWarnings("unchecked") + public static void beginTransaction() { + Transaction tx = (Transaction) threadTransaction.get(); + + if (tx == null) { + + tx = getSession().beginTransaction(); + threadTransaction.set(tx); + } + + } + + /** + * Commit the database transaction. + */ + @SuppressWarnings("unchecked") + public static void commitTransaction() { + Transaction tx = (Transaction) threadTransaction.get(); + + if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) { + + tx.commit(); + } + threadTransaction.set(null); + + } + + /** + * Rollback the database transaction. + */ + @SuppressWarnings("unchecked") + public static void rollbackTransaction() { + Transaction tx = (Transaction) threadTransaction.get(); + try { + threadTransaction.set(null); + if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) { + + tx.rollback(); + } + + } finally { + closeSession(); + } + } + +} ++----------------------------------------------------------+ + + * com.salto.ejb3dao.hibernate.PersonHibernateDAO : the Hibernate implementation of PersonDAO + ++----------------------------------------------------------+ +package com.salto.ejb3dao.hibernate; + +import java.util.Map; +import java.util.List; +import java.sql.Timestamp; + +import com.salto.ejb3dao.pojo.Person; +import com.salto.ejb3dao.PersonDAO; + +import org.hibernate.Criteria; +import org.hibernate.LockMode; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; + +/** + * <p>Hibernate DAO layer for Persons</p> + * <p>Generated at Tue Feb 06 11:15:11 CET 2007</p> + * + * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + */ +public class PersonHibernateDAO extends + AbstractHibernateDAO<Person, Integer> implements + PersonDAO { + + public PersonHibernateDAO(Session s) { + super(s); + } + + public Person getById(Integer id) { + return (Person) getSession().get(Person.class, id); + } + + public Person getById(Integer id, boolean lock) { + if (lock) { + return (Person) getSession().get(Person.class, id, + LockMode.UPGRADE); + } else + return getById(id); + } + + /** + * Find Person by criteria. + * If a parameter is null it is not used in the query. + * //FIXME: there's certainly an issue with foreign keys... + */ + @SuppressWarnings("unchecked") + public List<Person> findByCriteria(String name, String firstName, Integer age, Integer idCity) { + + Criteria criteria = getSession().createCriteria(Person.class); + + if (name != null) { + criteria.add(Restrictions.eq("name", name)); + } + + if (firstName != null) { + criteria.add(Restrictions.eq("firstName", firstName)); + } + + if (age != null) { + criteria.add(Restrictions.eq("age", age)); + } + + if (idCity != null) { + criteria.add(Restrictions.eq("idCity", idCity)); + } + + return criteria.list(); + } + + /** + * Find Person by criteria. + */ + @SuppressWarnings("unchecked") + public List<Person> findByCriteria(Map criterias) { + + Criteria criteria = getSession().createCriteria(Person.class); + criteria.add(Restrictions.allEq(criterias)); + return criteria.list(); + } + + public int deleteById(Integer id) { + Query q = getSession().createQuery("delete from Person where id = :id"); + q.setParameter("id",id); + return q.executeUpdate(); + } + + @SuppressWarnings("unchecked") + public List<Person> findAll() { + Query q = getSession().createQuery("from Person"); + q.setCacheable(true); + return q.list(); + } + + /** + * Find Person by name + */ + @SuppressWarnings("unchecked") + public List<Person> findByName(String name) { + Query q = getSession().createQuery("from Person where name = :name"); + q.setParameter("name",name); + q.setCacheable(true); + return q.list(); + } + + /** + * Find Person by firstName + */ + @SuppressWarnings("unchecked") + public List<Person> findByFirstName(String firstName) { + Query q = getSession().createQuery("from Person where firstName = :firstName"); + q.setParameter("firstName",firstName); + q.setCacheable(true); + return q.list(); + } + + /** + * Find Person by age + */ + @SuppressWarnings("unchecked") + public List<Person> findByAge(Integer age) { + Query q = getSession().createQuery("from Person where age = :age"); + q.setParameter("age",age); + q.setCacheable(true); + return q.list(); + } + + /** + * Find Person by idCity + */ + @SuppressWarnings("unchecked") + public List<Person> findByIdCity(Integer idCity) { + Query q = getSession().createQuery("from Person where city.idCity = :idCity"); + q.setParameter("idCity",idCity); + q.setCacheable(true); + return q.list(); + } + + +} ++----------------------------------------------------------+ + +** Entities + + * com.salto.ejb3dao.pojo.City : Entity mapping city table + ++----------------------------------------------------------+ +package com.salto.ejb3dao.pojo; + +import java.util.List; +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Column; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Transient; +import javax.persistence.Embeddable; + +/** + * <p>Pojo mapping table city</p> + * <p></p> + * + * <p>Generated at Tue Feb 06 11:15:10 CET 2007</p> + * @author Salto-db Generator Ant v1.0.15 / EJB3 + * + */ +@Entity +@Table(name = "city", catalog = "sdb") +@SuppressWarnings("serial") +public class City implements Serializable { + + /** + * Attribute idCity. + */ + private Integer idCity; + + /** + * Attribute name. + */ + private String name; + + /** + * List of Person + */ + private List<Person> persons = null; + + + /** + * @return idCity + */ + @Basic + @Id + @GeneratedValue + @Column(name = "id_city") + public Integer getIdCity() { + return idCity; + } + + /** + * @param idCity new value for idCity + */ + public void setIdCity(Integer idCity) { + this.idCity = idCity; + } + + /** + * @return name + */ + @Basic + @Column(name = "name") + public String getName() { + return name; + } + + /** + * @param name new value for name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the list of Person + */ + @OneToMany(mappedBy="city") + public List<Person> getPersons() { + return this.persons; + } + + /** + * Set the list of Person + */ + public void setPersons(List<Person> persons) { + this.persons = persons; + } + + +} ++----------------------------------------------------------+ + + * com.salto.ejb3dao.pojo.Person : Entity mapping person table + ++----------------------------------------------------------+ +package com.salto.ejb3dao.pojo; + +import java.util.List; +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Column; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Transient; +import javax.persistence.Embeddable; + +/** + * <p>Pojo mapping table person</p> + * <p></p> + * + * <p>Generated at Tue Feb 06 11:15:11 CET 2007</p> + * @author Salto-db Generator Ant v1.0.15 / EJB3 + * + */ +@Entity +@Table(name = "person", catalog = "sdb") +@SuppressWarnings("serial") +public class Person implements Serializable { + + /** + * Attribute idPerson. + */ + private Integer idPerson; + + /** + * Attribute name. + */ + private String name; + + /** + * Attribute firstName. + */ + private String firstName; + + /** + * Attribute age. + */ + private Integer age; + + /** + * Attribute city + */ + private City city; + + + /** + * @return idPerson + */ + @Basic + @Id + @GeneratedValue + @Column(name = "id_person") + public Integer getIdPerson() { + return idPerson; + } + + /** + * @param idPerson new value for idPerson + */ + public void setIdPerson(Integer idPerson) { + this.idPerson = idPerson; + } + + /** + * @return name + */ + @Basic + @Column(name = "name") + public String getName() { + return name; + } + + /** + * @param name new value for name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return firstName + */ + @Basic + @Column(name = "first_name") + public String getFirstName() { + return firstName; + } + + /** + * @param firstName new value for firstName + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return age + */ + @Basic + @Column(name = "age") + public Integer getAge() { + return age; + } + + /** + * @param age new value for age + */ + public void setAge(Integer age) { + this.age = age; + } + + /** + * get city + */ + @ManyToOne + @JoinColumn(name = "id_city") + public City getCity() { + return this.city; + } + + /** + * set city + */ + public void setCity(City city) { + this.city = city; + } + +} ++----------------------------------------------------------+ + +** Configuration files + + * Finally, the hibernate configuration file hibernate.cfg.xml + ++----------------------------------------------------------+ +<!DOCTYPE hibernate-configuration PUBLIC + "-//Hibernate/Hibernate Configuration DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> + +<hibernate-configuration> + <session-factory> + + <!-- You need to complete the configuration here. This is just a sample, you should use a connection pool --> + <property name="connection.url">jdbc:mysql://localhost/sdb</property> + <property name="connection.username">root</property> + <property name="connection.driver_class">com.mysql.jdbc.Driver</property> + <!-- Your database is MySQL--> + <property name="dialect">org.hibernate.dialect.MySQLDialect</property> + <property name="connection.password">XXXXXXXX</property> + <property name="show_sql">true</property> + + <mapping class="com.salto.ejb3dao.pojo.City" /> + <mapping class="com.salto.ejb3dao.pojo.Person" /> + + </session-factory> +</hibernate-configuration> + ++----------------------------------------------------------+ + +* Usage + + Retrieve every persons in database : + ++--------------------------------------------------------------+ +List<Person> persons = DAOFactory.DEFAULT.buildPersonDAO().findAll(); ++--------------------------------------------------------------+ + + Retrieve every persons that lives in a "Paris" : + ++--------------------------------------------------------------+ +City paris = DAOFactory.DEFAULT.buildCityDAO().findByName("Paris"); +List<Person> parisCitizen = paris.getPersons(); + +// if you know what Paris's id is, you can use this code : +// List<Person> parisCitizen = DAOFactory.DEFAULT.buildPersonDAO().findByIdCity(parisId); ++--------------------------------------------------------------+ + + Save a new Person in database : + ++--------------------------------------------------------------+ +Person person = new Person(); +person.setName("doe"); +person.setFirstName("john"); +person.setAge(20); + +DAOFactory.DEFAULT.buildPersonDAO().save(person); ++--------------------------------------------------------------+ + + As you can see, there is absolutely no reference to hibernate or even to database management in the code you have to write. You can + focus on business logic instead of loosing time managing connections, transactions and so on. \ No newline at end of file Modified: salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedaotests.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedaotests.apt 2007-02-05 14:50:31 UTC (rev 242) +++ salto-db-generator/trunk/src/site/apt/plugins/ejb3hibernatedaotests.apt 2007-02-06 16:11:01 UTC (rev 243) @@ -2,4 +2,7 @@ EJB3, Hibernate DAOs and unit tests plugin --- -EJB3, Hibernate DAOs and unit tests plugin \ No newline at end of file +EJB3, Hibernate DAOs and unit tests plugin + + This plugin generated the same files as the "EJB3 And Hibernate Daos" plugin, plus JUnit testcases for every generated daos. + \ No newline at end of file Modified: salto-db-generator/trunk/src/site/apt/plugins/hibernate.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/hibernate.apt 2007-02-05 14:50:31 UTC (rev 242) +++ salto-db-generator/trunk/src/site/apt/plugins/hibernate.apt 2007-02-06 16:11:01 UTC (rev 243) @@ -4,7 +4,7 @@ Hibernate plugin - This plugin generate pojos and mapping files for hibernate. + This plugin generates pojos and mapping files for hibernate. It cares about associations by parsing foreign keys. @@ -18,21 +18,321 @@ [] - Here is the corresponding DDL : + Here is the corresponding MySQL DDL : +---------------------------------------------------+ -create table CITY ( - id_city number(20), - name varchar2(50), - constraint PK_CITY primary key ( id_city ) USING INDEX -); +CREATE TABLE city ( + id_city int(11) NOT NULL auto_increment, + name varchar(50) NOT NULL, + PRIMARY KEY (id_city) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -create table PERSON ( - id_person number(20), - name varchar2(50), - first_name varchar2(50), - age number(20), - id_city number(20), - constraint PK_PERSON primary key ( id_person ) USING INDEX -); -+---------------------------------------------------+ \ No newline at end of file +CREATE TABLE person ( + id_person int(11) NOT NULL auto_increment, + name varchar(50) NOT NULL, + first_name varchar(50) NOT NULL, + age int(11) NOT NULL, + id_city int(11) NOT NULL, + PRIMARY KEY (id_person), + KEY fk_person_city (id_city), + CONSTRAINT fk_person_city FOREIGN KEY (id_city) REFERENCES city (id_city) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; ++---------------------------------------------------+ + + A person lives in a city, and for each city there are many persons living in it. So we have a many-to-one relationship. + + Hibernate plugin generates two classes in this case, City and Person : + +** City.java + ++---------------------------------------------------------------------------------------+ +package com.salto.hibernate; + +import java.util.List; +import java.io.Serializable; +import java.sql.Timestamp; + + +/** + * Pojo mapping table city + * + * + * Generated at Tue Feb 06 10:10:55 CET 2007 + * @author Salto-db Eclipse v1.0.14 + * + */ +public class City implements Serializable { + + /** + * Attribute idCity. + */ + private Integer idCity; + + /** + * Attribute name. + */ + private String name; + + /** + * List of Person + */ + private List<Person> persons = null; + + + /** + * @return idCity + */ + public Integer getIdCity() { + return idCity; + } + + /** + * @param idCity new value for idCity + */ + public void setIdCity(Integer idCity) { + this.idCity = idCity; + } + + /** + * @return name + */ + public String getName() { + return name; + } + + /** + * @param name new value for name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the list of Person + */ + public List<Person> getPersons() { + return this.persons; + } + + /** + * Set the list of Person + */ + public void setPersons(List<Person> persons) { + this.persons = persons; + } + +} ++---------------------------------------------------------------------------------------+ + +** Person.java + ++--------------------------------------------------------------------------------------+ +package com.salto.hibernate; + +import java.util.List; +import java.io.Serializable; +import java.sql.Timestamp; + + +/** + * Pojo mapping table person + * + * + * Generated at Tue Feb 06 10:10:56 CET 2007 + * @author Salto-db Eclipse v1.0.14 + * + */ +public class Person implements Serializable { + + /** + * Attribute idPerson. + */ + private Integer idPerson; + + /** + * Attribute name. + */ + private String name; + + /** + * Attribute firstName. + */ + private String firstName; + + /** + * Attribute age. + */ + private Integer age; + + /** + * Attribute city + */ + private City city; + + + /** + * @return idPerson + */ + public Integer getIdPerson() { + return idPerson; + } + + /** + * @param idPerson new value for idPerson + */ + public void setIdPerson(Integer idPerson) { + this.idPerson = idPerson; + } + + /** + * @return name + */ + public String getName() { + return name; + } + + /** + * @param name new value for name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return firstName + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName new value for firstName + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return age + */ + public Integer getAge() { + return age; + } + + /** + * @param age new value for age + */ + public void setAge(Integer age) { + this.age = age; + } + + /** + * get city + */ + public City getCity() { + return this.city; + } + + /** + * set city + */ + public void setCity(City city) { + this.city = city; + } + + + +} ++-----------------------------------------------------------------------------------+ + + Hibernate plugin generates also the mapping file and the hibernate.cfg.xml file : + +** City.hbm.xml + ++-----------------------------------------------------------------------------------+ +<!DOCTYPE hibernate-mapping PUBLIC + "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> + +<!-- This file has been generated by Salto-db Eclipse v1.0.14 at Tue Feb 06 10:10:56 CET 2007 --> +<hibernate-mapping> + <class name="com.salto.hibernate.City" table="city"> + + <id name="idCity"> + <generator class="native"/> + </id> + + <property name="name" column="name"/> + + <bag name="persons" inverse="true"> + <key column="id_city"/> + <one-to-many class="com.salto.hibernate.Person"/> + </bag> + + </class> +</hibernate-mapping> ++-----------------------------------------------------------------------------------+ + +** Person.hbm.xml + ++-----------------------------------------------------------------------------------+ +<!DOCTYPE hibernate-mapping PUBLIC + "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> + +<!-- This file has been generated by Salto-db Eclipse v1.0.14 at Tue Feb 06 10:10:56 CET 2007 --> +<hibernate-mapping> + <class name="com.salto.hibernate.Person" table="person"> + + <id name="idPerson"> + <generator class="native"/> + </id> + + <property name="name" column="name"/> + + <property name="firstName" column="first_name"/> + + <property name="age" column="age"/> + + <many-to-one name="city" column="id_city"/> + + </class> +</hibernate-mapping> ++-----------------------------------------------------------------------------------+ + +** hibernate.cfg.xml + ++-----------------------------------------------------------------------------------+ +<!DOCTYPE hibernate-configuration PUBLIC + "-//Hibernate/Hibernate Configuration DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> + +<!-- This file has been generated by Salto-db Eclipse v1.0.14 at Tue Feb 06 10:10:56 CET 2007 --> +<hibernate-configuration> + <session-factory> + + <!-- You need to complete the configuration here. This is just a sample, you should use a connection pool--> + <property name="connection.url">jdbc:mysql://localhost/sdb</property> + <property name="connection.username">root</property> + <property name="connection.driver_class">com.mysql.jdbc.Driver</property> + <!-- Your database is MySQL--> + <property name="dialect">org.hibernate.dialect.MySQLDialect</property> + <property name="connection.password">XXXXXXXXX</property> + <property name="show_sql">true</property> + + <mapping resource="City.hbm.xml" /> + <mapping resource="Person.hbm.xml" /> + + </session-factory> +</hibernate-configuration> ++-----------------------------------------------------------------------------------+ + + Once these files have been generated, you can directly use them in your project to load and to persist your data. + Of course you still need to be familiar with Hibernate to do so... + + + + + + + \ No newline at end of file Added: salto-db-generator/trunk/src/site/resources/images/screenshot1.png =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/screenshot1.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-05 14:50:42
|
Revision: 242 http://svn.sourceforge.net/salto-db/?rev=242&view=rev Author: rflament Date: 2007-02-05 06:50:31 -0800 (Mon, 05 Feb 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/eclipseplugin.apt Added Paths: ----------- salto-db-generator/trunk/src/site/resources/images/eclipseplugin1.png salto-db-generator/trunk/src/site/resources/images/eclipseplugin2.png Modified: salto-db-generator/trunk/src/site/apt/eclipseplugin.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/eclipseplugin.apt 2007-02-05 14:30:43 UTC (rev 241) +++ salto-db-generator/trunk/src/site/apt/eclipseplugin.apt 2007-02-05 14:50:31 UTC (rev 242) @@ -22,11 +22,13 @@ * Screenshots of the Eclipse plugin - [/images/eclipseplugin1.png] Salto-db perspective + Salto-db perspective : - [/images/eclipseplugin2.png] Database connection +[images/eclipseplugin1.png] Salto-db perspective + + Database connection : - [/images/eclipseplugin2.png] Apply templates View +[images/eclipseplugin2.png] Database connection Added: salto-db-generator/trunk/src/site/resources/images/eclipseplugin1.png =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/eclipseplugin1.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/eclipseplugin2.png =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/eclipseplugin2.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-05 14:41:56
|
Revision: 241 http://svn.sourceforge.net/salto-db/?rev=241&view=rev Author: rflament Date: 2007-02-05 06:30:43 -0800 (Mon, 05 Feb 2007) Log Message: ----------- tutorial manu Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/eclipseplugin.apt salto-db-generator/trunk/src/site/site.xml Added Paths: ----------- salto-db-generator/trunk/src/site/apt/tutorials/ salto-db-generator/trunk/src/site/apt/tutorials/tuto-doc.apt salto-db-generator/trunk/src/site/resources/images/tutorials/ salto-db-generator/trunk/src/site/resources/images/tutorials/doc/ salto-db-generator/trunk/src/site/resources/images/tutorials/doc/eclipse.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/schema.png salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-1.1.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-1.2.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-2.1.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-2.2.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-3.1.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-3.2.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-4.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-5.jpg salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-6.jpg Modified: salto-db-generator/trunk/src/site/apt/eclipseplugin.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/eclipseplugin.apt 2007-02-02 14:59:13 UTC (rev 240) +++ salto-db-generator/trunk/src/site/apt/eclipseplugin.apt 2007-02-05 14:30:43 UTC (rev 241) @@ -11,8 +11,14 @@ the plugin you want to run. Here is a flash demo of the plugin : {{http://salto-db.sourceforge.net/demo/}} + +* Installation + + Installation is straight forward, once you have installed Eclipse. - You can install it in Eclipse with this update site : {{http://salto-db.sourceforge.net/plugin/}} + You need to add a new update site (Eclipse -> Help -> Software Updates -> Find and install -> Search for new features to install -> New remote site) + + The update site URL that you need is the following: {{http://salto-db.sourceforge.net/plugin/}} * Screenshots of the Eclipse plugin Added: salto-db-generator/trunk/src/site/apt/tutorials/tuto-doc.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/tutorials/tuto-doc.apt (rev 0) +++ salto-db-generator/trunk/src/site/apt/tutorials/tuto-doc.apt 2007-02-05 14:30:43 UTC (rev 241) @@ -0,0 +1,73 @@ + --- + Salto-db generator: installation & use + --- + Manuel Verriez + --- + --- + + Salto-db generator is an Eclipse plug-in that allows you to generate JAVA classes in order to interact between your application and a datasource. + + At this time, salto-db generator supports two persistance layers softwares: + + * salto-db: salto-db dataobjects generation + + * hibernate: Plain Old Java Objects (POJO) generation + xml mapping files or EJB3 annotations (since Hibernate 3.2) + +Installation + + Installation is straight forward, once you have Eclipse. You need to add a new update site (Eclipse -> Help -> Software Updates -> Find and install -> Search for new features to install -> New remote site) + + The update site URL that you need is the following: {{http://salto-db.sourceforge.net/plugin/}} + + Salto-db generator is available in an Eclipse perspective: + +[../images/tutorials/doc/eclipse.jpg] Salto-db perspective + +Use + + Here is an example to illustrate functionalities provided by this plug-in. + + Suppose that we have a database which contains three tables with the following relationships between them: + +[../images/tutorials/doc/schema.png] Database schema + + One or more customers (CLIENT table) can live in only one address (ADRESSE table). Each customer has his own detail (PROFIL_CLIENT table). + + The first step is to connect to database through salto-db generator plug-in to retrieve database schema. + +[../images/tutorials/doc/step-1.1.jpg] + +[../images/tutorials/doc/step-1.2.jpg] + + Then, you just have to "connect" to this new connection: + +[../images/tutorials/doc/step-2.1.jpg] + + Once you are connected, you can see tables in database: + +[../images/tutorials/doc/step-2.2.jpg] + + The next step is to generate classes. You have to choose your plugin (Hibernate with EJB3 annotations, Hibernate, Salto-db) thanks to this view: + +[../images/tutorials/doc/step-3.1.jpg] + + You also need to select tables that you need to map in your application: + +[../images/tutorials/doc/step-3.2.jpg] + + Salto-db generator proposes you types mapping between Java types and Sql types: + +[../images/tutorials/doc/step-4.jpg] + + You can click the "Apply Templates" button to apply template. Generation can start! + + Your project looks like: + +[../images/tutorials/doc/step-5.jpg] + + We advise you to have a look to the hibernate.cfg.xml to check if you are agree with the chosen dialect. + + You can now use generated classes in your code: + +[../images/tutorials/doc/step-6.jpg] + \ No newline at end of file Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/eclipse.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/eclipse.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/schema.png =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/schema.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-1.1.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-1.1.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-1.2.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-1.2.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-2.1.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-2.1.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-2.2.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-2.2.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-3.1.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-3.1.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-3.2.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-3.2.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-4.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-4.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-5.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-5.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-6.jpg =================================================================== (Binary files differ) Property changes on: salto-db-generator/trunk/src/site/resources/images/tutorials/doc/step-6.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: salto-db-generator/trunk/src/site/site.xml =================================================================== --- salto-db-generator/trunk/src/site/site.xml 2007-02-02 14:59:13 UTC (rev 240) +++ salto-db-generator/trunk/src/site/site.xml 2007-02-05 14:30:43 UTC (rev 241) @@ -18,7 +18,7 @@ <item name="Download" href="download.html"/><!-- <item name="FAQ" href="faq.html"/> --></menu> - + <menu name="Plugins"> <item name="Salto-db" href="plugins/saltodb.html"/> <item name="EJB3" href="plugins/ejb3.html"/> @@ -28,6 +28,10 @@ <item name="Pojos and Hibernate DAOs" href="plugins/pojohibernatedao.html"/> </menu> + <menu name="Tutorials"> + <item name="Eclipse plugin tutorial" href="tutorials/tuto-doc.html"/> + </menu> + ${reports} </body> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-02 14:59:14
|
Revision: 240 http://svn.sourceforge.net/salto-db/?rev=240&view=rev Author: rflament Date: 2007-02-02 06:59:13 -0800 (Fri, 02 Feb 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/index.apt salto-db-generator/trunk/src/site/apt/plugins/hibernate.apt salto-db-generator/trunk/src/site/apt/plugins/saltodb.apt Modified: salto-db-generator/trunk/src/site/apt/index.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/index.apt 2007-02-02 10:08:41 UTC (rev 239) +++ salto-db-generator/trunk/src/site/apt/index.apt 2007-02-02 14:59:13 UTC (rev 240) @@ -6,7 +6,7 @@ Salto-db Generator can generate code from a database structure. - Historically it has been developped to generate dataobjects for the {{{http://sourceforge.net/projects/salto-db}Salto persitence mechanism}}{{}} (aka saltodb), but now + Historically it has been developped to generate dataobjects for the {{{http://sourceforge.net/projects/salto-db}Salto persitence mechanism}} (aka saltodb), but now it can generate anything thanks to plugins. Salto-db Generator connects to a database thanks to jdbc, parses the tables structures and executes a plugin. A plugin can do anything with the Modified: salto-db-generator/trunk/src/site/apt/plugins/hibernate.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/hibernate.apt 2007-02-02 10:08:41 UTC (rev 239) +++ salto-db-generator/trunk/src/site/apt/plugins/hibernate.apt 2007-02-02 14:59:13 UTC (rev 240) @@ -2,4 +2,37 @@ Hibernate plugin --- -Hibernate plugin \ No newline at end of file +Hibernate plugin + + This plugin generate pojos and mapping files for hibernate. + + It cares about associations by parsing foreign keys. + +* Example + + Suppose we have two tables in a database : + + * Table CITY + + * Table PERSON + + [] + + Here is the corresponding DDL : + ++---------------------------------------------------+ +create table CITY ( + id_city number(20), + name varchar2(50), + constraint PK_CITY primary key ( id_city ) USING INDEX +); + +create table PERSON ( + id_person number(20), + name varchar2(50), + first_name varchar2(50), + age number(20), + id_city number(20), + constraint PK_PERSON primary key ( id_person ) USING INDEX +); ++---------------------------------------------------+ \ No newline at end of file Modified: salto-db-generator/trunk/src/site/apt/plugins/saltodb.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/plugins/saltodb.apt 2007-02-02 10:08:41 UTC (rev 239) +++ salto-db-generator/trunk/src/site/apt/plugins/saltodb.apt 2007-02-02 14:59:13 UTC (rev 240) @@ -2,4 +2,8 @@ Salto-db plugin --- -Salto-db plugin \ No newline at end of file +Salto-db plugin + + This plugin will generate a Salto-db dataobject for each table. + + These dataobjects should be used with the {{{http://sourceforge.net/projects/salto-db}Salto persitence mechanism}}. \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-02 10:08:43
|
Revision: 239 http://svn.sourceforge.net/salto-db/?rev=239&view=rev Author: rflament Date: 2007-02-02 02:08:41 -0800 (Fri, 02 Feb 2007) Log Message: ----------- Added Paths: ----------- salto-db-generator/trunk/src/site/apt/index.apt Added: salto-db-generator/trunk/src/site/apt/index.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/index.apt (rev 0) +++ salto-db-generator/trunk/src/site/apt/index.apt 2007-02-02 10:08:41 UTC (rev 239) @@ -0,0 +1,15 @@ + --- + Salto-db Generator + --- + +Salto-db Generator + + Salto-db Generator can generate code from a database structure. + + Historically it has been developped to generate dataobjects for the {{{http://sourceforge.net/projects/salto-db}Salto persitence mechanism}}{{}} (aka saltodb), but now + it can generate anything thanks to plugins. + + Salto-db Generator connects to a database thanks to jdbc, parses the tables structures and executes a plugin. A plugin can do anything with the + tables structures. Built-in plugins generate java code to access data with different ORMs from a java application. Have a look at the different plugins descriptions for more informations. + + Salto-db Generator can be run from Ant or as an Eclipse plugin. \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-02 09:39:44
|
Revision: 238 http://svn.sourceforge.net/salto-db/?rev=238&view=rev Author: rflament Date: 2007-02-02 01:39:40 -0800 (Fri, 02 Feb 2007) Log Message: ----------- Removed Paths: ------------- salto-db-generator/trunk/salto-db-generator.jar Deleted: salto-db-generator/trunk/salto-db-generator.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-02 09:33:37
|
Revision: 237 http://svn.sourceforge.net/salto-db/?rev=237&view=rev Author: rflament Date: 2007-02-02 01:33:34 -0800 (Fri, 02 Feb 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/antusage.apt Modified: salto-db-generator/trunk/src/site/apt/antusage.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/antusage.apt 2007-02-01 09:42:13 UTC (rev 236) +++ salto-db-generator/trunk/src/site/apt/antusage.apt 2007-02-02 09:33:34 UTC (rev 237) @@ -25,27 +25,31 @@ * Parameters of the salto-db-generate task -*----*-----+ -|driverClassName|Class name of the jdbc driver to use (i.e. com.mysql.jdbc.Driver for MySQL, oracle.jdbc.OracleDriver for Oracle, etc.) -*----*-----+ -|generateView|If set to false, views will be ignored by Salto-db Generator. Default is true. -*----*-----+ -|jdbcUrl|JDBC url to access to the database. -*----*-----+ -|login|Login to access to the database. -*----*-----+ -|plugin|Name of the plugin you want to use in Salto-db Generator. -*----*-----+ -|outputDir|Output directory where generated files will be saved. -*----*-----+ -|packageName|Name of the java package in which generated files will be saved. -*----*-----+ -|password|Password of the user to access to the database. -*----*-----+ -|schema|Name of the schema in which target tables can be found -*-----*-----+ -|tableName|Pattern to search for tables that you want to use. You can use the joker character '%'. -*----*-----+ +*---------------*--------+------------------------------------------------------------------------------------------------------------------------+ +|driverClassName|required|Class name of the jdbc driver to use (i.e. com.mysql.jdbc.Driver for MySQL, oracle.jdbc.OracleDriver for Oracle, etc.) +*------------*--------------------------+--------+ +|generateView|optional (default is true)|If set to false, views will be ignored by Salto-db Generator. Default is true. +*----*-----+--------+ +|jdbcUrl|required|JDBC url to access to the database. +*----*-----+--------+ +|login|required|Login to access to the database. +*----*-----+--------+ +|nameOffset|optional (default is 0)|You can set an offset to ignore first characters of table names. As an example if you run the Hibernate plugin on a table named "TB_PERSON", a pojo mapping this table will be generated. By default its name would be "TbPerson" but if you set nameOffset to 3, the generated name will be "Person" because the first characters "TB_" have been ignored. +*----*-----+--------+ +|plugin|optional (default is Salto-db)|Name of the plugin you want to use in Salto-db Generator. +*----*-----+--------+ +|prefix|optional (default is empty string)|You can choose a prefix that will be added to every classes that the plugin considers as a table. As an example if you run the Hibernate plugin on a table named "PERSON", a pojo mapping this table will be generated. By default its name would be "Person" but if you set a prefix the generated name will be prefix+"Person". +*----*-----+--------+ +|outputDir|required|Output directory where generated files will be saved. +*----*-----+--------+ +|packageName|required|Name of the java package in which generated files will be saved. +*----*-----+--------+ +|password|required|Password of the user to access to the database. +*----*-----+--------+ +|schema|required|Name of the schema in which target tables can be found +*-----*-----+--------+ +|tableName|required|Pattern to search for tables that you want to use. You can use the joker character '%'. +*----*-----+--------+ Parameters * Sample build file for Ant that will generate ejb3s This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-01 09:42:14
|
Revision: 236 http://svn.sourceforge.net/salto-db/?rev=236&view=rev Author: rflament Date: 2007-02-01 01:42:13 -0800 (Thu, 01 Feb 2007) Log Message: ----------- Added Paths: ----------- salto-db-generator/trunk/src/site/resources/ salto-db-generator/trunk/src/site/resources/images/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-01 09:35:43
|
Revision: 235 http://svn.sourceforge.net/salto-db/?rev=235&view=rev Author: rflament Date: 2007-02-01 01:35:42 -0800 (Thu, 01 Feb 2007) Log Message: ----------- squelette faq Modified Paths: -------------- salto-db-generator/trunk/src/site/site.xml Added Paths: ----------- salto-db-generator/trunk/src/site/fml/ salto-db-generator/trunk/src/site/fml/faq.fml Added: salto-db-generator/trunk/src/site/fml/faq.fml =================================================================== --- salto-db-generator/trunk/src/site/fml/faq.fml (rev 0) +++ salto-db-generator/trunk/src/site/fml/faq.fml 2007-02-01 09:35:42 UTC (rev 235) @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<faqs title="Frequently Asked Questions" toplink="false"> + + <part id="general"> + <title>General</title> + + + <faq id="whats-salto-db-generator"> + <question> + What is Salto-db Generator? + </question> + <answer> + <p></p> + </answer> + </faq> + </part> + + +</faqs> Modified: salto-db-generator/trunk/src/site/site.xml =================================================================== --- salto-db-generator/trunk/src/site/site.xml 2007-02-01 09:29:45 UTC (rev 234) +++ salto-db-generator/trunk/src/site/site.xml 2007-02-01 09:35:42 UTC (rev 235) @@ -15,8 +15,9 @@ <item name="Introduction" href="index.html"/> <item name="Ant usage" href="antusage.html"/> <item name="Eclipse plugin" href="eclipseplugin.html"/> - <item name="Download" href="download.html"/> - </menu> + <item name="Download" href="download.html"/><!-- + <item name="FAQ" href="faq.html"/> + --></menu> <menu name="Plugins"> <item name="Salto-db" href="plugins/saltodb.html"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-02-01 09:29:46
|
Revision: 234 http://svn.sourceforge.net/salto-db/?rev=234&view=rev Author: rflament Date: 2007-02-01 01:29:45 -0800 (Thu, 01 Feb 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/download.apt salto-db-generator/trunk/src/site/apt/eclipseplugin.apt Modified: salto-db-generator/trunk/src/site/apt/download.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/download.apt 2007-01-31 17:54:43 UTC (rev 233) +++ salto-db-generator/trunk/src/site/apt/download.apt 2007-02-01 09:29:45 UTC (rev 234) @@ -5,6 +5,6 @@ Download - You can download it at {{http://sourceforge.net/project/showfiles.php?group_id=164224&package_id=203600}}. + You can download salto-db-generator.jar at {{http://sourceforge.net/project/showfiles.php?group_id=164224&package_id=203600}}. - If you use Eclipse you should try the Eclipse plugin. \ No newline at end of file + To install the Eclipse plugin you must use the update site : {{http://salto-db.sourceforge.net/plugin/}}. \ No newline at end of file Modified: salto-db-generator/trunk/src/site/apt/eclipseplugin.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/eclipseplugin.apt 2007-01-31 17:54:43 UTC (rev 233) +++ salto-db-generator/trunk/src/site/apt/eclipseplugin.apt 2007-02-01 09:29:45 UTC (rev 234) @@ -5,4 +5,26 @@ Eclipse plugin - You can use Salto-db generator in Eclipse thanks to the Eclipse plugin. \ No newline at end of file + You can use Salto-db generator in Eclipse thanks to the Eclipse plugin. + + In the Eclipse plugin you can connect to a database, choose target tables and views and run + the plugin you want to run. + + Here is a flash demo of the plugin : {{http://salto-db.sourceforge.net/demo/}} + + You can install it in Eclipse with this update site : {{http://salto-db.sourceforge.net/plugin/}} + +* Screenshots of the Eclipse plugin + + [/images/eclipseplugin1.png] Salto-db perspective + + [/images/eclipseplugin2.png] Database connection + + [/images/eclipseplugin2.png] Apply templates View + + + + + + + \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-01-31 17:54:44
|
Revision: 233 http://svn.sourceforge.net/salto-db/?rev=233&view=rev Author: rflament Date: 2007-01-31 09:54:43 -0800 (Wed, 31 Jan 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/download.apt Modified: salto-db-generator/trunk/src/site/apt/download.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/download.apt 2007-01-31 17:52:57 UTC (rev 232) +++ salto-db-generator/trunk/src/site/apt/download.apt 2007-01-31 17:54:43 UTC (rev 233) @@ -6,4 +6,5 @@ Download You can download it at {{http://sourceforge.net/project/showfiles.php?group_id=164224&package_id=203600}}. + If you use Eclipse you should try the Eclipse plugin. \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-01-31 17:53:10
|
Revision: 232 http://svn.sourceforge.net/salto-db/?rev=232&view=rev Author: rflament Date: 2007-01-31 09:52:57 -0800 (Wed, 31 Jan 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator/trunk/src/site/apt/antusage.apt Modified: salto-db-generator/trunk/src/site/apt/antusage.apt =================================================================== --- salto-db-generator/trunk/src/site/apt/antusage.apt 2007-01-31 16:40:49 UTC (rev 231) +++ salto-db-generator/trunk/src/site/apt/antusage.apt 2007-01-31 17:52:57 UTC (rev 232) @@ -4,4 +4,100 @@ Ant task - You can use Apache Ant to use Salto-db generator. \ No newline at end of file + Salto-db generator provides an Ant Task so you can use it in your build files. + + In order to generate something, you have to choose which plugin you want to use. Here are the + built-in plugins : + + * Salto-db + + * EJB3 + + * EJB3AndHibernateDao + + * EJB3HibernateDaoAndTestCases + + * Hibernate + + * PojoHibernateDao + + You need to set one of these plugins in the "plugin" parameter of the salto-db-generate task. + +* Parameters of the salto-db-generate task + +*----*-----+ +|driverClassName|Class name of the jdbc driver to use (i.e. com.mysql.jdbc.Driver for MySQL, oracle.jdbc.OracleDriver for Oracle, etc.) +*----*-----+ +|generateView|If set to false, views will be ignored by Salto-db Generator. Default is true. +*----*-----+ +|jdbcUrl|JDBC url to access to the database. +*----*-----+ +|login|Login to access to the database. +*----*-----+ +|plugin|Name of the plugin you want to use in Salto-db Generator. +*----*-----+ +|outputDir|Output directory where generated files will be saved. +*----*-----+ +|packageName|Name of the java package in which generated files will be saved. +*----*-----+ +|password|Password of the user to access to the database. +*----*-----+ +|schema|Name of the schema in which target tables can be found +*-----*-----+ +|tableName|Pattern to search for tables that you want to use. You can use the joker character '%'. +*----*-----+ +Parameters + +* Sample build file for Ant that will generate ejb3s + ++--------------------------------------- +<project name="salto-db-ant-test" basedir="." default="generate"> + + + <!-- set the name of your database schema --> + <property name="schema" value=""/> + + <!-- set a pattern to search for tables. You can use the joker character '%'. + If you want to generate DataObjects for every tables, just set '%' --> + <property name="tableName" value=""/> + + <!-- set your database username--> + <property name="login" value=""/> + + <!-- set your database password--> + <property name="password" value=""/> + + <!-- set your jdbc url to access the database--> + <property name="jdbcUrl" value=""/> + + <!-- set the jdbc driver class name to access to your database. + This class should be in the classpath of the taskdef. You can copy the jar file in the current directory.--> + <property name="driverClassName" value=""/> + + <!-- set the path where to generate DataObjects source code--> + <property name="outputDir" value="generated-src"/> + + <!-- set the package name in which to generate DataObjects--> + <property name="packageName" value="com.salto.db.test"/> + + <path id="lib.path"> + <fileset dir="." includes="*.jar"/> + </path> + + <taskdef name="salto-db-generate" classname="com.salto.db.ant.DOGeneratorTask" + classpathref="lib.path"/> + + <target name="generate"> + <salto-db-generate plugin="EJB3" schema="${schema}" tableName="${tableName}" + login="${login}" password="${password}" jdbcUrl="${jdbcUrl}" + driverClassName="${driverClassName}" outputDir="${outputDir}" packageName="${packageName}"/> + </target> + + +</project> ++--------------------------------------- + + All you need to do is to put this build file in the same directory as salto-db-generator.jar, or + you can change the "lib.path" path accordingly to your configuration. + + Then you need to set values for tableName, login, password, jdbcUrl and driverClassName properties. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rfl...@us...> - 2007-01-31 16:40:56
|
Revision: 231 http://svn.sourceforge.net/salto-db/?rev=231&view=rev Author: rflament Date: 2007-01-31 08:40:49 -0800 (Wed, 31 Jan 2007) Log Message: ----------- Modified Paths: -------------- salto-db-generator/trunk/templates/hibernateejb3dao/hibernatedao.vm salto-db-generator/trunk/templates/hibernateejb3dao/test.vm Modified: salto-db-generator/trunk/templates/hibernateejb3dao/hibernatedao.vm =================================================================== --- salto-db-generator/trunk/templates/hibernateejb3dao/hibernatedao.vm 2007-01-31 16:27:28 UTC (rev 230) +++ salto-db-generator/trunk/templates/hibernateejb3dao/hibernatedao.vm 2007-01-31 16:40:49 UTC (rev 231) @@ -123,7 +123,7 @@ */ @SuppressWarnings("unchecked") public List<${jdoInfo.javaClassName}> findBy$util.doNameCreator.attribute2class($col.javaAttName)($col.getNonPrimitifClass() ${col.javaAttName}) { - Query q = getSession().createQuery("from ${jdoInfo.javaClassName} where $util.doNameCreator.class2attribute($util.doNameCreator.createDoName(${colfk2.getPkTableName()})).${col.javaAttName} = :${col.javaAttName}"); //1 + Query q = getSession().createQuery("from ${jdoInfo.javaClassName} where $util.doNameCreator.class2attribute($util.doNameCreator.createDoName(${colfk2.getPkTableName()})).${col.javaAttName} = :${col.javaAttName}"); q.setParameter("${col.javaAttName}",${col.javaAttName}); q.setCacheable(true); return q.list(); @@ -145,7 +145,7 @@ } #else -#if ($ispk=="true") +#if ($ispk=="true" && $isfk=="false") /** * Find ${jdoInfo.javaClassName} by ${col.javaAttName} */ Modified: salto-db-generator/trunk/templates/hibernateejb3dao/test.vm =================================================================== --- salto-db-generator/trunk/templates/hibernateejb3dao/test.vm 2007-01-31 16:27:28 UTC (rev 230) +++ salto-db-generator/trunk/templates/hibernateejb3dao/test.vm 2007-01-31 16:40:49 UTC (rev 231) @@ -61,7 +61,7 @@ private ${col.javaAttClass} test$util.getDoNameCreator().attribute2class($col.javaAttName); #else -#if ($ispk=="true") +#if ($ispk=="true" && $isfk=="false") private ${col.javaAttClass} test$util.getDoNameCreator().attribute2class($col.javaAttName); #end #end @@ -204,7 +204,7 @@ } #else -#if ($ispk=="true") +#if ($ispk=="true" && $isfk=="false") public ${col.javaAttClass} getTest$util.getDoNameCreator().attribute2class($col.javaAttName)() { return test$util.getDoNameCreator().attribute2class($col.javaAttName); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |